Class: BrainzLab::Testing::Matchers::HaveSentAlertMatcher
- Inherits:
-
Object
- Object
- BrainzLab::Testing::Matchers::HaveSentAlertMatcher
- Defined in:
- lib/brainzlab/testing/matchers.rb
Overview
Matcher for alerts
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ HaveSentAlertMatcher
constructor
A new instance of HaveSentAlertMatcher.
- #matches?(alert_name) ⇒ Boolean
- #with_message(message) ⇒ Object
- #with_severity(severity) ⇒ Object
Constructor Details
#initialize ⇒ HaveSentAlertMatcher
Returns a new instance of HaveSentAlertMatcher.
334 335 336 337 |
# File 'lib/brainzlab/testing/matchers.rb', line 334 def initialize @expected_message = nil @expected_severity = nil end |
Instance Method Details
#description ⇒ Object
375 376 377 378 379 380 |
# File 'lib/brainzlab/testing/matchers.rb', line 375 def description desc = "have sent alert '#{@alert_name}'" desc += " with message '#{@expected_message}'" if @expected_message desc += " with severity :#{@expected_severity}" if @expected_severity desc end |
#failure_message ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/brainzlab/testing/matchers.rb', line 358 def actual_alerts = BrainzLab::Testing.event_store.alerts if actual_alerts.empty? "expected alert '#{@alert_name}' to have been sent, but no alerts were found" else msg = "expected alert '#{@alert_name}'" msg += " with message '#{@expected_message}'" if @expected_message msg += " with severity :#{@expected_severity}" if @expected_severity msg + ", but sent alerts were:\n #{actual_alerts.map { |a| { name: a[:name], severity: a[:severity] } }.inspect}" end end |
#failure_message_when_negated ⇒ Object
371 372 373 |
# File 'lib/brainzlab/testing/matchers.rb', line 371 def "expected alert '#{@alert_name}' not to have been sent, but it was" end |
#matches?(alert_name) ⇒ Boolean
349 350 351 352 353 354 355 356 |
# File 'lib/brainzlab/testing/matchers.rb', line 349 def matches?(alert_name) @alert_name = alert_name.to_s BrainzLab::Testing.event_store.alert_sent?( @alert_name, message: @expected_message, severity: @expected_severity ) end |
#with_message(message) ⇒ Object
339 340 341 342 |
# File 'lib/brainzlab/testing/matchers.rb', line 339 def () @expected_message = self end |
#with_severity(severity) ⇒ Object
344 345 346 347 |
# File 'lib/brainzlab/testing/matchers.rb', line 344 def with_severity(severity) @expected_severity = severity self end |