Class: BrainzLab::Testing::MetricExpectation
- Inherits:
-
Object
- Object
- BrainzLab::Testing::MetricExpectation
- Defined in:
- lib/brainzlab/testing/helpers.rb
Overview
Fluent expectation builder for metrics
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(type, name, store) ⇒ MetricExpectation
constructor
A new instance of MetricExpectation.
-
#satisfied? ⇒ Boolean
(also: #matches?)
Check if the expectation is satisfied.
-
#with_tags(tags) ⇒ self
Specify expected tags.
-
#with_value(value) ⇒ self
Specify expected value.
Constructor Details
#initialize(type, name, store) ⇒ MetricExpectation
Returns a new instance of MetricExpectation.
507 508 509 510 511 512 513 |
# File 'lib/brainzlab/testing/helpers.rb', line 507 def initialize(type, name, store) @type = type.to_sym @name = name.to_s @store = store @expected_value = nil @expected_tags = nil end |
Instance Method Details
#failure_message ⇒ Object
545 546 547 548 549 550 551 |
# File 'lib/brainzlab/testing/helpers.rb', line 545 def parts = ["expected metric #{@type}('#{@name}')"] parts << "with value #{@expected_value.inspect}" if @expected_value parts << "with tags #{@expected_tags.inspect}" if @expected_tags parts << ", but got: #{@store.metrics_named(@name).inspect}" parts.join end |
#failure_message_when_negated ⇒ Object
553 554 555 |
# File 'lib/brainzlab/testing/helpers.rb', line 553 def "expected metric #{@type}('#{@name}') not to be recorded, but it was" end |
#satisfied? ⇒ Boolean Also known as: matches?
Check if the expectation is satisfied
539 540 541 |
# File 'lib/brainzlab/testing/helpers.rb', line 539 def satisfied? @store.metric_recorded?(@type, @name, value: @expected_value, tags: @expected_tags) end |
#with_tags(tags) ⇒ self
Specify expected tags
530 531 532 533 |
# File 'lib/brainzlab/testing/helpers.rb', line 530 def () @expected_tags = self end |
#with_value(value) ⇒ self
Specify expected value
520 521 522 523 |
# File 'lib/brainzlab/testing/helpers.rb', line 520 def with_value(value) @expected_value = value self end |