Sha256: 92cfe07d9637690d49ede90607fe4a776cf1337dd29815a1b3dc692dfc2695b3

Contents?: true

Size: 1.16 KB

Versions: 14

Compression:

Stored size: 1.16 KB

Contents

RSpec.configure do |config|
  config.before(:example) do |example|
    next if example.metadata[:prevent_log_stubbing]

    @log_output = []
    %w(fatal error warn info debug).each do |method_name|
      allow_any_instance_of(Ably::Logger).to receive(method_name.to_sym).and_wrap_original do |method, *args, &block|
        # Don't log shutdown sequence to keep log noise to a minimum
        next if RSpec.const_defined?(:EventMachine) && RSpec::EventMachine.reactor_stopping?

        prefix = "#{Time.now.strftime('%H:%M:%S.%L')} [\e[33m#{method_name}\e[0m] "

        begin
          args << block.call unless block.nil?
          @log_output << "#{prefix}#{args.compact.join(' ')}"
        rescue StandardError => e
          @log_output << "#{prefix}Failed to log block - #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}}"
        end

        # Call original
        method.call(*args, &block)
      end
    end
  end

  config.after(:example) do |example|
    next if example.metadata[:prevent_log_stubbing]

    exception = example.exception
    puts "\n#{'-'*34}\n\e[36mVerbose Ably log from test failure\e[0m\n#{'-'*34}\n#{@log_output.join("\n")}\n\n" if exception
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
ably-1.1.1 spec/support/debug_failure_helper.rb
ably-rest-1.1.0 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.1.0 spec/support/debug_failure_helper.rb
ably-1.0.7 spec/support/debug_failure_helper.rb
ably-rest-1.0.6 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.0.6 spec/support/debug_failure_helper.rb
ably-rest-1.0.5 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.0.5 spec/support/debug_failure_helper.rb
ably-1.0.4 spec/support/debug_failure_helper.rb
ably-1.0.3 spec/support/debug_failure_helper.rb
ably-1.0.2 spec/support/debug_failure_helper.rb
ably-1.0.1 spec/support/debug_failure_helper.rb
ably-rest-1.0.0 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.0.0 spec/support/debug_failure_helper.rb