Rails 3 断言失败消息:“预期块返回真值”没有帮助;什么给了?
这种情况在我的控制器和路由测试中经常发生。例如,给定路由
match "/about", :to => "about#profile"
和测试
test "/about goes to about/profile" do
assert_generates "/about/", { :controller => "about", :action => "profile" }
end
唯一的失败消息是“预期块返回真值”。这种情况也会发生在以下测试中:
test "bills should redirect to /bills" do
get :bills
assert_redirected_to user_bills_path(@user)
end
如果我的控制器没有重定向到 user_bills_path(@user)
,我会收到相同的错误:“预期块返回真值”
这对于测试来说非常烦人 -驾驶,因为我无法在编写生产代码之前轻松检查我的断言是否失败,或者因为我编写了不正确的测试而失败。
它似乎来自 Rails 测试的东西。有什么办法可以避免这种情况或获得更好的消息吗?
This occurs frequently in my controller and route tests. Example, given the route
match "/about", :to => "about#profile"
And the test
test "/about goes to about/profile" do
assert_generates "/about/", { :controller => "about", :action => "profile" }
end
The only failure message is "Expected block to return true value". This happens also with tests like:
test "bills should redirect to /bills" do
get :bills
assert_redirected_to user_bills_path(@user)
end
If my controller doesn't' redirect to user_bills_path(@user)
, I get the same error: "Expected block to return true value"
This is very annoying for test-driving, as I cannot easily check that my assertion is failing before writing production code or failing because I've written the incorrect test.
It seems to be coming from Rails testing stuff. Any way to avoid this or get better messages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论