I'm trying to write an rspec test that will send an email using my custom delivery method for ActionMailer.
My custom delivery method implementation:
class MyCustomDeliveryMethod
def deliver!(message)
puts 'Custom deliver for message: ' + message.to_s
...
end
Rspec code:
it "should send an email" do
WebMock.allow_net_connect!
ActionMailer::Base.add_delivery_method( :api, MyCustomDeliveryMethod)
ActionMailer::Base.perform_deliveries = true
puts 'expecting this to call my custom delivery method'
ActionMailer::Base.mail( :to => '[email protected]',
:subject => 'here is a test subject sent by ActionMailer',
:body => 'here is a test body sent by <i>ActionMailer</i>',
:delivery_method => :api
)
end
test.rb
config.action_mailer.delivery_method = :api
However I never see the 'custom deliver' string. My other tests exercise the other methods of the class fine, it's just the triggering of the deliver!() method doesnt work. What am I missing?
(NB. there are a few examples around of testing ActionMailers with rspec, however they seem to refer to mocking the mailer behaviour, which is not what I want - I want the actual email to go out).
MyCustomMailer
mailer should be inherited from standartActionMailer::Base
, shouldn't it? – Aleksey