Ruby on Rails功能测试

时间:2012-05-16 07:07:22

标签: ruby-on-rails functional-testing

我有这段代码:

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

1 个答案:

答案 0 :(得分:0)

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

您对该变量有疑问。也许它不存在。