Sha256: 40e958ecb8a51bb71cbf21e8ccdc5251e1d2bb8d8fea8478d42475f5a9ce1b7b

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

# Store logger messages in specs for possible later output
class MockLogger
  attr_accessor :messages, :errors

  def self.configure_log(name, _config = {})
    @name = name
  end

  def initialize
    @messages = []
    @errors   = []
  end

  def clear
    @messages.clear
    @errors.clear
  end

  %w(debug info warn).each do |level|
    class_eval <<-RUBY
      def #{level}(msg = nil, &block)
        msg = yield if msg.nil? && block_given?
        @messages << '[#{level.upcase}] :: ' +
          (self.class.instance_variable_get('@name') || 'flapjack') + ' :: ' +
          msg
      end
    RUBY
  end

  %w(error fatal).each do |level|
    class_eval <<-ERRORS
      def #{level}(msg = nil, &block)
        msg = yield if msg.nil? && block_given?
        @messages << '[#{level.upcase}] :: ' +
          (self.class.instance_variable_get('@name') || 'flapjack') + ' :: ' +
          msg
        @errors << '[#{level.upcase}] :: ' +
          (self.class.instance_variable_get('@name') || 'flapjack') + ' :: ' +
          msg
      end
    ERRORS
  end

  %w(debug info warn error fatal).each do |level|
    class_eval <<-LEVELS
      def #{level}?
        true
      end
    LEVELS
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
zermelo-1.4.3 spec/support/mock_logger.rb
zermelo-1.4.2 spec/support/mock_logger.rb
zermelo-1.4.1 spec/support/mock_logger.rb
zermelo-1.4.0 spec/support/mock_logger.rb
zermelo-1.3.0 spec/support/mock_logger.rb