lib/gurke/reporter.rb in gurke-2.4.2 vs lib/gurke/reporter.rb in gurke-3.0.0

- old
+ new

@@ -1,37 +1,40 @@ +# frozen_string_literal: true + module Gurke # # A {Reporter} provides callbacks that will be executed whenever # a specific execution step starts or ends. # # @api public # + # rubocop:disable MissingCopEnableDirective + # rubocop:disable UnusedMethodArgument + # class Reporter - # rubocop:disable UnusedMethodArgument - # List of all callback methods as symbols. # - CALLBACKS = [ - :before_features, - :before_feature, - :before_scenario, - :before_step, - :start_features, - :start_feature, - :start_scenario, - :start_background, - :start_step, - :end_features, - :end_feature, - :end_scenario, - :end_background, - :end_step, - :after_features, - :after_feature, - :after_scenario, - :after_step - ] + CALLBACKS = %i[ + before_features + before_feature + before_scenario + before_step + start_features + start_feature + start_scenario + start_background + start_step + end_features + end_feature + end_scenario + end_background + end_step + after_features + after_feature + after_scenario + after_step + ].freeze # Called before the execution of any feature and before any # before-features hook is invoked. # # @param features [Array<Feature>] List of all features that @@ -250,33 +253,37 @@ end # @visibility private def invoke(mth, *args) send mth, *args - rescue => e + rescue StandardError => e warn "Rescued in reporter: #{e}\n" + e.backtrace.join("\n") end - # @api private # + protected - def format_exception(ex) + + def format_exception(ex, backtrace: true) s = [ex.class.to_s + ': ' + ex.message.strip] - if ex.backtrace.nil? - s << ' <no backtrace available>' - elsif ex.backtrace.empty? - s << ' <backtrace empty>' - else - ex.backtrace.each do |bt| - s << ' ' + bt.strip + + if backtrace + if ex.backtrace.nil? + s << ' <no backtrace available>' + elsif ex.backtrace.empty? + s << ' <backtrace empty>' + else + ex.backtrace.each do |bt| + s << ' ' + bt.strip + end end end if ex.respond_to?(:cause) && ex.cause && - ex.cause.respond_to?(:message) && ex.cause.respond_to?(:backtrace) + ex.cause.respond_to?(:message) && ex.cause.respond_to?(:backtrace) - cause = format_exception(ex.cause) + cause = format_exception(ex.cause, backtrace: backtrace) s << 'caused by: ' + cause.shift s += cause end s