Class: Tracing::Matchers::Span::HaveBaggage

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ HaveBaggage

Returns a new instance of HaveBaggage.



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

def initialize(*args)
  @expected = args.last.is_a?(Hash) ? args.delete_at(-1) : Hash.new
  args.each_slice(2) { |k, v| @expected[k] = v }
end

Instance Method Details

#description ⇒ String

Returns:

  • (String)


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

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

#failure_message ⇒ String Also known as: failure_message_for_should

Returns:

  • (String)


31
32
33
# File 'lib/tracing/matchers/span/have_baggage.rb', line 31

def failure_message
  any? ? "expected any baggage" : "expected #{@expected} baggage, got #{@actual}"
end

#failure_message_when_negated ⇒ String Also known as: failure_message_for_should_not

Returns:

  • (String)


37
38
39
# File 'lib/tracing/matchers/span/have_baggage.rb', line 37

def failure_message_when_negated
  any? ? "did not expect any baggage" : "did not expect #{@expected} baggage, got #{@actual}"
end

#matches?(span) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/tracing/matchers/span/have_baggage.rb', line 12

def matches?(span)
  @subject = span
  @actual = span.context.baggage

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