Class: Lumberjack::CaptureDevice::IncludeLogEntryMatcher
- Inherits:
-
Object
- Object
- Lumberjack::CaptureDevice::IncludeLogEntryMatcher
- Defined in:
- lib/lumberjack/capture_device/include_log_entry_matcher.rb
Overview
RSpec matcher for checking captured logs for specific entries.
Instance Method Summary collapse
-
#description ⇒ String
Provide a description of what this matcher checks.
-
#failure_message ⇒ String
Generate a failure message when the matcher fails.
-
#failure_message_when_negated ⇒ String
Generate a failure message when the negated matcher fails.
-
#initialize(expected_hash) ⇒ IncludeLogEntryMatcher
constructor
Initialize the matcher with expected log entry attributes.
-
#matches?(actual) ⇒ Boolean
Check if the logger contains a log entry matching the expected attributes.
Constructor Details
#initialize(expected_hash) ⇒ IncludeLogEntryMatcher
Initialize the matcher with expected log entry attributes.
8 9 10 11 |
# File 'lib/lumberjack/capture_device/include_log_entry_matcher.rb', line 8 def initialize(expected_hash) @expected_hash = expected_hash.transform_keys(&:to_sym) @logger = nil end |
Instance Method Details
#description ⇒ String
Provide a description of what this matcher checks.
51 52 53 |
# File 'lib/lumberjack/capture_device/include_log_entry_matcher.rb', line 51 def description "have logged entry with #{expectation_description(@expected_hash)}" end |
#failure_message ⇒ String
Generate a failure message when the matcher fails.
29 30 31 32 33 34 35 |
# File 'lib/lumberjack/capture_device/include_log_entry_matcher.rb', line 29 def if valid_logger? (@logger, @expected_hash) else (@logger) end end |
#failure_message_when_negated ⇒ String
Generate a failure message when the negated matcher fails.
40 41 42 43 44 45 46 |
# File 'lib/lumberjack/capture_device/include_log_entry_matcher.rb', line 40 def if valid_logger? (@logger, @expected_hash) else (@logger) end end |
#matches?(actual) ⇒ Boolean
Check if the logger contains a log entry matching the expected attributes.
18 19 20 21 22 23 24 |
# File 'lib/lumberjack/capture_device/include_log_entry_matcher.rb', line 18 def matches?(actual) @logger = actual return false unless valid_logger? device = @logger.is_a?(Lumberjack::Device::Test) ? @logger : @logger.device device.include?(@expected_hash) end |