Don't wrap exceptions in test mode unless specifically requested.
This helps debugging reports with invalid SQL, which would otherwise return no results instead of a useful error message while running tests.
This commit is contained in:
parent
7c55de6e6f
commit
72b5ab0454
|
@ -160,6 +160,8 @@ class Report
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find(type, opts = nil)
|
def self.find(type, opts = nil)
|
||||||
|
opts ||= {}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
report = _get(type, opts)
|
report = _get(type, opts)
|
||||||
report_method = :"report_#{type}"
|
report_method = :"report_#{type}"
|
||||||
|
@ -178,6 +180,10 @@ class Report
|
||||||
report.error = :timeout
|
report.error = :timeout
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
||||||
|
# In test mode, don't swallow exceptions by default to help debug errors.
|
||||||
|
raise if Rails.env.test? && !opts[:wrap_exceptions_in_test]
|
||||||
|
|
||||||
# ensures that if anything unexpected prevents us from
|
# ensures that if anything unexpected prevents us from
|
||||||
# creating a report object we fail elegantly and log an error
|
# creating a report object we fail elegantly and log an error
|
||||||
if !report
|
if !report
|
||||||
|
|
|
@ -814,7 +814,7 @@ describe Report do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a report with an exception error" do
|
it "returns a report with an exception error" do
|
||||||
report = Report.find("exception_test")
|
report = Report.find("exception_test", wrap_exceptions_in_test: true)
|
||||||
expect(report.error).to eq(:exception)
|
expect(report.error).to eq(:exception)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -853,7 +853,7 @@ describe Report do
|
||||||
|
|
||||||
Report.stubs(:new).raises(ReportInitError.new("x"))
|
Report.stubs(:new).raises(ReportInitError.new("x"))
|
||||||
|
|
||||||
report = Report.find('signups')
|
report = Report.find('signups', wrap_exceptions_in_test: true)
|
||||||
|
|
||||||
expect(report).to be_nil
|
expect(report).to be_nil
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue