Class: BrainzLab::Testing::Matchers::HaveBeenTracedMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/brainzlab/testing/matchers.rb

Overview

Matcher for traces

Instance Method Summary collapse

Constructor Details

#initializeHaveBeenTracedMatcher

Returns a new instance of HaveBeenTracedMatcher.



295
296
297
# File 'lib/brainzlab/testing/matchers.rb', line 295

def initialize
  @expected_opts = nil
end

Instance Method Details

#descriptionObject



325
326
327
328
329
# File 'lib/brainzlab/testing/matchers.rb', line 325

def description
  desc = "have traced '#{@trace_name}'"
  desc += " with #{@expected_opts.inspect}" if @expected_opts
  desc
end

#failure_messageObject



309
310
311
312
313
314
315
316
317
318
319
# File 'lib/brainzlab/testing/matchers.rb', line 309

def failure_message
  actual_traces = BrainzLab::Testing.event_store.traces

  if actual_traces.empty?
    "expected trace '#{@trace_name}' to have been recorded, but no traces were found"
  else
    msg = "expected trace '#{@trace_name}'"
    msg += " with options #{@expected_opts.inspect}" if @expected_opts
    msg + ", but recorded traces were:\n  #{actual_traces.map { |t| t[:name] }.inspect}"
  end
end

#failure_message_when_negatedObject



321
322
323
# File 'lib/brainzlab/testing/matchers.rb', line 321

def failure_message_when_negated
  "expected trace '#{@trace_name}' not to have been recorded, but it was"
end

#matches?(trace_name) ⇒ Boolean

Returns:

  • (Boolean)


304
305
306
307
# File 'lib/brainzlab/testing/matchers.rb', line 304

def matches?(trace_name)
  @trace_name = trace_name.to_s
  BrainzLab::Testing.event_store.trace_recorded?(@trace_name, @expected_opts)
end

#with(opts) ⇒ Object



299
300
301
302
# File 'lib/brainzlab/testing/matchers.rb', line 299

def with(opts)
  @expected_opts = opts
  self
end