title: RSpec, ActiveJob, Sidekiq: Avoid jobs from being fired when testing another job?
body: <p>I am testing the <strong>ParseProjectsJob</strong> which fires the <strong>PushProjectJob</strong> when it's done. I need to avoid this behaviour, here's what the <strong>ParseProjectsJob</strong> looks like:</p>
  
  <p>Have in mind that I'm using Sidekiq::Testing.inline! in my parse_project_spec.rb.</p>
  
  <pre><code># [...] = Omitted code.
  
  [...]
  class ParseProjectsJob &lt; ActiveJob::Base
    [...]
    def perform
        [...]
        PushProjectJob.set(wait: to_wait.second).
          perform_later({:project =&gt; onvia_project, :budget_years =&gt; @project_budget_years})
        [...]
    end
    [...]
  end
  [...]
  </code></pre>
  
  <p>So I've tried in my <strong>parse_projects_job_spec.rb</strong>:</p>
  
  <pre><code>allow_any_instance_of(PushProjectJob).to receive('perform_later') { true }
  </code></pre>
  
  <p>Outputs:
  <strong>PushProjectJob does not implement #perform_later</strong></p>
  
  <p>Also tried:</p>
  
  <pre><code>allow_any_instance_of(PushProjectJob).to receive('perform') { true }
  </code></pre>
  
  <p>It passes but the job is fired anyway.</p>
  
  <p>And at last I've tried:</p>
  
  <pre><code>allow_any_instance_of(PushProjectJob).to receive_message_chain('set.perform_later') { true }
  </code></pre>
  
  <p>Outputs: <strong>PushProjectJob does not implement #set</strong></p>
  
  <p><strong>parse_projects_job_spec.rb</strong>:</p>
  
  <pre><code>require 'rails_helper'
  require 'sidekiq/testing'
  require 'fileutils'
  
  RSpec.describe ParseProjectsJob, type: :job do
    Sidekiq::Testing.inline!
  
    let(:perform_job) {
      allow(PushProjectJob).to receive_message_chain('set.perform_later') { true }
      exitable { ParseProjectsJob.perform_later }
    }
  
    let(:download_valid_file) {
      FileUtils.cp 'spec/fixtures/projects_sheets/valid_file.xlsx',
        Rails.root.join('public', 'downloads', 'projects_sheet')
    }
  
    describe "#perform" do
      it "parse and push all projetcs inside a sheet" do
        download_valid_file
        perform_job
        expect(Job.projects_parse.with_success.last.
          actions.last.message).
          to eql('No more files to parse, the job is done.')
      end
    end
  end
  </code></pre>