title: Custom ActionMailer delivery method not called from rspec test
body: <p>I'm trying to write an rspec test that will send an email using my custom delivery method for ActionMailer.</p>
  
  <p>My custom delivery method implementation:</p>
  
  <pre><code>class MyCustomDeliveryMethod  
  
    def deliver!(message)
      puts 'Custom deliver for message: ' + message.to_s
      ...
    end
  </code></pre>
  
  <p>Rspec code:</p>
  
  <pre><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 =&gt; 'me@example.com',
      :subject =&gt; 'here is a test subject sent by ActionMailer',
      :body =&gt; 'here is a test body sent by &lt;i&gt;ActionMailer&lt;/i&gt;',
      :delivery_method =&gt; :api 
    )
  
  end
  </code></pre>
  
  <p>test.rb</p>
  
  <pre><code>config.action_mailer.delivery_method = :api
  </code></pre>
  
  <p>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? </p>
  
  <p>(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).</p>