class Tracing::Matchers::Span::BeChildOf
@private
Public Class Methods
new(parent)
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 6 def initialize(parent) @expected = parent end
Public Instance Methods
description()
click to toggle source
@return [String]
# 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()
click to toggle source
@return [String]
# 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
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
@return [String]
# 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
Also aliased as: failure_message_for_should_not
matches?(span)
click to toggle source
@return [Boolean]
# 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
Private Instance Methods
actual_message()
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 90 def actual_message case when @actual.respond_to?(:operation_name) then "a span with operation name \"#{@actual.operation_name}\"" when @actual.respond_to?(:parent_span_id) then "a span context with id \"#{@actual.parent_span_id}\"" when @actual.nil? then "nothing" else @actual end end
actual_span_id()
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 58 def actual_span_id case when @actual.respond_to?(:context) then @actual.context.span_id when @actual.respond_to?(:parent_span_id) then @actual.parent_span_id else @actual end end
any?()
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 44 def any? @expected == :any end
expected_message()
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 81 def expected_message case when @expected.respond_to?(:context) then "the span with operation name \"#{@expected.operation_name}\"" when @expected.respond_to?(:span_id) then "the span context with id \"#{@expected.span_id}\"" when @expected.is_a?(String) then "a span with operation name \"#{@expected}\"" else nil end end
expected_span_id()
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 66 def expected_span_id case when @expected.respond_to?(:context) then @expected.context.span_id when @expected.respond_to?(:span_id) then @expected.span_id when @expected.is_a?(String) span = @tracer.spans.find { |span| span.operation_name == @expected } span.context.span_id if span && span.context && span.context.span_id else @expected end end
expected_spans(tracer)
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 77 def expected_spans(tracer) tracer.spans.select { |span| span.operation_name == @expected } end
parent_of(subject)
click to toggle source
# File lib/tracing/matchers/span/be_child_of.rb, line 48 def parent_of(subject) return nil unless subject.context.parent_span_id parent_span = @tracer .spans .find { |span| span.context.span_id == subject.context.parent_span_id } parent_span || subject.context end