Sorry for so many messages, I hope I don&#39;t get in trouble for this. Maybe IRC would be better if there was a RSpec one.<div><br class="webkit-block-placeholder"></div><div>Anyway, the previous problem was solved with the following&nbsp;
<span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px; "><a href="http://pastie.textmate.org/private/m6qqfd7tzeanw2yar8rua">http://pastie.textmate.org/private/m6qqfd7tzeanw2yar8rua</a></span></div>
<div><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px;"><br class="webkit-block-placeholder"></span></div><div><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px;">The problem was caused by :
</span></div><div><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px;"><br class="webkit-block-placeholder"></span></div><div><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px;">
<div>&nbsp;&nbsp; &nbsp;@user = mock_model(User, :writings =&gt; [] )</div><div><br class="webkit-block-placeholder"></div><div>I&#39;m not sure if that is a bug or what, but that&#39;s what caused it.</div></span><div><br class="webkit-block-placeholder">
</div><div>It&#39;d also say &quot;no block given&quot; if I put something there other than a &quot;mock&quot;.</div><br><div class="gmail_quote">On Dec 3, 2007 10:33 PM, Fischer, Daniel &lt;<a href="mailto:me@danielfischer.com">
me@danielfischer.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Alright, thanks, I&#39;m getting more progress in this. As soon as I figure this out I won&#39;t have too many problems.. hopefully.
<div><br></div><div>Anyone know what &quot;undefined method `call&#39; for &quot;1&quot;:String&quot; means?
</div><div><br></div><div>I&#39;m trying to do this:</div><div><br></div><div><p style="margin:0.0px 0.0px 0.0px 0.0px;font:12.0px Helvetica"></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:12.0px Helvetica">
<a href="http://pastie.textmate.org/private/17jjjmbave0ph2mkcgp6w" target="_blank">http://pastie.textmate.org/private/17jjjmbave0ph2mkcgp6w</a></p><p style="margin:0.0px 0.0px 0.0px 0.0px;font:12.0px Helvetica"><br>
</p><p></p></div><div><div></div><div class="Wj3C7c"><div><div class="gmail_quote">On Dec 3, 2007 9:33 PM, David Chelimsky &lt;<a href="mailto:dchelimsky@gmail.com" target="_blank">dchelimsky@gmail.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Dec 3, 2007 10:26 PM, Fischer, Daniel &lt;<a href="mailto:me@danielfischer.com" target="_blank">me@danielfischer.com</a>&gt; wrote:<br>&gt; Hey cool, thanks for the help guys. One problem though, when I take this
<br>
&gt; approach I can&#39;t decouple the specs anymore. They all &quot;User_xxx receive<br>&gt; unexpected message :articles&quot;. It seems silly to include all behaviors in<br>&gt; one spec, or put that expectation in each test. Is there a way around this?
<br><br></div>Sure. Create a method somewhere that generates a baseline stub for you.<br><br>module UserControllerSpecHelper<br> &nbsp;def create_stub_user<br> &nbsp; &nbsp;mock_model(User, :articles =&gt; [])<br> &nbsp;end<br>end<br><br>describe UserController, &quot;...&quot; do
<br> &nbsp;include UserControllerSpecHelper<br> &nbsp;before(:each) do<br> &nbsp; &nbsp;@user = create_stub_user<br> &nbsp;end<br>end<br><br>If there are other methods &nbsp;you need to stub on all instances of user,<br>do it in the helper. Then you can use message expectations (mocks)
<br>where you need them to describe specific behaviour.<br><br>HTH,<br><font color="#888888">David<br></font><div><div></div><div><br>&gt;<br>&gt; Thanks for all the help,<br>&gt; Daniel Fischer<br>&gt; <a href="http://www.danielfischer.com" target="_blank">

http://www.danielfischer.com</a><br>&gt;<br>&gt;<br>&gt;<br>&gt; On Dec 3, 2007 2:44 AM, Daniel N &lt; <a href="mailto:has.sox@gmail.com" target="_blank">has.sox@gmail.com</a>&gt; wrote:<br>&gt; &gt; Assuming that there is a call like this in your controller
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; @articles = current_user.articles<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; One way to do this is to stub out the controller.current_user to return a<br>&gt; mock object of the current_user
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Then put an expectation on the current user that it&#39;s articles method gets<br>&gt; called. (return a mocked collection of articles)<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Then check that @articles is set to the returned mocked collection of
<br>&gt; articles from current_user.articles<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; phew...<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Ok So one way you might write this could be (This is untested...)<br>&gt; &gt;<br>&gt; &gt;
<br>&gt; &gt; it &quot;should scope the articles to the currrent_user&quot; do<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; &nbsp; user = mock_model(User)<br>&gt; &gt; &nbsp; articles = [mock_model(Article)]<br>&gt; &gt;<br>&gt; &gt;<br>

&gt; &gt; &nbsp; controller.stub!(:current_user).and_return(user)<br>&gt; &gt;<br>&gt; &gt; &nbsp; user.should_receive (:articles).and_return(articles)<br>&gt; &gt;<br>&gt; &gt; &nbsp; get :index<br>&gt; &gt;<br>&gt; &gt; &nbsp; assigns[:articles].should == articles
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; end<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Like I said though, that&#39;s not tested itself. &nbsp;If that&#39;s not exactly<br>&gt; right... it&#39;s along the right track of an option that can work.
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; HTH<br>&gt; &gt; Daniel<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; On Dec 3, 2007 9:07 PM, Stefan Magnus Landrø &lt;<a href="mailto:stefan.landro@gmail.com" target="_blank">
stefan.landro@gmail.com
</a>&gt;<br>&gt; wrote:<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; &gt; Typically, I&#39;d write a method in your user model that returns the user&#39;s<br>&gt; articles:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; class User do
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &nbsp; def find_articles_for_user<br>&gt; &gt; &gt; &nbsp; &nbsp;Article.find(:all, :conditions =&gt; [&#39;userid = ?&#39;, id)<br>&gt; &gt; &gt; &nbsp; end<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; end<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; Then you&#39;d use a mock in your controller spec, and make sure you test<br>&gt; that your method is being called.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On the other hand, the user model should be tested directly against the
<br>&gt; db.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; HTH,<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Stefan<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; 2007/12/3, Fischer, Daniel &lt;<a href="mailto:daniel@helpmebuyacar.org" target="_blank">

daniel@helpmebuyacar.org</a>&gt;:<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Let&#39;s say you&#39;re using the restful_authentication plugin.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;
<br>&gt; &gt; &gt; &gt; You have a model called articles. On the index action of the<br>&gt; articlescontroller you simply want to spec out that it&#39;ll scope the results<br>&gt; to the ownership of the current_user.<br>

&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; It should NOT include any articles other than the articles that user<br>&gt; owns.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; How would you properly spec this out?
<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Thanks for the help!<br>&gt; &gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; &gt; rspec-users mailing list<br>&gt; &gt; &gt; &gt; 
<a href="mailto:rspec-users@rubyforge.org" target="_blank">rspec-users@rubyforge.org</a><br>&gt; &gt; &gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users
</a><br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; --<br>&gt; &gt; &gt; Bekk Open Source<br>&gt; &gt; &gt; <a href="http://boss.bekk.no" target="_blank">http://boss.bekk.no
</a><br>&gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; rspec-users mailing list<br>&gt; &gt; &gt; <a href="mailto:rspec-users@rubyforge.org" target="_blank">rspec-users@rubyforge.org</a>
<br>&gt; &gt; &gt; 
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt; &gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; _______________________________________________
<br>&gt; &gt; rspec-users mailing list<br>&gt; &gt; <a href="mailto:rspec-users@rubyforge.org" target="_blank">rspec-users@rubyforge.org</a><br>&gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">
http://rubyforge.org/mailman/listinfo/rspec-users
</a><br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; rspec-users mailing list<br>&gt; <a href="mailto:rspec-users@rubyforge.org" target="_blank">rspec-users@rubyforge.org</a><br>
&gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt;<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org" target="_blank">rspec-users@rubyforge.org
</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>