1

私はこれを使って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">.
4

1 に答える 1

0

それらの柱がルビーを台無しにするだろうと思っていendたのですが、多分そうではないようです...?

とにかく、それで私はそれ/test/functional/countdowns_controller_test.rb:86がこの主張であると思います:assert_equal @new_countdown.name, @countdown.name

それで、あなたの主張は@new_countdown.nameと@countdown.nameが同じであると尋ねていますか?工場を開いて見てください、私は簡単な答えだと思います。ここで何をテストしようとしているのかわからない。

また、なぜ@countdown = Countdown.find(@countdown.id)同じインスタンス変数名を使用しているのですか?セットアップの@countdownは、テストの検索行の@countdownと同じではありませんか?

于 2010-08-19T02:13:46.317 に答える