2011-06-03 74 views
0

我正在开发一个目标应用程序,用户可以选中一个目标旁边的框将其标记为完整。我为这个功能编写了测试,但有些东西并不完全正确,因为它一直在失败。我最终感到厌倦,只写了代码,它的工作原理,但测试仍然失败。我仍然在学习Rspec,所以你可以给我的任何建议都会有帮助。Rspec集成测试(涉及复选框)不会通过

测试

# @user has already been signed in 

describe "completing a goal" do 

    before(:each) do 
    @goal = Factory(:goal, :user => @user) 
    end 

    it "should set 'completed' attribute to true" do 
    visit edit_goal_path(@goal) 
    check('goal_completed') 
    click_button('goal_submit') 
    @goal.completed.should be_true 
    end 
end 

结果

Failures: 

1) Goals completing a goal should set 'completed' attribute to true 
Failure/Error: @goal.completed.should be_true 
    expected nil to be true 
# ./spec/requests/goals_spec.rb:81:in `block (3 levels) in <top (required)>' 

回答

1

如果你想这是一个集成测试,这将是更好地为你的说法是对网页的内容。喜欢的东西:

assert_text "Goal met on 1/1/2011"

如果你想坚持与模型断言,我敢肯定,你只需要重新加载: @goal.reload.completed.should be_true

+0

固定的,谢谢!我不会把它放在控制器规范中,那么如果我坚持完成。应该be_true,因为它处理实际的控制器? – 2011-06-03 19:58:16