Class: Tracing::Matchers::Span::HaveLog

Inherits:
Object
  • Object
show all
Defined in:
lib/tracing/matchers/span/have_log.rb

Instance Method Summary collapse

Constructor Details

#initialize(**fields) ⇒ HaveLog

Returns a new instance of HaveLog.



6
7
8
# File 'lib/tracing/matchers/span/have_log.rb', line 6

def initialize(**fields)
  @expected = fields
end

Instance Method Details

#descriptionString

Returns:

  • (String)


25
26
27
28
29
# File 'lib/tracing/matchers/span/have_log.rb', line 25

def description
  desc = "have log entry"
  desc << " #{@expected}" unless any?
  desc
end

#failure_messageString Also known as: failure_message_for_should

Returns:

  • (String)


32
33
34
# 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

#failure_message_when_negatedString Also known as: failure_message_for_should_not

Returns:

  • (String)


38
39
40
# 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) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
# 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