class Tracing::Matchers::Span::HaveLog

@private

Public Class Methods

new(**fields) click to toggle source
# File lib/tracing/matchers/span/have_log.rb, line 6
def initialize(**fields)
  @expected = fields
end

Public Instance Methods

description() click to toggle source

@return [String]

# File lib/tracing/matchers/span/have_log.rb, line 25
def description
  desc = "have log entry"
  desc << " #{@expected}" unless any?
  desc
end
failure_message() click to toggle source

@return [String]

# File lib/tracing/matchers/span/have_log.rb, line 32
def failure_message
  any? ? "expected any log entry" : "expected #{@expected} log entry, got #{@actual}"
end
Also aliased as: failure_message_for_should
failure_message_for_should()
Alias for: failure_message
failure_message_for_should_not()
failure_message_when_negated() click to toggle source

@return [String]

# File lib/tracing/matchers/span/have_log.rb, line 38
def failure_message_when_negated
  any? ? "did not expect any log entry" : "did not expect #{@expected} log entry, got #{@actual}"
end
matches?(span) click to toggle source

@return [Boolean]

# File lib/tracing/matchers/span/have_log.rb, line 11
def matches?(span)
  @subject = span
  @actual = span.logs.map { |log| log.fields.dup.tap { |h| h[:event] = log.event } }

  if any?
    @actual.any?
  else
    @actual.any? do |log|
      @expected.all? { |k, v| log.key?(k) && values_match?(v, log[k]) }
    end
  end
end

Private Instance Methods

any?() click to toggle source
# File lib/tracing/matchers/span/have_log.rb, line 45
def any?
  @expected.empty?
end
values_match?(expected, actual) click to toggle source
# File lib/tracing/matchers/span/have_log.rb, line 49
def values_match?(expected, actual)
  expected.is_a?(Regexp) ? expected.match(actual) : expected == actual
end