Rspec集成测试(涉及复选框)不会通过

时间:2011-06-03 19:26:37

标签: ruby-on-rails ruby-on-rails-3 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 个答案:

答案 0 :(得分:1)

如果您希望将其作为集成测试,那么您的断言最好是关于页面的内容。类似的东西:

assert_text "Goal met on 1/1/2011"

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