gpt4 book ai didi

ruby-on-rails - 行动有效,但测试无效(应该)

转载 作者:行者123 更新时间:2023-11-28 20:58:24 31 4
gpt4 key购买 nike

我正在尝试用这个测试我在 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专栏会搞砸 ruby ,但看起来它可能不会......?

无论如何,所以我假设/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 相同?

关于ruby-on-rails - 行动有效,但测试无效(应该),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3029028/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com