title: Rspec allow and expect the same method with different arguments
body: <p>I want to test my method which runs method Temp::Service.run two times inside it:</p>
  
  <pre><code>module Temp
    class Service
  
      def self.do_job
        # first call step 1
        run("step1", {"arg1"=&gt; "v1", "arg2"=&gt;"v2"})
  
  
        # second call step 2
        run("step2", {"arg3"=&gt; "v3"})
  
  
      end
  
      def self.run(name, p)
        # do smth
  
        return true
      end
  
  
    end
  end
  </code></pre>
  
  <p>I want to test arguments provided to second call of method :run with first argument 'step2'
  while I want to ignore the first call of the same method :run but with first argument 'step1'.</p>
  
  <p>I have the RSpec test</p>
  
  <pre><code>RSpec.describe "My spec", :type =&gt; :request do
  
    describe 'method' do
      it 'should call' do
  
        # skip this
        allow(Temp::Service).to receive(:run).with('step1', anything).and_return(true)
  
        # check this
        expect(Temp::Service).to receive(:run) do |name, p|
          expect(name).to eq 'step2'
  
          # check p
          expect(p['arg3']).not_to be_nil
  
        end
  
  
        # do the job
        Temp::Service.do_job
  
      end
    end
  end
  </code></pre>
  
  <p>but I got error</p>
  
  <pre><code>expected: "step2"
       got: "step1"
  
  (compared using ==)
  </code></pre>
  
  <p>How to correctly use allow and expect for the same method ?</p>