我想测试我的更新动作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

所以你的说法却要求@ new_countdown.name和@ countdown.name是一样的吗?打开工厂并见到了,我猜是简单的答案。不知道你正试图测试在这里。

另外,为什么使用相同的实例变量名@countdown = Countdown.find(@countdown.id)?是不是在安装一样@countdown @countdown在发现线路测试?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top