test_mailer.rb |
|
---|---|
|
module Newman
class TestMailer |
|
|
To initialize a
However, there are handful of caveats worth knowing about this constructing an instance of this particular object. 1) Most unit tests won’t need a 2) Because there isn’t an obvious way to work with test objects in the
underlying mail gem without relying on global state,
3) The settings object is not actually used, and is only part of the signature for API compatibility reasons. With these caveats in mind, be sure to think long and hard about whether you actually need to explicitly build instances of this object before doing so :) |
class << self
def new(settings)
return self.instance if instance
Mail.defaults do
retriever_method :test
delivery_method :test
end
self.instance = allocate
end
attr_accessor :instance
end |
|
|
Keep in mind that because only a single |
def messages
msgs = Marshal.load(Marshal.dump(Mail::TestMailer.deliveries))
Mail::TestMailer.deliveries.clear
msgs
end |
|
|
|
def new_message(*a, &b)
Mail.new(*a, &b)
end |
|
|
|
def deliver_message(*a, &b)
new_message(*a, &b).deliver
end
end
end |