Class: Tracing::Matchers::HaveTraces

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

Defined Under Namespace

Classes: Trace

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ HaveTraces

Returns a new instance of HaveTraces.



5
6
7
# File 'lib/tracing/matchers/have_traces.rb', line 5

def initialize(n)
  @expected = n
end

Instance Method Details

#description ⇒ String

Returns:

  • (String)


32
33
34
35
36
37
# 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 ⇒ String Also known as: failure_message_for_should

Returns:

  • (String)


40
41
42
43
44
45
46
47
48
49
# 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

#failure_message_when_negated ⇒ String Also known as: failure_message_for_should_not

Returns:

  • (String)


53
54
55
56
57
58
59
60
61
62
# 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 ⇒ Object



14
15
16
17
# File 'lib/tracing/matchers/have_traces.rb', line 14

def finished
  @state = :finished
  self
end

#matches?(tracer) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
# 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 ⇒ Object



9
10
11
12
# File 'lib/tracing/matchers/have_traces.rb', line 9

def started
  @state = :started
  self
end