2012-05-16 156 views
0

我這個代碼:Ruby on Rails的功能測試

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

回答

0

它說「預計不會無」。所以它在assert_not_nil行上抱怨,在那裏你檢查comment變量。

您對該變量有問題。也許它不存在。