title: Sending an email with Sidekiq RSpec Test failed because Array is empty and could not change from 0 to 1
body: <p>I am trying to test sending an email with Sidekiq and I am having an error which means it doesn't enqueue since my test shows it didn't change from 0 to 1 in size. Could it be I am missing something out or how can I fix this?</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>expected `Array#size` to have changed by 1, but was changed by 0
  
    0) Sending Mail sends email to sidekiq
       Failure/Error:
         expect do
           OrderPointsMailer.paid_order_email(customer_detail.id).deliver_later
         end.to change(Sidekiq::Worker.jobs, :size).by(1)
  
         expected `Array#size` to have changed by 1, but was changed by 0
       # ./spec/requests/order_points_mailer_spec.rb:9:in `block (2 levels) in &lt;top (required)&gt;'
  
  1 example, 1 failure, 0 passed
  </code></pre>
  
  <p><strong>binding.pry</strong></p>
  
  <p>This shows <code>Sidekiq::Worker.jobs</code> is <code>empty array</code> and it is understandable why it failed but I do not know how I could fix this.</p>
  
  <pre><code>[1] pry(#&lt;RSpec::ExampleGroups::SendingMailWithSidekiq&gt;)&gt;Sidekiq::Worker.jobs
  =&gt; []
  </code></pre>
  
  <p><strong>app/jobs/order_points_job.rb</strong></p>
  
  <pre><code># frozen_string_literal: true
  
  class OrderPointsJob &lt; ApplicationJob
    def perform(customer_email)
      customer_detail = CustomerDetail.find_by(email: customer_email)
      return unless customer_detail
  
      OrderPointsMailer.paid_order_email(customer_detail.id).deliver_later # This call send email to sidekiq process
    end
  end
  </code></pre>
  
  <p><strong>RSpec</strong></p>
  
  <pre><code># frozen_string_literal: true
  
  require 'rails_helper'
  
  RSpec.describe 'Sending Mail with Sidekiq', type: :request do
    it 'sends email to sidekiq' do
      customer_detail = create(:customer_detail)
  
      expect do
        OrderPointsMailer.paid_order_email(customer_detail.id).deliver_later
      end.to change(Sidekiq::Worker.jobs, :size).by(1)
    end
  end
  </code></pre>
  
  <p><strong>rails_helper.rb</strong></p>
  
  <pre><code>require 'sidekiq/testing'
  Sidekiq::Testing.fake!
  </code></pre>