title: How do you expect a mailer function to be called with .deliver in Rspec?
body: <p>I have a test on a service <code>EmailTrainersAboutMissingReports.call</code> that expects it to call <code>TrainerMonitorMailer.missing_run_reports</code>:</p>
  
  <pre><code>describe EmailTrainersAboutMissingReports do
  
    describe ('::call') do
  
      context 'missing two group runs' do
  
        let!(:group_run)    { FactoryGirl.create :group_run, started_at: 1.day.ago }
        let!(:group_run_2)  { FactoryGirl.create :group_run, started_at: 1.day.ago }
  
        it 'is successful' do
          expect(TrainerMonitorMailer).to receive(:missing_run_reports).with(area,
                                                  [group_run, group_run_2])
          EmailTrainersAboutMissingReports.call
        end
  
      end
  
    end
  
  end
  </code></pre>
  
  <p>The code for the accompanying service looks like this:</p>
  
  <pre><code>class EmailTrainersAboutMissingReports
  
    def self.call
      response = RunReportMonitor.check_all_got_published_on_time(area)
      unless response.success?
        TrainerMonitorMailer.missing_run_reports(area, response.group_runs_missing_reports).deliver
      end
    end
  
  end
  </code></pre>
  
  <p>Where I'm running into trouble is that I chain the <code>deliver</code> method onto the mailer. So when I run the test I receive:</p>
  
  <pre><code>undefined method `deliver' for nil:NilClass
  </code></pre>
  
  <p>How can I define the expectation such that it expects missing_run_reports with the parameters above, but also expects this chained to call .deliver?</p>