<span class="gmail_quote">On 1/10/08, <b class="gmail_sendername">David Chelimsky</b> <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:</span><br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
album = mock("album")<br>songs = mock("songs")<br>album.stub!(:songs).and_return(songs)<br>songs.stub!(:streamable).and_return(true)<br><br>That's the general idea. Specifics will vary for each example.
</blockquote><div><br>If I do this, I end up with a mock object when I call @album.songs. I need that object to act like a Rails association -- so it should respond to #each, #first, and all our other Enumerable friends, since my view iterates over it, as well as the stubbed call to #streamable, which returns a "filtered" version of the assocation (see Rails code in OP). But I certainly don't want to start stubbing Enumerable methods.
<br><br># Let's say song1, song2, and song3 are instances of Song.<br># Song has a boolean attribute, streamable.<br># song1.streamable? => true<br># song2.streamable? => true<br># song3.streamable? => false<br>
album = mock("album")<br>songs = mock("songs")<br>album.stub!(:songs).and_return(songs)<br>songs.stub!(:streamable).and_return([song1, song2])<br><br>So now album.songs.streamable returns [song1, song2] -- perfect. But I need
album.songs to return [song1, song2, song3] as well. That's the problem.<br><br>I hope that's a little clearer. Thanks for the help.<br><br>Chris<br></div></div>