Sorry for so many messages, I hope I don'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
<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> @user = mock_model(User, :writings => [] )</div><div><br class="webkit-block-placeholder"></div><div>I'm not sure if that is a bug or what, but that's what caused it.</div></span><div><br class="webkit-block-placeholder">
</div><div>It'd also say "no block given" if I put something there other than a "mock".</div><br><div class="gmail_quote">On Dec 3, 2007 10:33 PM, Fischer, Daniel <<a href="mailto:me@danielfischer.com">
me@danielfischer.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Alright, thanks, I'm getting more progress in this. As soon as I figure this out I won't have too many problems.. hopefully.
<div><br></div><div>Anyone know what "undefined method `call' for "1":String" means?
</div><div><br></div><div>I'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 <<a href="mailto:dchelimsky@gmail.com" target="_blank">dchelimsky@gmail.com</a>> 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 <<a href="mailto:me@danielfischer.com" target="_blank">me@danielfischer.com</a>> wrote:<br>> Hey cool, thanks for the help guys. One problem though, when I take this
<br>
> approach I can't decouple the specs anymore. They all "User_xxx receive<br>> unexpected message :articles". It seems silly to include all behaviors in<br>> 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> def create_stub_user<br> mock_model(User, :articles => [])<br> end<br>end<br><br>describe UserController, "..." do
<br> include UserControllerSpecHelper<br> before(:each) do<br> @user = create_stub_user<br> end<br>end<br><br>If there are other methods 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>><br>> Thanks for all the help,<br>> Daniel Fischer<br>> <a href="http://www.danielfischer.com" target="_blank">
http://www.danielfischer.com</a><br>><br>><br>><br>> On Dec 3, 2007 2:44 AM, Daniel N < <a href="mailto:has.sox@gmail.com" target="_blank">has.sox@gmail.com</a>> wrote:<br>> > Assuming that there is a call like this in your controller
<br>> ><br>> ><br>> > @articles = current_user.articles<br>> ><br>> ><br>> > One way to do this is to stub out the controller.current_user to return a<br>> mock object of the current_user
<br>> ><br>> ><br>> > Then put an expectation on the current user that it's articles method gets<br>> called. (return a mocked collection of articles)<br>> ><br>> ><br>> > Then check that @articles is set to the returned mocked collection of
<br>> articles from current_user.articles<br>> ><br>> ><br>> > phew...<br>> ><br>> ><br>> > Ok So one way you might write this could be (This is untested...)<br>> ><br>> >
<br>> > it "should scope the articles to the currrent_user" do<br>> ><br>> ><br>> > user = mock_model(User)<br>> > articles = [mock_model(Article)]<br>> ><br>> ><br>
> > controller.stub!(:current_user).and_return(user)<br>> ><br>> > user.should_receive (:articles).and_return(articles)<br>> ><br>> > get :index<br>> ><br>> > assigns[:articles].should == articles
<br>> ><br>> ><br>> > end<br>> ><br>> ><br>> > Like I said though, that's not tested itself. If that's not exactly<br>> right... it's along the right track of an option that can work.
<br>> ><br>> ><br>> > HTH<br>> > Daniel<br>> ><br>> ><br>> ><br>> > On Dec 3, 2007 9:07 PM, Stefan Magnus Landrø <<a href="mailto:stefan.landro@gmail.com" target="_blank">
stefan.landro@gmail.com
</a>><br>> wrote:<br>> ><br>> ><br>> ><br>> ><br>> > > Typically, I'd write a method in your user model that returns the user's<br>> articles:<br>> > ><br>> > > class User do
<br>> > ><br>> > > def find_articles_for_user<br>> > > Article.find(:all, :conditions => ['userid = ?', id)<br>> > > end<br>> > ><br>> > > end<br>> > >
<br>> > > Then you'd use a mock in your controller spec, and make sure you test<br>> that your method is being called.<br>> > ><br>> > > On the other hand, the user model should be tested directly against the
<br>> db.<br>> > ><br>> > > HTH,<br>> > ><br>> > > Stefan<br>> > ><br>> > ><br>> > > 2007/12/3, Fischer, Daniel <<a href="mailto:daniel@helpmebuyacar.org" target="_blank">
daniel@helpmebuyacar.org</a>>:<br>> > > ><br>> > > ><br>> > > ><br>> > > > Let's say you're using the restful_authentication plugin.<br>> > > ><br>> > > >
<br>> > > > You have a model called articles. On the index action of the<br>> articlescontroller you simply want to spec out that it'll scope the results<br>> to the ownership of the current_user.<br>
> > > ><br>> > > ><br>> > > > It should NOT include any articles other than the articles that user<br>> owns.<br>> > > ><br>> > > ><br>> > > > How would you properly spec this out?
<br>> > > ><br>> > > ><br>> > > > Thanks for the help!<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>> > > ><br>> > ><br>> > ><br>> > ><br>> > > --<br>> > > Bekk Open Source<br>> > > <a href="http://boss.bekk.no" target="_blank">http://boss.bekk.no
</a><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>> > ><br>> ><br>> ><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>> ><br>><br>><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>><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>