アクションは動作しますが、テストはしません(Shoulda)
-
26-09-2019 - |
質問
私はこれでRailsの中で私の更新アクションをテストしようとしています
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
私は実際にそれを建てた足場を使用して更新処理を経るは、レコードの罰金を更新しますが、テストでは、私は、このエラーを与えます:
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">.
解決
私はそれらのend
列がルビーを台無しだろうと思っているだろうが、それのように見えるではないかもしれませんか...?
とにかく、だから私その/test/functional/countdowns_controller_test.rb:86
を前提とは、この主張です:assert_equal @new_countdown.name, @countdown.name
だからあなたの主張はcountdown.nameが同じである@ new_countdown.nameことや、@求めていますか?工場を開いて見て、私は簡単な答えだと思います。ないあなたがここでテストしようとしているもの。
また、なぜ同じインスタンス変数名を使用して@countdown = Countdown.find(@countdown.id)
はありますか?テストであなたの検索ラインに設定@countdownと同じで@countdownされていない?
所属していません StackOverflow