【发布时间】:2013-11-18 23:18:46
【问题描述】:
begin
...
rescue => e
puts "Error: #{ e } at: \n#{ e.backtrace.first }"
end
这很好用,但有时会报告错误是在机架测试中。这使得很难弄清楚错误来自哪里。
所以,我想在测试环境中运行时禁用rescue子句。
这可能吗?有没有更好的方法?
【问题讨论】:
begin
...
rescue => e
puts "Error: #{ e } at: \n#{ e.backtrace.first }"
end
这很好用,但有时会报告错误是在机架测试中。这使得很难弄清楚错误来自哪里。
所以,我想在测试环境中运行时禁用rescue子句。
这可能吗?有没有更好的方法?
【问题讨论】:
你可以这样做:
rescue => e
if Rails.env.test?
raise
else
puts "Error: #{ e } at: \n#{ e.backtrace.first }"
end
end
【讨论】:
rescue_from ActiveRecord::RecordNotFound, with: :render_404(不确定早期版本)。