Module: Loggr::Lint::Tests

Defined in:
lib/loggr/lint.rb

Overview

Adapter and Logger Lint Tests

You can test whether an object provides a compliant adapter and logger by including Logger::Lint::Tests in your tests.

Ensure you set the instance variable @adapter to the adapter to lint.

Instance Method Summary collapse

Instance Method Details

#test_adapter_loggerObject

Verifies `adapter#logger`, it checks that:

  • the factory method named #logger exists

  • that it accepts two arguments, name and options hash

  • the returned instnace responds to debug, info, warn, error and fatal

  • responds to tagged and mapped



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/loggr/lint.rb', line 23

def test_adapter_logger
  assert adapter.respond_to?(:logger), "The adapter should respond to #logger"
  assert adapter.method('logger').arity == -2, "The adapter should accept two parameters for #logger, name and options hash"

  @tempfile = Tempfile.new('lint')
  logger = adapter.logger('lint', :to => @tempfile.path)
  %w{debug info warn error fatal}.each do |level|
    assert logger.respond_to?(level), "The logger should respond to ##{level}"
    #assert logger.respond_to?("#{level}?"), "The logger should respond to ##{level}?"
  end

  assert logger.respond_to?(:tagged), "The logger should respond to #tagged"
  assert logger.respond_to?(:mapped), "The logger should respond to #mapped"
ensure
  @tempfile.unlink if @tempfile
end

#test_adapter_mdcObject

Verifies `adapter#mdc`, it checks that:

  • the factory method named #mdc exists

  • it accepts no arguments

  • the returned mdc responds to []=, [], delete, clear and to_hash



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/loggr/lint.rb', line 46

def test_adapter_mdc
  assert adapter.respond_to?(:mdc), "The adapter should respond to #mdc"
  assert adapter.method('mdc').arity == 0, "The adapter should accept no parameters for #mdc"

  mdc = adapter.mdc
  assert mdc.respond_to?(:[]=), "The mdc should respond to #[]="
  assert mdc.respond_to?(:[]),  "The mdc should respond to #[]"
  assert mdc.respond_to?(:delete),  "The mdc should respond to #delete"
  assert mdc.respond_to?(:clear),   "The mdc should respond to #clear"
  assert mdc.respond_to?(:to_hash), "The mdc should respond to #to_hash"
end