title: Rspec: expect an association to receive a message
body: <p>I'm in Rails 6 with Rspec 3.8.0.</p>
  
  <p>I have a model <code>A</code> which <code>belongs_to</code> B. And I'm trying to write a unit test with <code>A</code> as <code>subject</code>:</p>
  
  <pre><code>expect(subject.b).to receive(:to_s)
  subject.my_fn
  </code></pre>
  
  <p>Yet this spec always fails, saying that the instance of <code>B</code> did not receive the message, notwithstanding I have put <code>binding.pry</code> in the actual code to run and verified that <code>a.b.to_s</code> gets called:</p>
  
  <pre><code>class A
    def my_fn
      binding.pry
      b.to_s
    end
  end
  </code></pre>
  
  <p>I have even tried:</p>
  
  <pre><code>expect(a).to receive(:b).and_return(b)
  expect(b).to receive(:to_s)
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>expect_any_instance_of(b.class).to receive(:to_s)
  </code></pre>
  
  <p>Yet all expectations for <code>to_s</code> fail. Why is this?</p>