Stub @asset's :video first, i.e.<br><br>@mock_video_proxy = mock("assay.video proxy")<br>@asset.stub!(:video).and_return(@mock_video_proxy)<br>@assay.video.stub!(:hook).and_return @mock_hook<br><br>Generally mocking starts to get frustrating when the code you're mocking doesn't follow the Law of Demeter. I have been creating helper methods for these things,
e.g.<br><br>def mock_video_proxy<br> @mock_video_proxy ||= begin<br> proxy = mock("assay.video proxy")<br> @asset.stub!(:video).and_return(proxy)<br> proxy<br> end<br> proxy<br>end<br>
<br>so you can just use<br><br>mock_video_proxy.stub!(:hook).and_return @mock_hook<br><br>in any spec. I think there might be a better way, though. I'm not sure it's worth it to use mocks in this situation since you're already using fixtures. Why not just check the expected outcome of the hook method?
<br><br>Moses<br><br><div><span class="gmail_quote">On 6/26/07, <b class="gmail_sendername">Pat Maddox</b> <<a href="mailto:pergesu@gmail.com">pergesu@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
describe Asset, " when destroyed" do<br> fixtures :assets, :videos, :sites, :publish_settings<br><br> before(:each) do<br> @asset = assets(:test_asset)<br> @mock_hook = mock("hook")<br> @asset.video.stub!
(:hook).and_return @mock_hook # error occurs here<br> end<br><br> it "should call the delete hook" do<br> @mock_hook.should_receive(:update).with("test_video", :asset_id =><br>@assetid, :asset_action => "destroy")
<br> @asset.destroy<br> end<br>end<br><br>NameError in 'Asset when destroyed should call the delete hook'<br>undefined method `hook' for class<br>`ActiveRecord::Associations::BelongsToAssociation'<br><br>
I'm not sure why I can't stub the hook method on the video proxy...I<br>need to though, because my implementation is<br><br>video.hook.update....<br><br>Any ideas?<br>Pat<br>_______________________________________________
<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>
<br></blockquote></div><br>