Sha256: d68d68f6ac30cbbd01c8e7874382956b1806fa2b336e60d5a1a470037a1cf001

Contents?: true

Size: 1.24 KB

Versions: 31

Compression:

Stored size: 1.24 KB

Contents

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

    log_mutex = Mutex.new

    @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] "

        log_mutex.synchronize do
          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
        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

31 entries across 31 versions & 2 rubygems

Version Path
ably-rest-1.2.7 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.7 spec/support/debug_failure_helper.rb
ably-rest-1.2.6 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.6 spec/support/debug_failure_helper.rb
ably-rest-1.2.4 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.4 spec/support/debug_failure_helper.rb
ably-rest-1.2.3 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.3 spec/support/debug_failure_helper.rb
ably-rest-1.2.2 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.2 spec/support/debug_failure_helper.rb
ably-rest-1.2.1 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.1 spec/support/debug_failure_helper.rb
ably-rest-1.2.0 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.2.0 spec/support/debug_failure_helper.rb
ably-rest-1.1.8 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.1.8 spec/support/debug_failure_helper.rb
ably-rest-1.1.7 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.1.7 spec/support/debug_failure_helper.rb
ably-rest-1.1.6 lib/submodules/ably-ruby/spec/support/debug_failure_helper.rb
ably-1.1.6 spec/support/debug_failure_helper.rb