class RSpecLogger def error(e) # somehow report sideband error to rspec
endend
class SomeOtherReporter def error(e) puts e.message endend
class MyErrorLogger LOGGERS = [ SomeOtherReporter.new, RSpecLogger.new ]
def self.error(exception) LOGGERS.each { |r| r.error(exception) }
raise exception if should_reraise? # This could be replaced entirely via sideband reporting end
def self.should_reraise? true # if in test environment endend
describe MyErrorLogger do it 'should fail even if reraise is caught elsewhere' do
begin begin # Something raises an exception raise StandardError.new("Foo message") rescue => e # We rescue and log it described_class.error(e) end rescue => e # the reraised error is swallowed somewhere further up the stack, so the test passes if no assertions fail. nil end endendTry this:
class RSpecLogger
def errors
@errors ||= []
end
def error(e)
errors << e
end
end
RSpec.configure do |c|
c.before do
@rspec_logger = RSpecLogger.new
end
c.after do
expect(@rspec_logger.errors).to be_empty,
"Got some logged errors: #{@rspec_logger.errors.map(&:message).join("\n")}"
end
end
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/d0fcb0da-8578-49f0-be1e-9a9094276fe0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.