class Tracing::Matchers::HaveTraces

@private

Public Class Methods

new(n) click to toggle source
# File lib/tracing/matchers/have_traces.rb, line 5
def initialize(n)
  @expected = n
end

Public Instance Methods

description() click to toggle source

@return [String]

# File lib/tracing/matchers/have_traces.rb, line 32
def description
  desc = "have "
  desc << "exactly #{@expected} " if exactly?
  desc << "traces #{@state}"
  desc.strip
end
failure_message() click to toggle source

@return [String]

# File lib/tracing/matchers/have_traces.rb, line 40
def failure_message
  if exactly?
    message = "expected #{@expected} traces"
    message << " #{@state}" if @state
    message << ", got #{@actual}"
    message
  else
    "expected any trace #{@state}".strip
  end
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_traces.rb, line 53
def failure_message_when_negated
  if exactly?
    message = "did not expect #{@expected} traces"
    message << " #{@state}" if @state
    message << ", got #{@actual}"
    message
  else
    "did not expect traces #{@state}".strip
  end
end
finished() click to toggle source
# File lib/tracing/matchers/have_traces.rb, line 14
def finished
  @state = :finished
  self
end
matches?(tracer) click to toggle source

@return [Boolean]

# File lib/tracing/matchers/have_traces.rb, line 20
def matches?(tracer)
  @subject = tracer

  if exactly?
    @actual = traces.size
    @actual == @expected
  else
    traces.any?
  end
end
started() click to toggle source
# File lib/tracing/matchers/have_traces.rb, line 9
def started
  @state = :started
  self
end

Private Instance Methods

exactly?() click to toggle source
# File lib/tracing/matchers/have_traces.rb, line 71
def exactly?
  @expected.is_a?(Fixnum)
end
state() click to toggle source
# File lib/tracing/matchers/have_traces.rb, line 67
def state
  @state || :started
end
traces() click to toggle source
# File lib/tracing/matchers/have_traces.rb, line 75
def traces
  @subject.spans
    .group_by { |span| span.context.trace_id }
    .map { |trace_id, spans| Trace.new(trace_id, spans) }
    .select { |trace| @state == :finished ? trace.finished? : true }
end