Class: Newman::TestMailer

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



57
58
59
# File 'lib/newman/test_mailer.rb', line 57

def instance
  @instance
end

Class Method Details

.new(settings) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/newman/test_mailer.rb', line 46

def new(settings)
  return self.instance if instance

  Mail.defaults do
    retriever_method :test
    delivery_method  :test      
  end

  self.instance = allocate
end

Instance Method Details

#deliver_message(*a, &b) ⇒ Object

Newman::TestMailer#deliver_message method is used to construct and immediately deliver a message with the delivery settings set to test mode.



96
97
98
# File 'lib/newman/test_mailer.rb', line 96

def deliver_message(*a, &b)
  new_message(*a, &b).deliver
end

#messagesObject

Newman::TestMailer#messages is used to retrieve all messages currently in the inbox and then delete them from the underlying Mail::TestMailer object so that the inbox gets cleared. This method returns an array of Mail::Message objects if any messages were found, and returns an empty array otherwise.

Keep in mind that because only a single Newman::TestMailer ever gets instantiated no matter how many times you call Newman::TestMailer.new, you only get one test inbox per process.



72
73
74
75
76
77
# File 'lib/newman/test_mailer.rb', line 72

def messages
  msgs = Marshal.load(Marshal.dump(Mail::TestMailer.deliveries))
  Mail::TestMailer.deliveries.clear

  msgs
end

#new_message(*a, &b) ⇒ Object

Newman::TestMailer#new_message is used to construct a new Mail::Message object, with the delivery settings set to test mode. This method passes all its arguments on to Mail.new, so be sure to refer to the mail gem's documentation for details.



87
88
89
# File 'lib/newman/test_mailer.rb', line 87

def new_message(*a, &b)
  Mail.new(*a, &b)
end