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 your adapter.
Instance Method Summary collapse
- #test_adapter_logger ⇒ Object
- #test_adapter_mdc ⇒ Object
- #test_logger_methods ⇒ Object
- #test_mdc_methods ⇒ Object
Instance Method Details
#test_adapter_logger ⇒ Object
15 16 17 18 |
# File 'lib/loggr/lint.rb', line 15 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" end |
#test_adapter_mdc ⇒ Object
20 21 22 23 |
# File 'lib/loggr/lint.rb', line 20 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" end |
#test_logger_methods ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/loggr/lint.rb', line 34 def test_logger_methods 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 ensure tempfile.unlink end |
#test_mdc_methods ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/loggr/lint.rb', line 25 def test_mdc_methods 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 |