title: Rails/Rspec: Testing delayed_job mails
body: <p>Just wondering how to test that actionmailer requests are actually sent to the delayed_job que in rspec.</p>
  
  <p>I would have assumed it was quite simple, but my delayed_job queue doesn't seem to be incrementing. Code below:</p>
  
  <p>Controller:</p>
  
  <pre><code>  def create
      @contact = Contact.new(params[:contact])
        if @contact.save
          contactmailer = ContactMailer
          contactmailer.delay.contact_message(@contact)
          redirect_to(contacts_url)
        else
          render :action =&gt; "new"
        end
  </code></pre>
  
  <p>Spec:</p>
  
  <pre><code>  it "queues mail when a contact is created" do
      expectedcount = Delayed::Job.count + 1
      Contact.stub(:new).with(mock_contact()) { mock_contact(:save =&gt; true) }
      post :create, :contact =&gt; mock_contact
      expectedcount.should eq(Delayed::Job.count)
    end
  </code></pre>
  
  <p>Both before and after the call to the controller, the Delayed::Job.count returns 0. I've tried taking the conditional out of the controller, but I still can't get the delayed job count to increment.</p>
  
  <p>Any suggestions appreciated - cheer</p>