有没有办法在 Rails 中为 500 个错误页面编写测试? [英] Is there a way to write tests for 500 error page in Rails?
本文介绍了有没有办法在 Rails 中为 500 个错误页面编写测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 rails 应用程序中有一个自定义错误页面,测试 404 错误似乎很简单(获取不存在的页面并对某些文本执行 assert_match/select),但我想知道如何测试 500 错误页面.
I have a custom error pages in my rails app testing the 404 error seems straight forward enough (get nonexistent page and do assert_match/select for certain text) but I'm wondering how to test the 500 error page.
有什么想法吗?
推荐答案
所以我发现我可以在 rspec 中做这样的事情
So what I found out was that I could do something like this in rspec
def other_error
raise "ouch!"
end
it "renders 500 on Runtime error" do
get :other_error
response.should render_template("errors/500")
response.status.should == 500
end
这篇关于有没有办法在 Rails 中为 500 个错误页面编写测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文