title: Testing stubbed callback in associated model
body: <p>I have two models, linked by simple one-to-many relation.</p>
  
  <pre><code>class Device
    has_many :events
  
    def notify!
      (...)
    end
  end
  
  class Event
    after_create :notify_device
    belongs_to :device
  
    private
  
    def notify_device
      device.notify!
    end
  end
  </code></pre>
  
  <p><code>Device#notify!</code> method has to be stubbed in tests, as in normal flow it triggers communication with device linked via RS-232, which obviously may not be available in test environment (not to mention it shouldn't be notified in tests).</p>
  
  <p>I was trying to set <code>should_receive</code> expectation on <code>device</code> object created by FactoryGirl, but <code>device</code> method used in <code>Event</code> class returns different object, which doesn't know about that expectation.</p>
  
  <p>How to write rspec test that would test the fact that <code>#notify!</code> is called on proper device?</p>