Class: BrainzLab::Testing::Matchers::HaveSentAlertMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/brainzlab/testing/matchers.rb

Overview

Matcher for alerts

Instance Method Summary collapse

Constructor Details

#initializeHaveSentAlertMatcher

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

#descriptionObject



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_messageObject



358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/brainzlab/testing/matchers.rb', line 358

def failure_message
  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_negatedObject



371
372
373
# File 'lib/brainzlab/testing/matchers.rb', line 371

def failure_message_when_negated
  "expected alert '#{@alert_name}' not to have been sent, but it was"
end

#matches?(alert_name) ⇒ Boolean

Returns:

  • (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 with_message(message)
  @expected_message = 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