title: How to spy just one call of ActiveSupport::Notifications #instrument, not all of them
body: <p>I'm making a Rspec test that checks if <code>ActiveSupport::Notification.instrument</code> was called with some parameters.</p>
  
  <p>The thing is that in order to make this test a need <code>FactoryBot</code> to build some objects, but when I try to spy on <code>ActiveSupport::Notification.instrument</code> I always get an error:</p>
  
  <pre><code>ActiveSupport::Notifications received :instrument with unexpected arguments
           expected: (:asd)
                got: ("factory_bot.run_factory", {:factory=&gt;#&lt;FactoryBot::Factory:0x005569b6d30, @al... nil, dispatch: nil, distribution_state: 2, main_category_id: nil&gt;}, :strategy=&gt;:build, :traits=&gt;[]})
  </code></pre>
  
  <p>It seems that FactoryBot calls activesupport so when I mock it for my test purpose I end up mocking it too far...</p>
  
  <p>code example:</p>
  
  <p>class:</p>
  
  <pre><code>class SomeObject
      def initialize(something)
          #some code
      end
  
      def my_method
          ActiveSupport::Notifications.instrument :asd
      end
  end
  </code></pre>
  
  <p>spec:</p>
  
  <pre><code>describe "#my_method" do
      let(:some_object) { build :some_object }
      before do
        allow(ActiveSupport::Notifications).to receive(:instrument).with :asd
      end
  
      it "calls notifier" do
        described_class.new(some_object).my_method
  
        expect(ActiveSupport::Notifications).to have_received(:instrument).with :asd
      end
    end
  </code></pre>
  
  <p>How can I just mock my call and not FactoryBot's .</p>
  
  <p>I only manage that with one more <code>allow</code> before the one that mocks <code>:asd</code>:</p>
  
  <pre><code> allow(ActiveSupport::Notifications).to receive(:instrument).and_call_original
  </code></pre>
  
  <p>Is there another(better) way?</p>