class Tracing::Matchers::HaveSpan

@private

Public Class Methods

new(operation_name) click to toggle source
# File lib/tracing/matchers/have_span.rb, line 5
def initialize(operation_name)
  @expected = operation_name
  @predicates = []
end

Public Instance Methods

child_of(parent = :any) click to toggle source
# File lib/tracing/matchers/have_span.rb, line 38
def child_of(parent = :any)
  @predicates << Tracing::Matchers::Span::BeChildOf.new(parent)
  self
end
Also aliased as: with_parent
description() click to toggle source

@return [String]

# File lib/tracing/matchers/have_span.rb, line 59
def description
  "have a#{expected_span_description}"
end
failure_message() click to toggle source

@return [String]

# File lib/tracing/matchers/have_span.rb, line 64
def failure_message
  "expected a#{expected_span_description}, suggestions \n#{suggestions.map(&:to_s).join("\n")}"
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/have_span.rb, line 70
def failure_message_when_negated
  "did not expect#{expected_span_description}"
end
finished() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 16
def finished
  @state_predicate = RSpec::Matchers::BuiltIn::BePredicate.new(:be_finished)
  self
end
follow_after(previous) click to toggle source
# File lib/tracing/matchers/have_span.rb, line 44
def follow_after(previous)
  @predicates << Tracing::Matchers::Span::FollowAfter.new(previous)
  self
end
Also aliased as: following_after
following_after(previous)
Alias for: follow_after
in_progress() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 10
def in_progress
  @state_predicate = RSpec::Matchers::BuiltIn::BePredicate.new(:be_started)
  self
end
Also aliased as: started
matches?(tracer) click to toggle source

@return [Boolean]

# File lib/tracing/matchers/have_span.rb, line 51
def matches?(tracer)
  @subject = tracer
  @actual = actual_spans

  @actual.any? { |span| all_predicates.all? { |matcher| matcher.matches?(span) } }
end
started()
Alias for: in_progress
with_baggage(*args) click to toggle source
# File lib/tracing/matchers/have_span.rb, line 33
def with_baggage(*args)
  @predicates << Tracing::Matchers::Span::HaveBaggage.new(*args)
  self
end
with_log(**fields) click to toggle source
# File lib/tracing/matchers/have_span.rb, line 27
def with_log(**fields)
  @predicates << Tracing::Matchers::Span::HaveLog.new(**fields)
  self
end
Also aliased as: with_logs
with_logs(**fields)
Alias for: with_log
with_parent(parent = :any)
Alias for: child_of
with_tag(*args) click to toggle source
# File lib/tracing/matchers/have_span.rb, line 21
def with_tag(*args)
  @predicates << Tracing::Matchers::Span::HaveTag.new(*args)
  self
end
Also aliased as: with_tags
with_tags(*args)
Alias for: with_tag

Private Instance Methods

actual_spans() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 90
def actual_spans
  @subject.spans.select(&expected_predicate)
end
all_predicates() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 106
def all_predicates
  @all_predicates = (@predicates + [@state_predicate]).compact
end
expected_predicate() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 94
def expected_predicate
  operation_name? ? -> (span) { span.operation_name == @expected } : -> (_) { true }
end
expected_span_description() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 77
def expected_span_description
  desc = ""
  desc << " #{@state_predicate.description.gsub('be ', '')}" if state_predicate?
  desc << " span"
  desc << " with operation name \"#{@expected}\"" if operation_name?
  @predicates.each { |matcher| desc << " #{matcher.description.gsub('have', 'with')}" }
  desc
end
operation_name?() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 98
def operation_name?
  @expected.is_a?(String)
end
state_predicate?() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 102
def state_predicate?
  @state_predicate
end
suggestions() click to toggle source
# File lib/tracing/matchers/have_span.rb, line 86
def suggestions
  @actual.empty? ? @subject.spans : @actual
end