0

我有这个代码:

  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 的新手

4

1 回答 1

0

它说“预计不会为零”。所以它在你检查注释变量的 assert_not_nil 行抱怨。

你有这个变量的问题。也许它不存在。

于 2012-06-13T08:20:46.157 回答