Class: RhizMail::MockMailer

Inherits:
Object
  • Object
show all
Defined in:
lib/rhizmail.rb

Overview

The MockMailer can be swapped out for the Mailer in test code, and then queried to make sure that the right emails were sent out. To set this, call

mock_mailer = RhizMail::MockMailer.new
RhizMail::Mailer.set_mailer mock_mailer

Afterwards, every time you call Message#deliver it will be delivered by the MockMailer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMockMailer

Returns a new instance of MockMailer.



251
# File 'lib/rhizmail.rb', line 251

def initialize; flush; end

Instance Attribute Details

#messages_sentObject (readonly)

Returns the value of attribute messages_sent.



249
250
251
# File 'lib/rhizmail.rb', line 249

def messages_sent
  @messages_sent
end

Instance Method Details

#flushObject

Clear out the history of messages sent.



254
# File 'lib/rhizmail.rb', line 254

def flush; @messages_sent = []; end

#send_message(email) ⇒ Object

Pretends to send an email, recording it in messages_sent to allow inspection later.



258
259
260
261
# File 'lib/rhizmail.rb', line 258

def send_message(email)
  email.verify_sendable
  @messages_sent << email
end