mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
DEV: attempt to report last exception as the "cause" for failures
This allows our request specs to report exceptions so we can debug May have a few false positives but generally should be quiet TODO only wire magic in for request specs, currently happens for all
This commit is contained in:
@ -14,6 +14,31 @@ require 'mocha/api'
|
||||
require 'certified'
|
||||
require 'webmock/rspec'
|
||||
|
||||
class RspecErrorTracker
|
||||
|
||||
def self.last_exception=(ex)
|
||||
@ex = ex
|
||||
end
|
||||
|
||||
def self.last_exception
|
||||
@ex
|
||||
end
|
||||
|
||||
def initialize(app, config = {})
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
begin
|
||||
@app.call(env)
|
||||
rescue => e
|
||||
RspecErrorTracker.last_exception = e
|
||||
raise e
|
||||
end
|
||||
ensure
|
||||
end
|
||||
end
|
||||
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.expand_path("../../config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
@ -96,6 +121,18 @@ RSpec.configure do |config|
|
||||
end
|
||||
end
|
||||
|
||||
config.after :each do |x|
|
||||
if x.exception && ex = RspecErrorTracker.last_exception
|
||||
# magic in a cause if we have none
|
||||
unless x.exception.cause
|
||||
class << x.exception
|
||||
attr_accessor :cause
|
||||
end
|
||||
x.exception.cause = ex
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
config.before :each do |x|
|
||||
# TODO not sure about this, we could use a mock redis implementation here:
|
||||
# this gives us really clean "flush" semantics, howere the side-effect is that
|
||||
@ -126,6 +163,8 @@ RSpec.configure do |config|
|
||||
|
||||
I18n.locale = :en
|
||||
|
||||
RspecErrorTracker.last_exception = nil
|
||||
|
||||
if $test_cleanup_callbacks
|
||||
$test_cleanup_callbacks.reverse_each(&:call)
|
||||
$test_cleanup_callbacks = nil
|
||||
|
Reference in New Issue
Block a user