[rspec-users] Can I stub a method on a belongs_to association:

Pat Maddox pergesu at gmail.com
Tue Jun 26 15:52:32 EDT 2007


describe Asset, " when destroyed" do
  fixtures :assets, :videos, :sites, :publish_settings

  before(:each) do
    @asset = assets(:test_asset)
    @mock_hook = mock("hook")
    @asset.video.stub!(:hook).and_return @mock_hook   # error occurs here
  end

  it "should call the delete hook" do
    @mock_hook.should_receive(:update).with("test_video", :asset_id =>
@assetid, :asset_action => "destroy")
    @asset.destroy
  end
end

NameError in 'Asset when destroyed should call the delete hook'
undefined method `hook' for class
`ActiveRecord::Associations::BelongsToAssociation'

I'm not sure why I can't stub the hook method on the video proxy...I
need to though, because my implementation is

video.hook.update....

Any ideas?
Pat


More information about the rspec-users mailing list