Class: BrainzLab::Testing::AlertExpectation

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

Overview

Fluent expectation builder for alerts

Instance Method Summary collapse

Constructor Details

#initialize(name, store) ⇒ AlertExpectation

Returns a new instance of AlertExpectation.



600
601
602
603
604
605
# File 'lib/brainzlab/testing/helpers.rb', line 600

def initialize(name, store)
  @name = name.to_s
  @store = store
  @expected_message = nil
  @expected_severity = nil
end

Instance Method Details

#failure_messageObject



637
638
639
640
641
642
643
# File 'lib/brainzlab/testing/helpers.rb', line 637

def failure_message
  parts = ["expected alert '#{@name}'"]
  parts << "with message '#{@expected_message}'" if @expected_message
  parts << "with severity :#{@expected_severity}" if @expected_severity
  parts << " to be sent, but it wasn't"
  parts.join
end

#failure_message_when_negatedObject



645
646
647
# File 'lib/brainzlab/testing/helpers.rb', line 645

def failure_message_when_negated
  "expected alert '#{@name}' not to be sent, but it was"
end

#satisfied?Boolean Also known as: matches?

Check if the expectation is satisfied

Returns:

  • (Boolean)


631
632
633
# File 'lib/brainzlab/testing/helpers.rb', line 631

def satisfied?
  @store.alert_sent?(@name, message: @expected_message, severity: @expected_severity)
end

#with_message(message) ⇒ self

Specify expected message

Parameters:

  • message (String)

    Message to match

Returns:

  • (self)


612
613
614
615
# File 'lib/brainzlab/testing/helpers.rb', line 612

def with_message(message)
  @expected_message = message
  self
end

#with_severity(severity) ⇒ self

Specify expected severity

Parameters:

  • severity (Symbol)

    Severity to match

Returns:

  • (self)


622
623
624
625
# File 'lib/brainzlab/testing/helpers.rb', line 622

def with_severity(severity)
  @expected_severity = severity
  self
end