Class: BrainzLab::Testing::LogExpectation
- Inherits:
-
Object
- Object
- BrainzLab::Testing::LogExpectation
- Defined in:
- lib/brainzlab/testing/helpers.rb
Overview
Fluent expectation builder for logs
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(level, store) ⇒ LogExpectation
constructor
A new instance of LogExpectation.
-
#satisfied? ⇒ Boolean
(also: #matches?)
Check if the expectation is satisfied.
-
#with_data(data) ⇒ self
Specify expected data.
-
#with_message(message) ⇒ self
Specify expected message.
Constructor Details
#initialize(level, store) ⇒ LogExpectation
Returns a new instance of LogExpectation.
455 456 457 458 459 460 |
# File 'lib/brainzlab/testing/helpers.rb', line 455 def initialize(level, store) @level = level.to_sym @store = store @expected_message = nil @expected_data = nil end |
Instance Method Details
#failure_message ⇒ Object
492 493 494 495 496 497 498 |
# File 'lib/brainzlab/testing/helpers.rb', line 492 def parts = ["expected log at level :#{@level}"] parts << "with message matching #{@expected_message.inspect}" if @expected_message parts << "with data #{@expected_data.inspect}" if @expected_data parts << ", but got: #{@store.logs_at_level(@level).map { |l| { message: l[:message], data: l[:data] } }.inspect}" parts.join end |
#failure_message_when_negated ⇒ Object
500 501 502 |
# File 'lib/brainzlab/testing/helpers.rb', line 500 def "expected no log at level :#{@level} to be recorded, but it was" end |
#satisfied? ⇒ Boolean Also known as: matches?
Check if the expectation is satisfied
486 487 488 |
# File 'lib/brainzlab/testing/helpers.rb', line 486 def satisfied? @store.logged?(@level, @expected_message, @expected_data) end |
#with_data(data) ⇒ self
Specify expected data
477 478 479 480 |
# File 'lib/brainzlab/testing/helpers.rb', line 477 def with_data(data) @expected_data = data self end |
#with_message(message) ⇒ self
Specify expected message
467 468 469 470 |
# File 'lib/brainzlab/testing/helpers.rb', line 467 def () @expected_message = self end |