我有这样的代码:
def test_create
assert_difference('Comment.count') do
post :create, :comment => {:comment => 'Comment'}
assert_not_nil assigns(:comment)
assert_equal assigns(:comment).comment, "Comment"
assert_equal assigns(:comment).valid?, true
end
assert_response :redirect
assert_redirected_to article_path(assigns(:comment))
assert_equal flash[:notice], 'Comment was successfully created.'
end并尝试测试它,但它返回:
test_create(CommentsControllerTest) [test/functional/comments_controller_test.rb:5]:
<nil> expected to not be nil.这段代码有什么问题?请帮帮我我是Rails上的新手
发布于 2012-06-13 16:20:46
上面写着“预计不会为零”。因此,它在检查assert_not_nil变量的注释行出现了问题。
这个变量有问题。也许它并不存在。
https://stackoverflow.com/questions/10613615
复制相似问题