mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 18:54:44 +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:
@ -50,6 +50,10 @@ Discourse::Application.configure do
|
|||||||
config.log_level = :fatal
|
config.log_level = :fatal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if defined? RspecErrorTracker
|
||||||
|
config.middleware.insert_after ActionDispatch::Flash, RspecErrorTracker
|
||||||
|
end
|
||||||
|
|
||||||
config.after_initialize do
|
config.after_initialize do
|
||||||
SiteSetting.defaults.tap do |s|
|
SiteSetting.defaults.tap do |s|
|
||||||
s.set_regardless_of_locale(:s3_upload_bucket, 'bucket')
|
s.set_regardless_of_locale(:s3_upload_bucket, 'bucket')
|
||||||
|
@ -14,6 +14,31 @@ require 'mocha/api'
|
|||||||
require 'certified'
|
require 'certified'
|
||||||
require 'webmock/rspec'
|
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'
|
ENV["RAILS_ENV"] ||= 'test'
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
@ -96,6 +121,18 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
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|
|
config.before :each do |x|
|
||||||
# TODO not sure about this, we could use a mock redis implementation here:
|
# 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
|
# this gives us really clean "flush" semantics, howere the side-effect is that
|
||||||
@ -126,6 +163,8 @@ RSpec.configure do |config|
|
|||||||
|
|
||||||
I18n.locale = :en
|
I18n.locale = :en
|
||||||
|
|
||||||
|
RspecErrorTracker.last_exception = nil
|
||||||
|
|
||||||
if $test_cleanup_callbacks
|
if $test_cleanup_callbacks
|
||||||
$test_cleanup_callbacks.reverse_each(&:call)
|
$test_cleanup_callbacks.reverse_each(&:call)
|
||||||
$test_cleanup_callbacks = nil
|
$test_cleanup_callbacks = nil
|
||||||
|
Reference in New Issue
Block a user