Class: BrainzLab::Testing::Matchers::HaveBeenRecordedMatcher
- Inherits:
-
Object
- Object
- BrainzLab::Testing::Matchers::HaveBeenRecordedMatcher
- Defined in:
- lib/brainzlab/testing/matchers.rb
Overview
Matcher for metrics
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ HaveBeenRecordedMatcher
constructor
A new instance of HaveBeenRecordedMatcher.
- #matches?(type_and_name) ⇒ Boolean
- #with_tags(tags) ⇒ Object
- #with_value(value) ⇒ Object
Constructor Details
#initialize ⇒ HaveBeenRecordedMatcher
Returns a new instance of HaveBeenRecordedMatcher.
239 240 241 242 |
# File 'lib/brainzlab/testing/matchers.rb', line 239 def initialize @expected_value = nil @expected_tags = nil end |
Instance Method Details
#description ⇒ Object
285 286 287 288 289 290 |
# File 'lib/brainzlab/testing/matchers.rb', line 285 def description desc = "have recorded metric #{@type}('#{@name}')" desc += " with value #{@expected_value.inspect}" if @expected_value desc += " with tags #{@expected_tags.inspect}" if @expected_tags desc end |
#failure_message ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/brainzlab/testing/matchers.rb', line 267 def actual_metrics = BrainzLab::Testing.event_store.metrics_named(@name) if actual_metrics.empty? "expected metric #{@type}('#{@name}') to have been recorded, but no such metric was found.\n" \ "Recorded metrics: #{BrainzLab::Testing.event_store.metrics.map { |m| "#{m[:type]}('#{m[:name]}')" }.inspect}" else msg = "expected metric #{@type}('#{@name}')" msg += " with value #{@expected_value.inspect}" if @expected_value msg += " with tags #{@expected_tags.inspect}" if @expected_tags msg + ", but recorded metrics were:\n #{actual_metrics.inspect}" end end |
#failure_message_when_negated ⇒ Object
281 282 283 |
# File 'lib/brainzlab/testing/matchers.rb', line 281 def "expected metric #{@type}('#{@name}') not to have been recorded, but it was" end |
#matches?(type_and_name) ⇒ Boolean
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/brainzlab/testing/matchers.rb', line 254 def matches?(type_and_name) @type, @name = type_and_name @type = @type.to_sym @name = @name.to_s BrainzLab::Testing.event_store.metric_recorded?( @type, @name, value: @expected_value, tags: @expected_tags ) end |
#with_tags(tags) ⇒ Object
249 250 251 252 |
# File 'lib/brainzlab/testing/matchers.rb', line 249 def () @expected_tags = self end |
#with_value(value) ⇒ Object
244 245 246 247 |
# File 'lib/brainzlab/testing/matchers.rb', line 244 def with_value(value) @expected_value = value self end |