Action works, but test doesn't (Shoulda)
Posted
by trobrock
on Stack Overflow
See other posts from Stack Overflow
or by trobrock
Published on 2010-06-12T14:47:25Z
Indexed on
2010/06/12
14:52 UTC
Read the original article
Hit count: 314
I am trying to test my update action in Rails with this:
context "on PUT to :update" do
setup do
@countdown = Factory(:countdown)
@new_countdown = Factory.stub(:countdown)
put :update, :id => @countdown.id, :name => @new_countdown.name, :end => @new_countdown.end
end
should_respond_with :redirect
should_redirect_to("the countdowns view") { countdown_url(assigns(:countdown)) }
should_assign_to :countdown
should_set_the_flash_to /updated/i
should "save :countdown with new attributes" do
@countdown = Countdown.find(@countdown.id)
assert_equal @new_countdown.name, @countdown.name
assert_equal 0, (@new_countdown.end - @countdown.end).to_i
end
end
When I actually go through the updating process using the scaffold that was built it updates the record fine, but the tests give me this error:
1) Failure:
test: on PUT to :update should save :countdown with new attributes. (CountdownsControllerTest)
[/test/functional/countdowns_controller_test.rb:86:in `__bind_1276353837_121269'
/Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call'
/Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: on PUT to :update should save :countdown with new attributes. ']:
<"Countdown 8"> expected but was
<"Countdown 7">.
© Stack Overflow or respective owner