Sha256: 8da2d9dad22b3f1aa9eaf2ca7c0ccba2248cd1239fd4b81dcb56001bc0b49e56

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

class FakeLogger
  def initialize
    @entries = {
      :info  => [],
      :debug => [],
      :warn  => [],
      :error => [],
      :fatal => [],
    }
  end

  def info(message = nil, &block)
    log(:info, message, &block)
  end

  def debug(message = nil, &block)
    log(:debug, message, &block)
  end

  def warn(message = nil, &block)
    log(:warn, message, &block)
  end

  def error(message = nil, &block)
    log(:error, message, &block)
  end

  def fatal(message = nil, &block)
    log(:fatal, message, &block)
  end

  def log(severity, message = nil, &block)
    message ||= block.call
    @entries[severity] << message
  end

  def has_entry?(level, expected_entry)
    @entries[level].any? { |actual_entry| actual_entry.include?(expected_entry) }
  end

  attr_reader :entries
end

Spec::Matchers.define :have_entry do |severity, entry|
  match do |logger|
    @logger = logger
    logger.has_entry?(severity, entry)
  end

  failure_message_for_should do
    "Expected #{severity}(#{entry.inspect}); got entries:\n\n#{entries}"
  end

  failure_message_for_should_not do
    "Unexpected #{severity}(#{entry.inspect}); got entries:\n\n#{entries}"
  end

  def entries
    lines = @logger.entries.inject([]) do |result, (severity, entries)|
      if entries.empty?
        result
      else
        result << "#{severity}:\n#{entries.join("\n")}"
      end
    end
    lines.join("\n\n")
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
copycopter_client-1.0.0.beta10 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta9 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta8 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta7 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta6 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta5 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta4 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta3 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta2 spec/support/fake_logger.rb
copycopter_client-1.0.0.beta1 spec/support/fake_logger.rb