title: Rspec: Mocked payload is returning nil instead of the actual object created for testing purposes
body: <p>I've created the following service</p>
  <pre><code>class ApiCustomers &lt; ApiBase
    def initialize(url: nill)
      url = url.presence || ENV.fetch(&quot;CUSTOMERS_API_APP_NAME&quot;)
      super(url)
    end
  
    def find_customer_apps(customer_id, params=nil)
      begin
        customer_url = &quot;#{@url}/customers/#{customer_id}/applications&quot;
        # call api-customers
        if params.nil?
          response = connection.get(customer_url)
        else
          response = connection.get(customer_url, params)
        end
      rescue StandardError =&gt; e
        Rails.logger.error &quot;Error fetching API-CUSTOMERS Applications: #{e}&quot;
        raise e
      end
  
      return response.body[&quot;data&quot;]
    end
  end
  </code></pre>
  <p>Now, I want to test that with the following code:</p>
  <pre><code>require &quot;rails_helper&quot;
  
  RSpec.describe ApiCustomers do
    let(:customer_id) { SecureRandom.uuid }
    let(:customers_client) { ApiCustomers.new(url: &quot;api_customers.local&quot;) }
  
    context &quot;#find_customer_apps&quot; do
      let(:app) { double(&quot;application&quot;, id: 123, name: &quot;App&quot;, customer_id: &quot;123&quot;, supported: false, additional_notes: &quot;Test&quot;) }
      let(:success_response) { OpenStruct.new({ status: 200, body: { &quot;data&quot;: app } }) }
      let(:bad_request) { OpenStruct.new({ status: 400, body: {&quot;error&quot;=&gt;&quot;invalid call&quot;} }) }
  
      describe &quot;with valid params&quot; do
        before do
          allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(success_response)
        end
  
        it &quot;returns customer applications&quot; do
          applications_payload = customers_client.find_customer_apps(account_id, nil)
  
  
          expect(applications_payload).not_to be_nil
        end
      end
  
      describe &quot;with invalid params&quot; do
        before do
          allow_any_instance_of(Faraday::Connection).to receive(:get).and_raise(CustomErrors::BadRequest)
        end
  
        it &quot;raises an error&quot; do
          expect { customers_client.find_customer_apps(nil, nil) }.to raise_error(CustomErrors::BadRequest)
        end
      end
    end
  end
  </code></pre>
  <p>The test <code>with invalid params</code> is working, but for some reason the one <code>with valid params</code> is failing.</p>
  <p>If I print the <code>success_response</code>, this is being created properly. I do not know what I am getting <code>nil</code> in my <code>applications_paylod</code>. What I am missing? I thought this line should cover what I am doing: <code>allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(success_response)</code></p>
  <p>Thanks in advance.</p>