Stub @asset&#39;s :video first, i.e.<br><br>@mock_video_proxy = mock(&quot;assay.video proxy&quot;)<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&#39;re mocking doesn&#39;t follow the Law of Demeter. I have been creating helper methods for these things, 
e.g.<br><br>def mock_video_proxy<br>&nbsp; @mock_video_proxy ||= begin<br>&nbsp;&nbsp;&nbsp; proxy = mock(&quot;assay.video proxy&quot;)<br>&nbsp;&nbsp;&nbsp; @asset.stub!(:video).and_return(proxy)<br>&nbsp; &nbsp; proxy<br>&nbsp; end<br>&nbsp; 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&#39;m not sure it&#39;s worth it to use mocks in this situation since you&#39;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> &lt;<a href="mailto:pergesu@gmail.com">pergesu@gmail.com</a>&gt; 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, &quot; when destroyed&quot; do<br>&nbsp;&nbsp;fixtures :assets, :videos, :sites, :publish_settings<br><br>&nbsp;&nbsp;before(:each) do<br>&nbsp;&nbsp;&nbsp;&nbsp;@asset = assets(:test_asset)<br>&nbsp;&nbsp;&nbsp;&nbsp;@mock_hook = mock(&quot;hook&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;@asset.video.stub!
(:hook).and_return @mock_hook&nbsp;&nbsp; # error occurs here<br>&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;it &quot;should call the delete hook&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp;@mock_hook.should_receive(:update).with(&quot;test_video&quot;, :asset_id =&gt;<br>@assetid, :asset_action =&gt; &quot;destroy&quot;)
<br>&nbsp;&nbsp;&nbsp;&nbsp;@asset.destroy<br>&nbsp;&nbsp;end<br>end<br><br>NameError in &#39;Asset when destroyed should call the delete hook&#39;<br>undefined method `hook&#39; for class<br>`ActiveRecord::Associations::BelongsToAssociation&#39;<br><br>
I&#39;m not sure why I can&#39;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>