title: RSpec Stubbing Service Object Method
body: <p>I'm having an issue with stubbing out a call to a service object (QuickbooksService) from an AR object. As far as I can tell the method should be stubbed properly and return the value I'm specifying but when I run the spec I can see the method being called and failing.</p>
  
  <p>Here's the class definition of the object I'm testing.</p>
  
  <pre><code>class Order &lt; ActiveRecord::Base
    def create_invoice
      QuickbooksService.new(:estimate).create_invoice(arg1, arg2, arg3)
    end
  end
  </code></pre>
  
  <p>And from order_spec</p>
  
  <pre><code>describe("#create_invoice") do
    expect(QuickbooksService.new(:estimate)).to receive(:create_invoice).and_return(1)
  end
  </code></pre>
  
  <p>I've also tried</p>
  
  <pre><code>allow(QuickbooksService.new(:estimate)).to receive(:form_invoice_create).with(anything()).and_return(1)
  </code></pre>
  
  <p>So instead of returning <code>1</code> the <code>create_invoice</code> method is being executed inside of QuickbooksService. Any insight would be appreciated!</p>