Class: Tracing::Matchers::Span::BeChildOf

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

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ BeChildOf

Returns a new instance of BeChildOf.



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

def initialize(parent)
  @expected = parent
end

Instance Method Details

#description ⇒ String

Returns:

  • (String)


26
27
28
# File 'lib/tracing/matchers/span/be_child_of.rb', line 26

def description
  any? ? "have a parent" : "have #{expected_message} as the parent"
end

#failure_message ⇒ String Also known as: failure_message_for_should

Returns:

  • (String)


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

def failure_message
  any? ? "expected a parent" : "expected #{expected_message} as the parent, got #{actual_message}"
end

#failure_message_when_negated ⇒ String Also known as: failure_message_for_should_not

Returns:

  • (String)


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

def failure_message_when_negated
  any? ? "did not expect the parent" : "did not expect #{expected_message} parent, got #{actual_message}"
end

#matches?(span) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(span)
  @tracer = span.tracer
  @subject = span
  # actual is either Span, or SpanContext
  @actual = parent_of(@subject)

  case
  when any? then !!@actual
  when @actual.nil? && @expected then false
  else
    expected_span_id == actual_span_id
  end
end