Class: SemanticLogger::Test::RSpec::LogEventMatcher
- Inherits:
-
Object
- Object
- SemanticLogger::Test::RSpec::LogEventMatcher
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/semantic_logger/test/rspec.rb
Overview
Matches a block, asserting that it emits at least one log event that matches the supplied expectations.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(capture, on:, expected:) ⇒ LogEventMatcher
constructor
A new instance of LogEventMatcher.
- #matches?(block) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(capture, on:, expected:) ⇒ LogEventMatcher
Returns a new instance of LogEventMatcher.
153 154 155 156 157 |
# File 'lib/semantic_logger/test/rspec.rb', line 153 def initialize(capture, on:, expected:) @capture = capture @on = on @matcher = EventMatcher.new(**expected) end |
Instance Method Details
#description ⇒ Object
168 169 170 |
# File 'lib/semantic_logger/test/rspec.rb', line 168 def description "log a semantic logger event matching #{@matcher.description}" end |
#failure_message ⇒ Object
172 173 174 175 |
# File 'lib/semantic_logger/test/rspec.rb', line 172 def "expected the block to #{description}.\n" \ "Captured #{@events.size} event(s):\n#{captured_inspect}" end |
#failure_message_when_negated ⇒ Object
177 178 179 180 |
# File 'lib/semantic_logger/test/rspec.rb', line 177 def "expected the block not to #{description}, but it did.\n" \ "Captured #{@events.size} event(s):\n#{captured_inspect}" end |
#matches?(block) ⇒ Boolean
159 160 161 162 |
# File 'lib/semantic_logger/test/rspec.rb', line 159 def matches?(block) @events = @capture.call(@on, &block) @events.any? { |event| @matcher.matches?(event) } end |
#supports_block_expectations? ⇒ Boolean
164 165 166 |
# File 'lib/semantic_logger/test/rspec.rb', line 164 def supports_block_expectations? true end |