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] spec'ing shared controller methods

2007-12-03 Thread Jonathan Linowes
didnt mean to confuse, i'm asking about the code in the body of the email. The pastie was just for background reference. --J On Dec 4, 2007, at 12:41 AM, Jonathan Linowes wrote: > I want to isolate and spec methods that are shared by controllers, > and live in application.rb. > > Whereas I usua

[rspec-users] spec'ing shared controller methods

2007-12-03 Thread Jonathan Linowes
I want to isolate and spec methods that are shared by controllers, and live in application.rb. Whereas I usually also provide examples in individual controllers that use these methods, not necessarily all the edge cases and I'd like to isolate the examples. This is the approach I'm taking (

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] spec for model_id should eql

2007-12-03 Thread Jarkko Laine
On 3.12.2007, at 21.23, David Chelimsky wrote: > On Dec 3, 2007 1:18 PM, Jarkko Laine <[EMAIL PROTECTED]> wrote: >> >> On 3.12.2007, at 21.05, Nathan Sutton wrote: >> >>> Department.stub!(:find_by_code).with("75").and_return("3") >> >> You can't use with() with stub! (only with should_receive), s

Re: [rspec-users] spec for model_id should eql

2007-12-03 Thread Nathan Sutton
It's worked since I started using rspec, but I started relatively recently, and only on edge. Nathan Sutton [EMAIL PROTECTED] rspec edge revision 3014 rspec_on_rails edge revision 3014 rails edge revision 8238 On Dec 3, 2007, at 1:23 PM, David Chelimsky wrote: > On Dec 3, 2007 1:18 PM, Jark

Re: [rspec-users] spec for model_id should eql

2007-12-03 Thread David Chelimsky
On Dec 3, 2007 1:18 PM, Jarkko Laine <[EMAIL PROTECTED]> wrote: > > On 3.12.2007, at 21.05, Nathan Sutton wrote: > > > Department.stub!(:find_by_code).with("75").and_return("3") > > You can't use with() with stub! (only with should_receive), so just > leave it away: > > Department.stub!(:find_by_co

Re: [rspec-users] spec for model_id should eql

2007-12-03 Thread Jarkko Laine
On 3.12.2007, at 21.05, Nathan Sutton wrote: > Department.stub!(:find_by_code).with("75").and_return("3") You can't use with() with stub! (only with should_receive), so just leave it away: Department.stub!(:find_by_code).and_return("3") //jarkko -- Jarkko Laine http://jlaine.net http://doth

Re: [rspec-users] spec for model_id should eql

2007-12-03 Thread Nathan Sutton
Department.stub!(:find_by_code).with("75").and_return("3") Nathan Sutton [EMAIL PROTECTED] rspec edge revision 3014 rspec_on_rails edge revision 3014 rails edge revision 8238 On Dec 3, 2007, at 12:33 PM, Sahyoun wrote: > Hello, > > I'm confused why the spec described below is failing. Other

[rspec-users] spec for model_id should eql

2007-12-03 Thread Sahyoun
Hello, I'm confused why the spec described below is failing. Other simple comparison specs are passing fine for the same model. The code is working accordingly when I test it through the console, I'm just having difficulty getting this spec to work. Any pointers would be appreciated. Failure mess

Re: [rspec-users] Stylistic preferences

2007-12-03 Thread Stefan Magnus Landrø
Well, I kinda like the word given, however I feel it's competing with the Context in describe Class, "Context" do Maybe before should be replaced with some givens and expectations, like so: describe Class, "Context" do given do end always_expect do end it "should ..." do end e

Re: [rspec-users] Stylistic preferences

2007-12-03 Thread Daniel Tenner
The code works fine. I was asking about the "given" thing. Daniel On 3 Dec 2007, at 13:32 3 Dec 2007, Bryan Liles wrote: > > On Nov 29, 2007, at 5:54 AM, Daniel Tenner wrote: > >> What are people's opinions on which of these two styles is better to >> use? >> >> >> it "should be possible to di

Re: [rspec-users] Stylistic preferences

2007-12-03 Thread Bryan Liles
On Nov 29, 2007, at 5:54 AM, Daniel Tenner wrote: > What are people's opinions on which of these two styles is better to > use? > > > it "should be possible to disable the number" do > given(valid_sms_user) do |user| > user.save > user.disable_number > user.should be_disab

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