Class: SemanticLogger::Test::RSpec::LogEventMatcher

Inherits:
Object
  • Object
show all
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

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

#descriptionObject



168
169
170
# File 'lib/semantic_logger/test/rspec.rb', line 168

def description
  "log a semantic logger event matching #{@matcher.description}"
end

#failure_messageObject



172
173
174
175
# File 'lib/semantic_logger/test/rspec.rb', line 172

def failure_message
  "expected the block to #{description}.\n" \
    "Captured #{@events.size} event(s):\n#{captured_inspect}"
end

#failure_message_when_negatedObject



177
178
179
180
# File 'lib/semantic_logger/test/rspec.rb', line 177

def failure_message_when_negated
  "expected the block not to #{description}, but it did.\n" \
    "Captured #{@events.size} event(s):\n#{captured_inspect}"
end

#matches?(block) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


164
165
166
# File 'lib/semantic_logger/test/rspec.rb', line 164

def supports_block_expectations?
  true
end