title: Within a feature spec, how to test that a Devise mailer is called successfully?
body: <p>I have a feature test for user registration. How do I test that Devise confirmation instructions are sent correctly? I don't need to test the content of the email, only that the mailer has been called. </p>
  
  <p>I am sending mails in the background. </p>
  
  <pre><code>#user.rb    
  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end
  </code></pre>
  
  <p>I have tried a few approaches that work for other mailers, including </p>
  
  <pre><code>it "sends the confirmation email" do
    expect(Devise.mailer.deliveries.count).to eq 1
  end
  </code></pre>
  
  <p>and </p>
  
  <pre><code>it "sends the confirmation email" do
    message_delivery = instance_double(ActionMailer::MessageDelivery)
    expect(Devise::Mailer).to receive(:confirmation_instructions).and_return(message_delivery)
    expect(message_delivery).to receive(:deliver_later)
  end
  </code></pre>
  
  <p>none of which are working as expected for Devise messages. </p>
  
  <p>What am I doing wrong? </p>
  
  <h2>Edit</h2>
  
  <p>The feature spec looks like this:</p>
  
  <pre><code>feature "User signs up"  do
    before :each do
      visit '/'
      click_link 'Sign up'
      fill_in 'user_email', with: valid_attributes[:email]
      fill_in 'user_password', with: valid_attributes[:password]
      fill_in 'user_password_confirmation', with: valid_attributes[:password]
      click_button 'Sign up'
    end
    it "sends the confirmation email" ...
  
  end
  </code></pre>