【发布时间】:2013-10-17 10:43:47
【问题描述】:
setup do
@prayer = prayers(:one)
end
test "should update prayer count" do
assert_difference('@prayer.count', 1) do
get "update_counter", {:id => @prayer.id}
end
assert_redirected_to root_path
end
# Running tests:
counter updated and saved. Count is:
1
F
Finished tests in 1.374664s, 0.7275 tests/s, 0.7275 assertions/s.
1) Failure:
PrayersControllerTest#test_should_update_prayer_count [test/controllers/prayers_controller_test.rb:147]:
"@prayer.count" didn't change by 1.
Expected: 1
Actual: 0
update_counter 功能运行良好且报告正确,但测试失败。 @prayer 变量是指向数据库还是指向某个单独的夹具对象?我也尝试过@prayer = Prayer.find(1),但结果相同。有什么想法吗?
夹具 yml 是:
one:
id: 1
prayer: Pray for nice weather
count: 0
user_id: 1
谢谢。
【问题讨论】:
-
仅供参考,it's bad form 通过 GET 请求对服务器进行更改。
-
谢谢。现在改为“post”(除非你坚持 put)我想我在对一些集成测试进行故障排除时尝试了“get”。
标签: ruby-on-rails testing tdd