Class: BrainzLab::Testing::ErrorExpectation
- Inherits:
-
Object
- Object
- BrainzLab::Testing::ErrorExpectation
- Defined in:
- lib/brainzlab/testing/helpers.rb
Overview
Fluent expectation builder for errors
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(error_class, store) ⇒ ErrorExpectation
constructor
A new instance of ErrorExpectation.
-
#satisfied? ⇒ Boolean
(also: #matches?)
Check if the expectation is satisfied.
-
#with_context(context) ⇒ self
Specify expected context.
-
#with_message(message) ⇒ self
Specify expected message.
Constructor Details
#initialize(error_class, store) ⇒ ErrorExpectation
Returns a new instance of ErrorExpectation.
403 404 405 406 407 408 |
# File 'lib/brainzlab/testing/helpers.rb', line 403 def initialize(error_class, store) @error_class = error_class @store = store @expected_message = nil @expected_context = nil end |
Instance Method Details
#failure_message ⇒ Object
440 441 442 443 444 445 446 |
# File 'lib/brainzlab/testing/helpers.rb', line 440 def parts = ["expected error #{@error_class} to be captured"] parts << "with message matching #{@expected_message.inspect}" if @expected_message parts << "with context #{@expected_context.inspect}" if @expected_context parts << ", but got: #{@store.errors.map { |e| { class: e[:error_class], message: e[:message] } }.inspect}" parts.join end |
#failure_message_when_negated ⇒ Object
448 449 450 |
# File 'lib/brainzlab/testing/helpers.rb', line 448 def "expected error #{@error_class} not to be captured, but it was" end |
#satisfied? ⇒ Boolean Also known as: matches?
Check if the expectation is satisfied
434 435 436 |
# File 'lib/brainzlab/testing/helpers.rb', line 434 def satisfied? @store.error_captured?(@error_class, message: @expected_message, context: @expected_context) end |
#with_context(context) ⇒ self
Specify expected context
425 426 427 428 |
# File 'lib/brainzlab/testing/helpers.rb', line 425 def with_context(context) @expected_context = context self end |
#with_message(message) ⇒ self
Specify expected message
415 416 417 418 |
# File 'lib/brainzlab/testing/helpers.rb', line 415 def () @expected_message = self end |