Re: [rspec-users] Need help mocking this out

2007-12-16 Thread Pat Maddox
On Dec 16, 2007 1:43 PM, David Chelimsky <[EMAIL PROTECTED]> wrote: > I tend to take this one more step. I'm a bit of a demeter zealot, and > I'm also usually writing the examples from the code first. So I'd do > something like: > > it "should find the current users articles" do > article = mock_

Re: [rspec-users] Need help mocking this out

2007-12-16 Thread David Chelimsky
On Dec 16, 2007 4:01 PM, Daniel N <[EMAIL PROTECTED]> wrote: > > > > On Dec 17, 2007 8:43 AM, David Chelimsky <[EMAIL PROTECTED]> wrote: > > > > On Dec 16, 2007 11:03 AM, Jonathan Linowes <[EMAIL PROTECTED]> > wrote: > > > > > > btw, to answer the same question for member actions (such as show), yo

Re: [rspec-users] Need help mocking this out

2007-12-16 Thread Daniel N
On Dec 17, 2007 8:43 AM, David Chelimsky <[EMAIL PROTECTED]> wrote: > On Dec 16, 2007 11:03 AM, Jonathan Linowes <[EMAIL PROTECTED]> > wrote: > > > > btw, to answer the same question for member actions (such as show), you > can > > stub or assert the association proxy class > > > > @article = cur

Re: [rspec-users] Need help mocking this out

2007-12-16 Thread David Chelimsky
On Dec 16, 2007 11:03 AM, Jonathan Linowes <[EMAIL PROTECTED]> wrote: > > btw, to answer the same question for member actions (such as show), you can > stub or assert the association proxy class > > @article = current_user.articles.find(params[:id]) > > then, > > it "should find article scoped by

Re: [rspec-users] Need help mocking this out

2007-12-16 Thread Jonathan Linowes
btw, to answer the same question for member actions (such as show), you can stub or assert the association proxy class @article = current_user.articles.find(params[:id]) then, it "should find article scoped by current_user" do article = mock_model(Article) current_user

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Jarkko Laine
On 4.12.2007, at 8.40, Fischer, Daniel wrote: > 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. #rspec @freenode //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http:

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
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. Anyway, the previous problem was solved with the following http://pastie.textmate.org/private/m6qqfd7tzeanw2yar8rua The problem was caused by : @user = mock_model(User, :wri

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
Alright, thanks, I'm getting more progress in this. As soon as I figure this out I won't have too many problems.. hopefully. Anyone know what "undefined method `call' for "1":String" means? I'm trying to do this: http://pastie.textmate.org/private/17jjjmbave0ph2mkcgp6w On Dec 3, 2007 9:33 PM, D

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread David Chelimsky
On Dec 3, 2007 10:26 PM, Fischer, Daniel <[EMAIL PROTECTED]> wrote: > Hey cool, thanks for the help guys. One problem though, when I take this > approach I can't decouple the specs anymore. They all "User_xxx receive > unexpected message :articles". It seems silly to include all behaviors in > one

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
I also have another problem, when I am trying to do the similar strategy for XML based speccing it fails on saying nil.to_xml Arg.. And all it is, is the following => (with a before_filter on login required) but still, it's just current_user. def show @writing = current_user.writings.find(p

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
Hey cool, thanks for the help guys. One problem though, when I take this approach I can't decouple the specs anymore. They all "User_xxx receive unexpected message :articles". It seems silly to include all behaviors in one spec, or put that expectation in each test. Is there a way around this? Than

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Stefan Magnus Landrø
Well, if articles is already scoped, you just say: user.should_receive('articles').and_return(some_articles) To make sure your articles method is scoped, write a model test that hits the database, and verify that only the user's articles are returned. As Daniel Tenner says, you should try to kee

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Daniel Tenner
Hi Daniel, You're trying to do too much in the controller. It's not the controller's responsibility to ensure that the user is capable of returning its own article without including anyone else's - that's the user's (or the Article model's, perhaps) responsibility. Your controller should

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Daniel N
Assuming that there is a call like this in your controller @articles = current_user.articles One way to do this is to stub out the controller.current_user to return a mock object of the current_user Then put an expectation on the current user that it's articles method gets called. (return a mocke

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Jarkko Laine
On 3.12.2007, at 11.57, Fischer, Daniel wrote: > Let's say you're using the restful_authentication plugin. > > You have a model called articles. On the index action of the > articlescontroller you simply want to spec out that it'll scope the > results to the ownership of the current_user. > >

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
yuck, that seems kind of nasty, no? user.articles is already scoped... There has to be a different solution! On Dec 3, 2007 2:07 AM, Stefan Magnus Landrø <[EMAIL PROTECTED]> wrote: > Typically, I'd write a method in your user model that returns the user's > articles: > > class User do > > def

Re: [rspec-users] Need help mocking this out

2007-12-03 Thread Stefan Magnus Landrø
Typically, I'd write a method in your user model that returns the user's articles: class User do def find_articles_for_user Article.find(:all, :conditions => ['userid = ?', id) end end Then you'd use a mock in your controller spec, and make sure you test that your method is being called.

[rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
Let's say you're using the restful_authentication plugin. You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it'll scope the results to the ownership of the current_user. It should NOT include any articles other than the articles that u

[rspec-users] Need help mocking this out

2007-12-03 Thread Fischer, Daniel
Let's say you're using the restful_authentication plugin. You have a model called articles. On the index action of the articlescontroller you simply want to spec out that it'll scope the results to the ownership of the current_user. It should NOT include any articles other than the articles that u