Sha256: b45b9c1683988d6a41038f76b698a6abd31632ff625991438b59947a5c5c4fc1

Contents?: true

Size: 971 Bytes

Versions: 37

Compression:

Stored size: 971 Bytes

Contents

# Class with standard Ruby Logger interface
#   but it keeps a record of the lof entries for later inspection
#
# Recommendation: Use :prevent_log_stubbing attibute on tests that use this logger
#
class TestLogger
  def initialize
    @messages = []
  end

  SEVERITIES = [:fatal, :error, :warn, :info, :debug]
  SEVERITIES.each do |severity_sym|
    define_method(severity_sym) do |*args, &block|
      if block
        @messages << [severity_sym, block.call]
      else
        @messages << [severity_sym, args.join(', ')]
      end
    end
  end

  def logs(options = {})
    min_severity = options[:min_severity]
    if min_severity
      severity_level = SEVERITIES.index(min_severity)
      raise "Unknown severity: #{min_severity}" if severity_level.nil?

      @messages.select do |severity, message|
        SEVERITIES.index(severity) <= severity_level
      end
    else
      @messages
    end
  end

  def level
    1
  end

  def level=(new_level)
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
ably-rest-1.1.5 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.5 spec/support/test_logger_helper.rb
ably-rest-1.1.4 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.4 spec/support/test_logger_helper.rb
ably-rest-1.1.4.rc lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.4.rc spec/support/test_logger_helper.rb
ably-rest-1.1.3 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.3 spec/support/test_logger_helper.rb
ably-rest-1.1.2 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.2 spec/support/test_logger_helper.rb
ably-rest-1.1.2.rc1 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.1 spec/support/test_logger_helper.rb
ably-rest-1.1.0 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.0 spec/support/test_logger_helper.rb
ably-1.0.7 spec/support/test_logger_helper.rb
ably-rest-1.0.6 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.0.6 spec/support/test_logger_helper.rb