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.2.7 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.7 spec/support/test_logger_helper.rb
ably-rest-1.2.6 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.6 spec/support/test_logger_helper.rb
ably-rest-1.2.4 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.4 spec/support/test_logger_helper.rb
ably-rest-1.2.3 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.3 spec/support/test_logger_helper.rb
ably-rest-1.2.2 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.2 spec/support/test_logger_helper.rb
ably-rest-1.2.1 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.1 spec/support/test_logger_helper.rb
ably-rest-1.2.0 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.2.0 spec/support/test_logger_helper.rb
ably-rest-1.1.8 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.8 spec/support/test_logger_helper.rb
ably-rest-1.1.7 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.7 spec/support/test_logger_helper.rb
ably-rest-1.1.6 lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
ably-1.1.6 spec/support/test_logger_helper.rb