开发者

Rspec integration test (involving check box) won't pass

I'm working on a goal application, where a user can check a box next to a goal to mark it as complete. I wrote the test for this functionality, but something isn't quite right, because it keeps failing. I eventually got fed up and just wrote the code, which works, but the test still keeps failing. I'm still learning Rspec, so any advice you could give me would be helpful.

The Test

# @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)
    chec开发者_开发知识库k('goal_completed')
    click_button('goal_submit')
    @goal.completed.should be_true
  end
end

The Result

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)>'


If you want this to be an integration test, it would be better for your assertion to be about the contents of the page. Something like:

assert_text "Goal met on 1/1/2011"

If you want to stick with model assertions, I'm pretty sure you just need to reload: @goal.reload.completed.should be_true

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜