views:

35

answers:

1

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">.
A: 

I'd have thought those end columns would screw up ruby, but looks like it doesn't maybe...?

Anyways, So I assume that /test/functional/countdowns_controller_test.rb:86 is this assertion: assert_equal @new_countdown.name, @countdown.name.

So your assertion is asking that @new_countdown.name and @countdown.name are the same? Open the factory and see, i guess is the easy answer. not sure what you are trying to test here.

also, why is @countdown = Countdown.find(@countdown.id) using the same instance variable name? Isn't @countdown in setup the same as @countdown in your find line in the test?

pjammer