Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
begin ... rescue => e puts "Error: #{ e } at: \n#{ e.backtrace.first }" end
这工作得很好,但有时报告错误是在机架测试中。这使得很难弄清楚错误来自哪里。
所以,我想在测试环境中运行时禁用救援子句。
这可能吗?有更好的方法吗?
你可以这样做:
rescue => e if Rails.env.test? raise else puts "Error: #{ e } at: \n#{ e.backtrace.first }" end end