Class: LoggerForTest
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- LoggerForTest
- Defined in:
- lib/logger_for_test.rb
Overview
This is the implementation of Logger that stores an in memory representation of your log lines. It uses the delegator pattern to ensure that things continue to work suggested usages: LoggerForTest.new(Logger.new(STDOUT)) LoggerForTest.new(Rails.logger))
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Attribute Summary collapse
-
#log_lines ⇒ Object
Returns the value of attribute log_lines.
Instance Method Summary collapse
- #add(sev, message, progname = nil) ⇒ Object
- #contains_log?(message, sev = nil, progname = nil) ⇒ Boolean
-
#initialize(*args) ⇒ LoggerForTest
constructor
A new instance of LoggerForTest.
Constructor Details
#initialize(*args) ⇒ LoggerForTest
Returns a new instance of LoggerForTest.
12 13 14 15 |
# File 'lib/logger_for_test.rb', line 12 def initialize(*args) super @log_lines = [] end |
Instance Attribute Details
#log_lines ⇒ Object
Returns the value of attribute log_lines.
16 17 18 |
# File 'lib/logger_for_test.rb', line 16 def log_lines @log_lines end |
Instance Method Details
#add(sev, message, progname = nil) ⇒ Object
18 19 20 21 |
# File 'lib/logger_for_test.rb', line 18 def add(sev, , progname = nil) log_lines << format(, sev, progname) super(sev, , progname) end |
#contains_log?(message, sev = nil, progname = nil) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/logger_for_test.rb', line 23 def contains_log?(, sev = nil, progname = nil) filtered_by(sev, progname).any? do |line| line.fetch(:message) =~ Regexp.new() end end |