0
begin
  ...
rescue => e
  puts "Error: #{ e } at: \n#{ e.backtrace.first }"
end

这工作得很好,但有时报告错误是在机架测试中。这使得很难弄清楚错误来自哪里。

所以,我想在测试环境中运行时禁用救援子句。

这可能吗?有更好的方法吗?

4

1 回答 1

2

你可以这样做:

rescue => e
  if Rails.env.test?
    raise
  else
    puts "Error: #{ e } at: \n#{ e.backtrace.first }"
  end
end
于 2013-11-18T23:28:23.867 回答