Class: BrainzLab::Testing::TraceExpectation

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

Overview

Fluent expectation builder for traces

Instance Method Summary collapse

Constructor Details

#initialize(name, store) ⇒ TraceExpectation

Returns a new instance of TraceExpectation.



560
561
562
563
564
# File 'lib/brainzlab/testing/helpers.rb', line 560

def initialize(name, store)
  @name = name.to_s
  @store = store
  @expected_opts = nil
end

Instance Method Details

#failure_messageObject



586
587
588
589
590
591
# File 'lib/brainzlab/testing/helpers.rb', line 586

def failure_message
  parts = ["expected trace '#{@name}'"]
  parts << "with options #{@expected_opts.inspect}" if @expected_opts
  parts << " to be recorded, but it wasn't"
  parts.join
end

#failure_message_when_negatedObject



593
594
595
# File 'lib/brainzlab/testing/helpers.rb', line 593

def failure_message_when_negated
  "expected trace '#{@name}' not to be recorded, but it was"
end

#satisfied?Boolean Also known as: matches?

Check if the expectation is satisfied

Returns:

  • (Boolean)


580
581
582
# File 'lib/brainzlab/testing/helpers.rb', line 580

def satisfied?
  @store.trace_recorded?(@name, @expected_opts)
end

#with(opts) ⇒ self

Specify expected options

Parameters:

  • opts (Hash)

    Options to match

Returns:

  • (self)


571
572
573
574
# File 'lib/brainzlab/testing/helpers.rb', line 571

def with(opts)
  @expected_opts = opts
  self
end