Fischer, Daniel
2007-May-31 00:03 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
My problem has been listed here: http://railsforum.com/viewtopic.php?pid=25439#p25439 Don''t think it would be required to completely re-type it here :) Thanks! -- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community
Chris Anderson
2007-May-31 00:08 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Daniel, Usually the route specs have nothing to do with the controller''s code. Your controller may not be issuing the proper find, but your route setup has no effect on the do_get method in your second spec. More helpful would be to see your controller code. Chris On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote:> My problem has been listed here: > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > Don''t think it would be required to completely re-type it here :) > > Thanks! > > -- > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Chris Anderson http://jchris.mfdz.com
Fischer, Daniel
2007-May-31 00:15 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Chris, class PostsController < ApplicationController before_filter(:get_user) before_filter :login_required def index @posts = @user.posts.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @posts.to_xml } end end def show respond_to do |format| format.html # show.rhtml format.xml { render :xml => @post.to_xml } end end def new @post = Post.new end def edit end def create @post = Post.new(params[:post]) @post.user_id = @user.id respond_to do |format| if @post.save flash[:notice] = ''Post was successfully created.'' format.html { redirect_to post_url(@user, @post) } format.xml { head :created, :location => post_url(@user, @post) } else format.html { render :action => "new" } format.xml { render :xml => @post.errors.to_xml } end end end def update respond_to do |format| if @post.update_attributes(params[:post]) flash[:notice] = ''Post was successfully updated.'' format.html { redirect_to post_url(@user, @post) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @post.errors.to_xml } end end end def destroy @post.destroy respond_to do |format| format.html { redirect_to posts_url } format.xml { head :ok } end end private def get_user @user = User.find(params[:user_id]) @post = @user.posts.find(params[:id]) if params[:id] end end Hope that clears it up :) On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote:> Daniel, > Usually the route specs have nothing to do with the controller''s code. > Your controller may not be issuing the proper find, but your route > setup has no effect on the do_get method in your second spec. > > More helpful would be to see your controller code. > > Chris > > On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > My problem has been listed here: > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > Don''t think it would be required to completely re-type it here :) > > > > Thanks! > > > > -- > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > Chris Anderson > http://jchris.mfdz.com >-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community
Jonathan Linowes
2007-May-31 00:50 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Don''t you need to stub the User model :find too? (needed in your private get_user call) private def get_user @user = User.find(params[:user_id]) @post = @user.posts.find(params[:id]) if params[:id] end On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote:> My problem has been listed here: > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > Don''t think it would be required to completely re-type it here :) > > Thanks! > > -- > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Fischer, Daniel
2007-May-31 01:07 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Jonathan, Yeah something like that. I have no idea how to put it together properly. I''m beyond confused at this point, that''s why I could really use some help. I figured out my "response" error, but now Im trying to "find all posts" Right now I got something like: User.should_receive(:posts).with(:all).and_return([@posts]) But I know it should be User.posts.find(:all) - i''m not sure how to make this a proper behavior check. How do I setup my mocks to correspond with this? Thanks. On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:> Don''t you need to stub the User model :find too? (needed in your > private get_user call) > > private > def get_user > @user = User.find(params[:user_id]) > @post = @user.posts.find(params[:id]) if params[:id] > end > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > My problem has been listed here: > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > Don''t think it would be required to completely re-type it here :) > > > > Thanks! > > > > -- > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community
Chris Anderson
2007-May-31 05:01 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
I usually do something like this in my before(:each) section: User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc mock(''posts collection''))) @pc.stub(:find).and_return([@p = mock_model(Post)]) with the corresponding should_receives in my various examples... the trick is to mock the user''s posts collection as its own object. On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote:> Jonathan, > > Yeah something like that. I have no idea how to put it together > properly. I''m beyond confused at this point, that''s why I could really > use some help. > > I figured out my "response" error, but now Im trying to "find all posts" > > Right now I got something like: > > User.should_receive(:posts).with(:all).and_return([@posts]) > > But I know it should be User.posts.find(:all) - i''m not sure how to > make this a proper behavior check. > > How do I setup my mocks to correspond with this? > > Thanks. > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > Don''t you need to stub the User model :find too? (needed in your > > private get_user call) > > > > private > > def get_user > > @user = User.find(params[:user_id]) > > @post = @user.posts.find(params[:id]) if params[:id] > > end > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > My problem has been listed here: > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > Don''t think it would be required to completely re-type it here :) > > > > > > Thanks! > > > > > > -- > > > -Daniel Fischer > > > > > > http://danielfischer.com - Geek Blog > > > http://abigfisch.com - Portfolio > > > http://writersbeat.com - Writing Community > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Chris Anderson http://jchris.mfdz.com
Fischer, Daniel
2007-May-31 06:17 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Okay that failed. I could really use a full blown example with this, just mocking isn''t going to "give me insight" anymore I don''t think. If anyone can post a basic crud behavior check, w/ nested routes - I''d really appreciate it. Thanks, Daniel On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote:> > I usually do something like this in my before(:each) section: > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > mock(''posts collection''))) > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > with the corresponding should_receives in my various examples... the > trick is to mock the user''s posts collection as its own object. > > On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > Jonathan, > > > > Yeah something like that. I have no idea how to put it together > > properly. I''m beyond confused at this point, that''s why I could really > > use some help. > > > > I figured out my "response" error, but now Im trying to "find all posts" > > > > Right now I got something like: > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > But I know it should be User.posts.find(:all) - i''m not sure how to > > make this a proper behavior check. > > > > How do I setup my mocks to correspond with this? > > > > Thanks. > > > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > > Don''t you need to stub the User model :find too? (needed in your > > > private get_user call) > > > > > > private > > > def get_user > > > @user = User.find(params[:user_id]) > > > @post = @user.posts.find(params[:id]) if params[:id] > > > end > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > My problem has been listed here: > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > Don''t think it would be required to completely re-type it here :) > > > > > > > > Thanks! > > > > > > > > -- > > > > -Daniel Fischer > > > > > > > > http://danielfischer.com - Geek Blog > > > > http://abigfisch.com - Portfolio > > > > http://writersbeat.com - Writing Community > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > -- > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > -- > Chris Anderson > http://jchris.mfdz.com >-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070530/c00a411b/attachment-0001.html
Fischer, Daniel
2007-May-31 08:31 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Oh my... I don''t know what happened... but my entire posts_controller_spec completely exploded and i''m having 31 failures, before I was having like 8. I''m not sure what is going on, I could REALLY use the help. http://pastie.caboo.se/66440 for a list of everything that is going on, and the code. I really appreciate the help guys, once I get over the mountain I''m sure I''ll understand it :) On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote:> Okay that failed. > > I could really use a full blown example with this, just mocking isn''t going > to "give me insight" anymore I don''t think. If anyone can post a basic crud > behavior check, w/ nested routes - I''d really appreciate it. > > Thanks, > Daniel > > On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote: > > I usually do something like this in my before(:each) section: > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > mock(''posts collection''))) > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > with the corresponding should_receives in my various examples... the > > trick is to mock the user''s posts collection as its own object. > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > Jonathan, > > > > > > Yeah something like that. I have no idea how to put it together > > > properly. I''m beyond confused at this point, that''s why I could really > > > use some help. > > > > > > I figured out my "response" error, but now Im trying to "find all posts" > > > > > > Right now I got something like: > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > But I know it should be User.posts.find(:all) - i''m not sure how to > > > make this a proper behavior check. > > > > > > How do I setup my mocks to correspond with this? > > > > > > Thanks. > > > > > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > > > Don''t you need to stub the User model :find too? (needed in your > > > > private get_user call) > > > > > > > > private > > > > def get_user > > > > @user = User.find(params[:user_id]) > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > end > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > My problem has been listed here: > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > Don''t think it would be required to completely re-type it here :) > > > > > > > > > > Thanks! > > > > > > > > > > -- > > > > > -Daniel Fischer > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > http://abigfisch.com - Portfolio > > > > > http://writersbeat.com - Writing Community > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > -- > > > -Daniel Fischer > > > > > > http://danielfischer.com - Geek Blog > > > http://abigfisch.com - Portfolio > > > http://writersbeat.com - Writing Community > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > -- > > Chris Anderson > > http://jchris.mfdz.com > > > > > > -- > > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community
David Chelimsky
2007-May-31 10:42 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote:> Oh my... > > I don''t know what happened... but my entire posts_controller_spec > completely exploded and i''m having 31 failures, before I was having > like 8. I''m not sure what is going on, I could REALLY use the help. > > http://pastie.caboo.se/66440 for a list of everything that is going > on, and the code.Try running the one file with the -b switch to get a full backtrace. script/spec spec/controllers/posts_controller_spec.rb -b> > I really appreciate the help guys, once I get over the mountain I''m > sure I''ll understand it :) > > On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > Okay that failed. > > > > I could really use a full blown example with this, just mocking isn''t going > > to "give me insight" anymore I don''t think. If anyone can post a basic crud > > behavior check, w/ nested routes - I''d really appreciate it. > > > > Thanks, > > Daniel > > > > On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote: > > > I usually do something like this in my before(:each) section: > > > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > > mock(''posts collection''))) > > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > > > with the corresponding should_receives in my various examples... the > > > trick is to mock the user''s posts collection as its own object. > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > Jonathan, > > > > > > > > Yeah something like that. I have no idea how to put it together > > > > properly. I''m beyond confused at this point, that''s why I could really > > > > use some help. > > > > > > > > I figured out my "response" error, but now Im trying to "find all posts" > > > > > > > > Right now I got something like: > > > > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > > > But I know it should be User.posts.find(:all) - i''m not sure how to > > > > make this a proper behavior check. > > > > > > > > How do I setup my mocks to correspond with this? > > > > > > > > Thanks. > > > > > > > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > > > > Don''t you need to stub the User model :find too? (needed in your > > > > > private get_user call) > > > > > > > > > > private > > > > > def get_user > > > > > @user = User.find(params[:user_id]) > > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > > end > > > > > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > > > My problem has been listed here: > > > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > > > Don''t think it would be required to completely re-type it here :) > > > > > > > > > > > > Thanks! > > > > > > > > > > > > -- > > > > > > -Daniel Fischer > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > http://abigfisch.com - Portfolio > > > > > > http://writersbeat.com - Writing Community > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > -- > > > > -Daniel Fischer > > > > > > > > http://danielfischer.com - Geek Blog > > > > http://abigfisch.com - Portfolio > > > > http://writersbeat.com - Writing Community > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > -- > > > Chris Anderson > > > http://jchris.mfdz.com > > > > > > > > > > > -- > > > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community > > > -- > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Fischer, Daniel
2007-May-31 11:17 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
1) ''PostsController handling GET /users/1/posts should be successful'' FAILED expected success? to return true, got false /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations.rb:52:in `fail_with'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/handler.rb:16:in `handle_matcher'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/extensions/object.rb:32:in `should'' ./spec/controllers/posts_controller_spec.rb:46: /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:73:in `instance_eval'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:73:in `run_example'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:23:in `run'' /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:21:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:72:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:69:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:69:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:45:in `run_behaviours'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:44:in `each'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:44:in `run_behaviours'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:27:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/command_line.rb:17:in `run'' /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/bin/spec:3: /usr/local/bin/spec:18:in `load'' /usr/local/bin/spec:18: Doesn''t really tell me anything, how about you? On 5/31/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > Oh my... > > > > I don''t know what happened... but my entire posts_controller_spec > > completely exploded and i''m having 31 failures, before I was having > > like 8. I''m not sure what is going on, I could REALLY use the help. > > > > http://pastie.caboo.se/66440 for a list of everything that is going > > on, and the code. > > Try running the one file with the -b switch to get a full backtrace. > > script/spec spec/controllers/posts_controller_spec.rb -b > > > > > I really appreciate the help guys, once I get over the mountain I''m > > sure I''ll understand it :) > > > > On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > Okay that failed. > > > > > > I could really use a full blown example with this, just mocking isn''t > going > > > to "give me insight" anymore I don''t think. If anyone can post a basic > crud > > > behavior check, w/ nested routes - I''d really appreciate it. > > > > > > Thanks, > > > Daniel > > > > > > On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote: > > > > I usually do something like this in my before(:each) section: > > > > > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > > > mock(''posts collection''))) > > > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > > > > > with the corresponding should_receives in my various examples... the > > > > trick is to mock the user''s posts collection as its own object. > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > Jonathan, > > > > > > > > > > Yeah something like that. I have no idea how to put it together > > > > > properly. I''m beyond confused at this point, that''s why I could > really > > > > > use some help. > > > > > > > > > > I figured out my "response" error, but now Im trying to "find all > posts" > > > > > > > > > > Right now I got something like: > > > > > > > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > > > > > But I know it should be User.posts.find(:all) - i''m not sure how > to > > > > > make this a proper behavior check. > > > > > > > > > > How do I setup my mocks to correspond with this? > > > > > > > > > > Thanks. > > > > > > > > > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > > > > > Don''t you need to stub the User model :find too? (needed in your > > > > > > private get_user call) > > > > > > > > > > > > private > > > > > > def get_user > > > > > > @user = User.find(params[:user_id]) > > > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > > > > > My problem has been listed here: > > > > > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > > > > > Don''t think it would be required to completely re-type it here > :) > > > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > -- > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > http://abigfisch.com - Portfolio > > > > > > > http://writersbeat.com - Writing Community > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > -Daniel Fischer > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > http://abigfisch.com - Portfolio > > > > > http://writersbeat.com - Writing Community > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > -- > > > > Chris Anderson > > > > http://jchris.mfdz.com > > > > > > > > > > > > > > > > -- > > > > > > -Daniel Fischer > > > > > > http://danielfischer.com - Geek Blog > > > http://abigfisch.com - Portfolio > > > http://writersbeat.com - Writing Community > > > > > > -- > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > >-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070531/139670e8/attachment.html
David Chelimsky
2007-May-31 11:28 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote:> 1) > ''PostsController handling GET /users/1/posts should be successful'' FAILED > expected success? to return true, got false > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations.rb:52:in > `fail_with'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/handler.rb:16:in > `handle_matcher'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/extensions/object.rb:32:in > `should'' > ./spec/controllers/posts_controller_spec.rb:46: > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:73:in > `instance_eval'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:73:in > `run_example'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:23:in > `run'' > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:21:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:72:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:69:in > `each'' > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/dsl/behaviour.rb:69:in `run'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:45:in > `run_behaviours'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:44:in > `each'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:44:in > `run_behaviours'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:27:in > `run'' > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/runner/command_line.rb:17:in `run'' > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/bin/spec:3: > /usr/local/bin/spec:18:in `load'' > /usr/local/bin/spec:18: > > Doesn''t really tell me anything, how about you?Nope. Thanks for playing ;) One thing - controller examples used to implicitly re-raise controller errors. We removed this in response to a bug report, which had the insidious side-effect of hiding errors without you knowing. If you upgrade to 1.0.4, you''ll see a call in spec_helper.rb to raise_controller_errors. This is a new method that lets you do so explicitly, and is included in spec_helper.rb by default. I''m thinking this might help expose the problem.> > > On 5/31/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > Oh my... > > > > > > I don''t know what happened... but my entire posts_controller_spec > > > completely exploded and i''m having 31 failures, before I was having > > > like 8. I''m not sure what is going on, I could REALLY use the help. > > > > > > http://pastie.caboo.se/66440 for a list of everything that is going > > > on, and the code. > > > > Try running the one file with the -b switch to get a full backtrace. > > > > script/spec spec/controllers/posts_controller_spec.rb -b > > > > > > > > I really appreciate the help guys, once I get over the mountain I''m > > > sure I''ll understand it :) > > > > > > On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > > Okay that failed. > > > > > > > > I could really use a full blown example with this, just mocking isn''t > going > > > > to "give me insight" anymore I don''t think. If anyone can post a basic > crud > > > > behavior check, w/ nested routes - I''d really appreciate it. > > > > > > > > Thanks, > > > > Daniel > > > > > > > > On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote: > > > > > I usually do something like this in my before(:each) section: > > > > > > > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > > > > mock(''posts collection''))) > > > > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > > > > > > > with the corresponding should_receives in my various examples... the > > > > > trick is to mock the user''s posts collection as its own object. > > > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > > Jonathan, > > > > > > > > > > > > Yeah something like that. I have no idea how to put it together > > > > > > properly. I''m beyond confused at this point, that''s why I could > really > > > > > > use some help. > > > > > > > > > > > > I figured out my "response" error, but now Im trying to "find all > posts" > > > > > > > > > > > > Right now I got something like: > > > > > > > > > > > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > > > > > > > But I know it should be User.posts.find(:all) - i''m not sure how > to > > > > > > make this a proper behavior check. > > > > > > > > > > > > How do I setup my mocks to correspond with this? > > > > > > > > > > > > Thanks. > > > > > > > > > > > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > > > > > > Don''t you need to stub the User model :find too? (needed in your > > > > > > > private get_user call) > > > > > > > > > > > > > > private > > > > > > > def get_user > > > > > > > @user = User.find(params[:user_id]) > > > > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > > > > > > > My problem has been listed here: > > > > > > > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > > > > > > > Don''t think it would be required to completely re-type it here > :) > > > > > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > > > -- > > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > > http://abigfisch.com - Portfolio > > > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > -Daniel Fischer > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > http://abigfisch.com - Portfolio > > > > > > http://writersbeat.com - Writing Community > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > Chris Anderson > > > > > http://jchris.mfdz.com > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > -Daniel Fischer > > > > > > > > http://danielfischer.com - Geek Blog > > > > http://abigfisch.com - Portfolio > > > > http://writersbeat.com - Writing Community > > > > > > > > > -- > > > -Daniel Fischer > > > > > > http://danielfischer.com - Geek Blog > > > http://abigfisch.com - Portfolio > > > http://writersbeat.com - Writing Community > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > -- > > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community
Fischer, Daniel
2007-May-31 12:03 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
David, Awesome - well at least it''s telling me something isn''t working "that well" anymore. Instead of the previous "expected success? to return true, got false" It''s now "Couldn''t find User with ID=1" But I swore that same code worked before, it looks proper in my pastie doesn''t it? *scratches head* - it certainly works when it''s "live". On 5/31/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > 1) > > ''PostsController handling GET /users/1/posts should be successful'' > FAILED > > expected success? to return true, got false > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/expectations.rb:52:in > > `fail_with'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/expectations/handler.rb:16:in > > `handle_matcher'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/expectations/extensions/object.rb:32:in > > `should'' > > ./spec/controllers/posts_controller_spec.rb:46: > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/dsl/example.rb:73:in > > `instance_eval'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/dsl/example.rb:73:in > > `run_example'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/dsl/example.rb:23:in > > `run'' > > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/dsl/example.rb:21:in > > `run'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/dsl/behaviour.rb:72:in > > `run'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/dsl/behaviour.rb:69:in > > `each'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > > 1.0.2/lib/spec/dsl/behaviour.rb:69:in `run'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/runner/behaviour_runner.rb:45:in > > `run_behaviours'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/runner/behaviour_runner.rb:44:in > > `each'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/runner/behaviour_runner.rb:44:in > > `run_behaviours'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2 > /lib/spec/runner/behaviour_runner.rb:27:in > > `run'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > > 1.0.2/lib/spec/runner/command_line.rb:17:in `run'' > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/bin/spec:3: > > /usr/local/bin/spec:18:in `load'' > > /usr/local/bin/spec:18: > > > > Doesn''t really tell me anything, how about you? > > Nope. Thanks for playing ;) > > One thing - controller examples used to implicitly re-raise controller > errors. We removed this in response to a bug report, which had the > insidious side-effect of hiding errors without you knowing. If you > upgrade to 1.0.4, you''ll see a call in spec_helper.rb to > raise_controller_errors. This is a new method that lets you do so > explicitly, and is included in spec_helper.rb by default. > > I''m thinking this might help expose the problem. > > > > > > > On 5/31/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > > Oh my... > > > > > > > > I don''t know what happened... but my entire posts_controller_spec > > > > completely exploded and i''m having 31 failures, before I was having > > > > like 8. I''m not sure what is going on, I could REALLY use the help. > > > > > > > > http://pastie.caboo.se/66440 for a list of everything that is going > > > > on, and the code. > > > > > > Try running the one file with the -b switch to get a full backtrace. > > > > > > script/spec spec/controllers/posts_controller_spec.rb -b > > > > > > > > > > > I really appreciate the help guys, once I get over the mountain I''m > > > > sure I''ll understand it :) > > > > > > > > On 5/30/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > > > Okay that failed. > > > > > > > > > > I could really use a full blown example with this, just mocking > isn''t > > going > > > > > to "give me insight" anymore I don''t think. If anyone can post a > basic > > crud > > > > > behavior check, w/ nested routes - I''d really appreciate it. > > > > > > > > > > Thanks, > > > > > Daniel > > > > > > > > > > On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote: > > > > > > I usually do something like this in my before(:each) section: > > > > > > > > > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > > > > > > mock(''posts collection''))) > > > > > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > > > > > > > > > with the corresponding should_receives in my various examples... > the > > > > > > trick is to mock the user''s posts collection as its own object. > > > > > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > > > Jonathan, > > > > > > > > > > > > > > Yeah something like that. I have no idea how to put it > together > > > > > > > properly. I''m beyond confused at this point, that''s why I > could > > really > > > > > > > use some help. > > > > > > > > > > > > > > I figured out my "response" error, but now Im trying to "find > all > > posts" > > > > > > > > > > > > > > Right now I got something like: > > > > > > > > > > > > > > > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > > > > > > > > > But I know it should be User.posts.find(:all) - i''m not sure > how > > to > > > > > > > make this a proper behavior check. > > > > > > > > > > > > > > How do I setup my mocks to correspond with this? > > > > > > > > > > > > > > Thanks. > > > > > > > > > > > > > > On 5/30/07, Jonathan Linowes <jonathan at parkerhill.com> wrote: > > > > > > > > Don''t you need to stub the User model :find too? (needed in > your > > > > > > > > private get_user call) > > > > > > > > > > > > > > > > private > > > > > > > > def get_user > > > > > > > > @user = User.find(params[:user_id]) > > > > > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > > > > > > > > > My problem has been listed here: > > > > > > > > > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > > > > > > > > > Don''t think it would be required to completely re-type it > here > > :) > > > > > > > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > > > > > -- > > > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > > > http://abigfisch.com - Portfolio > > > > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > http://abigfisch.com - Portfolio > > > > > > > http://writersbeat.com - Writing Community > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Chris Anderson > > > > > > http://jchris.mfdz.com > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > -Daniel Fischer > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > http://abigfisch.com - Portfolio > > > > > http://writersbeat.com - Writing Community > > > > > > > > > > > > -- > > > > -Daniel Fischer > > > > > > > > http://danielfischer.com - Geek Blog > > > > http://abigfisch.com - Portfolio > > > > http://writersbeat.com - Writing Community > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > -- > > > > -Daniel Fischer > > > > http://danielfischer.com - Geek Blog > > http://abigfisch.com - Portfolio > > http://writersbeat.com - Writing Community >-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070531/f8b813b4/attachment.html
Fischer, Daniel
2007-Jun-01 04:09 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Alright so I removed the ''nested'' resources, but I still have another problem. Most of my failures are gone, but I still have three left: 1) Spec::Mocks::MockExpectationError in ''PostsController handling GET /posts/1;edit should find the posts requested'' Post expected :find with (any args) once, but received it twice ./spec/controllers/posts_controller_spec.rb:217: 2) Spec::Mocks::MockExpectationError in ''PostsController handling POST /posts should create a new posts'' Mock ''Post_1027'' received unexpected message :user_id= with (202018) /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/posts_controller.rb:36:in `create'' /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in `process_without_test'' ./spec/controllers/posts_controller_spec.rb:250:in `do_post'' ./spec/controllers/posts_controller_spec.rb:256: 3) Spec::Mocks::MockExpectationError in ''PostsController handling POST /posts should redirect to the new posts'' Mock ''Post_1028'' received unexpected message :user_id= with (202018) /Users/sparta/Projects/work/idastudios/podff_machine/config/../app/controllers/posts_controller.rb:36:in `create'' /Users/sparta/Projects/work/idastudios/podff_machine/config/../vendor/plugins/haml/lib/sass/plugin.rb:116:in `process_without_test'' ./spec/controllers/posts_controller_spec.rb:250:in `do_post'' ./spec/controllers/posts_controller_spec.rb:260: Finished in 0.697209 seconds 38 examples, 3 failures I don''t understand the first one, but I do have an idea on the second/third one. I am setting the @post.user_id to the current user in the controller, I''m trying to mock that behavior but whatever I try doesn''t work. What would be the proper way? Right now I am doing this: it "should create a new posts" do Post.should_receive(:user_id).and_return(1) Post.should_receive(:new).with({''name'' => ''Post''}).and_return(@post) do_post end still fails with that message though :( On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote:> David, > > Awesome - well at least it''s telling me something isn''t working "that well" > anymore. > > Instead of the previous "expected success? to return true, got false" > > It''s now "Couldn''t find User with ID=1" > > But I swore that same code worked before, it looks proper in my pastie > doesn''t it? > > *scratches head* - it certainly works when it''s "live". > > On 5/31/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > 1) > > > ''PostsController handling GET /users/1/posts should be successful'' > FAILED > > > expected success? to return true, got false > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations.rb:52:in > > > `fail_with'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/handler.rb:16:in > > > `handle_matcher'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/expectations/extensions/object.rb:32:in > > > `should'' > > > ./spec/controllers/posts_controller_spec.rb:46: > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/dsl/example.rb:73:in > > > `instance_eval'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:73:in > > > `run_example'' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/dsl/example.rb:23:in > > > `run'' > > > /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/example.rb:21:in > > > `run'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:72:in > > > `run'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/dsl/behaviour.rb:69:in > > > `each'' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > > > 1.0.2/lib/spec/dsl/behaviour.rb:69:in `run'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:45:in > > > `run_behaviours'' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/runner/behaviour_runner.rb:44:in > > > `each'' > > > > /usr/local/lib/ruby/gems/1.8/gems/rspec-1.0.2/lib/spec/runner/behaviour_runner.rb:44:in > > > `run_behaviours'' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/lib/spec/runner/behaviour_runner.rb:27:in > > > `run'' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > > > 1.0.2/lib/spec/runner/command_line.rb:17:in `run'' > > > /usr/local/lib/ruby/gems/1.8/gems/rspec- > 1.0.2/bin/spec:3: > > > /usr/local/bin/spec:18:in `load'' > > > /usr/local/bin/spec:18: > > > > > > Doesn''t really tell me anything, how about you? > > > > Nope. Thanks for playing ;) > > > > One thing - controller examples used to implicitly re-raise controller > > errors. We removed this in response to a bug report, which had the > > insidious side-effect of hiding errors without you knowing. If you > > upgrade to 1.0.4, you''ll see a call in spec_helper.rb to > > raise_controller_errors. This is a new method that lets you do so > > explicitly, and is included in spec_helper.rb by default. > > > > I''m thinking this might help expose the problem. > > > > > > > > > > > On 5/31/07, David Chelimsky <dchelimsky at gmail.com > wrote: > > > > On 5/31/07, Fischer, Daniel <daniel at danielfischer.com> wrote: > > > > > Oh my... > > > > > > > > > > I don''t know what happened... but my entire posts_controller_spec > > > > > completely exploded and i''m having 31 failures, before I was having > > > > > like 8. I''m not sure what is going on, I could REALLY use the help. > > > > > > > > > > http://pastie.caboo.se/66440 for a list of everything that is going > > > > > on, and the code. > > > > > > > > Try running the one file with the -b switch to get a full backtrace. > > > > > > > > script/spec spec/controllers/posts_controller_spec.rb > -b > > > > > > > > > > > > > > I really appreciate the help guys, once I get over the mountain I''m > > > > > sure I''ll understand it :) > > > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > > Okay that failed. > > > > > > > > > > > > I could really use a full blown example with this, just mocking > isn''t > > > going > > > > > > to "give me insight" anymore I don''t think. If anyone can post a > basic > > > crud > > > > > > behavior check, w/ nested routes - I''d really appreciate it. > > > > > > > > > > > > Thanks, > > > > > > Daniel > > > > > > > > > > > > On 5/30/07, Chris Anderson <jchris at mfdz.com> wrote: > > > > > > > I usually do something like this in my before(:each) section: > > > > > > > > > > > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > > > > > > > mock(''posts collection''))) > > > > > > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > > > > > > > > > > > with the corresponding should_receives in my various examples... > the > > > > > > > trick is to mock the user''s posts collection as its own object. > > > > > > > > > > > > > > On 5/30/07, Fischer, Daniel < daniel at danielfischer.com> wrote: > > > > > > > > Jonathan, > > > > > > > > > > > > > > > > Yeah something like that. I have no idea how to put it > together > > > > > > > > properly. I''m beyond confused at this point, that''s why I > could > > > really > > > > > > > > use some help. > > > > > > > > > > > > > > > > I figured out my "response" error, but now Im trying to "find > all > > > posts" > > > > > > > > > > > > > > > > Right now I got something like: > > > > > > > > > > > > > > > > > > > > > > > > > > User.should_receive(:posts).with(:all).and_return([@posts]) > > > > > > > > > > > > > > > > But I know it should be User.posts.find(:all) - i''m not sure > how > > > to > > > > > > > > make this a proper behavior check. > > > > > > > > > > > > > > > > How do I setup my mocks to correspond with this? > > > > > > > > > > > > > > > > Thanks. > > > > > > > > > > > > > > > > On 5/30/07, Jonathan Linowes < jonathan at parkerhill.com> wrote: > > > > > > > > > Don''t you need to stub the User model :find too? (needed in > your > > > > > > > > > private get_user call) > > > > > > > > > > > > > > > > > > private > > > > > > > > > def get_user > > > > > > > > > @user = User.find(params[:user_id]) > > > > > > > > > @post = @user.posts.find(params[:id]) if params[:id] > > > > > > > > > end > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On May 30, 2007, at 8:03 PM, Fischer, Daniel wrote: > > > > > > > > > > > > > > > > > > > My problem has been listed here: > > > > > > > > > > > > > > > > > http://railsforum.com/viewtopic.php?pid=25439#p25439 > > > > > > > > > > > > > > > > > > > > Don''t think it would be required to completely re-type it > here > > > :) > > > > > > > > > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > > > > http://abigfisch.com - Portfolio > > > > > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > > rspec-users mailing list > > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > > > rspec-users mailing list > > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > -Daniel Fischer > > > > > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > > > http://abigfisch.com - Portfolio > > > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > _______________________________________________ > > > > > > > > rspec-users mailing list > > > > > > > > rspec-users at rubyforge.org > > > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > Chris Anderson > > > > > > > http://jchris.mfdz.com > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > -Daniel Fischer > > > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > > http://abigfisch.com - Portfolio > > > > > > http://writersbeat.com - Writing Community > > > > > > > > > > > > > > > -- > > > > > -Daniel Fischer > > > > > > > > > > http://danielfischer.com - Geek Blog > > > > > http://abigfisch.com - Portfolio > > > > > http://writersbeat.com - Writing Community > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > > > > > > > > > -- > > > > > > -Daniel Fischer > > > > > > http://danielfischer.com - Geek Blog > > > http://abigfisch.com - Portfolio > > > http://writersbeat.com - Writing Community > > > > > > -- > > -Daniel Fischer > > http://danielfischer.com - Geek Blog > http://abigfisch.com - Portfolio > http://writersbeat.com - Writing Community-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community
Jonathan Linowes
2007-Jun-01 18:31 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
I haven''t thought it through (no pun intended) but maybe this could be simplified and generalized , like add a ".through" to the stub and/ or should_receive ?? On May 31, 2007, at 1:01 AM, Chris Anderson wrote:> I usually do something like this in my before(:each) section: > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > mock(''posts collection''))) > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > with the corresponding should_receives in my various examples... the > trick is to mock the user''s posts collection as its own object. >
Fischer, Daniel
2007-Jun-02 08:31 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Jonathon, Not sure - I don''t really know what to do at this point, but I have a new problem again lol. Anyway, I can''t seem to create new mailing messages? I guess I ask to many... Well, forgive me - but I''ll just attach it here since I can''t make a new one. Hey, Sorry for so many questions - I''m really bad at this right now. I''m trying to cover the following code w/ rspec def index if params[:user_id] @user = User.find(params[:user_id]) @messages = @user.messages end end So basically what I''m doing is listing all the messages for a user, provided there is an id parameter. describe MessagesController, " handling GET /messages for a user" do before do @message = mock_model(Message) @message.stub!(:user_id).and_return(1) @user = mock_model(User) @user.stub!(:id).and_return(1) User.stub!(:messages).and_return([@message]) User.stub!(:find).and_return([@user]) end def do_get get :index, :user_id => 1 end it "should be successful" do do_get response.should be_success end it "should render index template" do do_get response.should render_template(''index'') end it "should find all messages" do User.should_receive(:messages).and_return([@message]) do_get end it "should assign the found messages for the view" do do_get assigns[:messages].should == [@message] end end I''m trying to use the basic scaffold spec, but I''m absolutely clueless on what the proper way to handle this is, I''m not even sure the proper way I should mock the messages method, so it''ll return a "stub?" of a collection, or whatever the proper term is. I''m sorry you have to deal with a newb, but if you could really help me out I''d appreciate it a ton, thanks! On 6/1/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:> > I haven''t thought it through (no pun intended) but maybe this could > be simplified and generalized , like add a ".through" to the stub and/ > or should_receive > ?? > > > On May 31, 2007, at 1:01 AM, Chris Anderson wrote: > > > I usually do something like this in my before(:each) section: > > > > User.stub!(:find).and_return(@u = mock_model(User, :posts => @pc > > mock(''posts collection''))) > > @pc.stub(:find).and_return([@p = mock_model(Post)]) > > > > with the corresponding should_receives in my various examples... the > > trick is to mock the user''s posts collection as its own object. > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- -Daniel Fischer http://danielfischer.com - Geek Blog http://abigfisch.com - Portfolio http://writersbeat.com - Writing Community
Martin Emde
2007-Jun-03 19:07 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Here is the correct spec for this index action: def index if params[:user_id] @user = User.find(params[:user_id]) @messages = @user.messages end end describe MessagesController, " handling GET /messages for a user" do before do @user = mock_model(User) @messages = mock("messages") @user.stub!(:messages).and_return(@messages) User.stub!(:find).and_return(@user) end def do_get get :index, :user_id => 1 end it "should render index template" do do_get response.should render_template(''index'') end it "should find user with params[:user_id]" do User.should_receive(:find).with(1).and_return(@user) do_get end it "should get user''s messages" do @user.should_receive(:messages).and_return(@messages) do_get end it "should assign the found messages for the view" do do_get assigns[:messages].should be(@messages) end end Hope that helps you out. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070603/011115a7/attachment.html
Anthony Carlos
2007-Jun-04 03:44 UTC
[rspec-users] Could anyone please help with rspec/nested resource behavior checking?
Daniel, Which of these examples is failing? Or, are you asking a more general question about how to use a mock or a stub? I''m going through my own pains trying to learn this stuff, so my perspective might be close to yours! Please scroll down; I have a couple of in-line questions for ya! On Jun 2, 2007, at 4:31 AM, Fischer, Daniel wrote:> Jonathon, > > Not sure - I don''t really know what to do at this point, but I have a > new problem again lol. > > Anyway, I can''t seem to create new mailing messages? I guess I ask > to many... > > Well, forgive me - but I''ll just attach it here since I can''t make > a new one. > > Hey, > > Sorry for so many questions - I''m really bad at this right now. > > I''m trying to cover the following code w/ rspec > > def index > if params[:user_id] > @user = User.find(params[:user_id]) > @messages = @user.messages > end > end > > So basically what I''m doing is listing all the messages for a user, > provided there is an id parameter. > > describe MessagesController, " handling GET /messages for a user" do > > before do > @message = mock_model(Message) > @message.stub!(:user_id).and_return(1) > @user = mock_model(User) > @user.stub!(:id).and_return(1) > User.stub!(:messages).and_return([@message]) > User.stub!(:find).and_return([@user]) > end > > def do_get > get :index, :user_id => 1 > end > > it "should be successful" do > do_get > response.should be_success > end > > it "should render index template" do > do_get > response.should render_template(''index'') > end > > it "should find all messages" do > User.should_receive(:messages).and_return([@message]) > do_get > end > > it "should assign the found messages for the view" do > do_get > assigns[:messages].should == [@message] > end > end > > > I''m trying to use the basic scaffold spec, but I''m absolutely clueless > on what the proper way to handle this is, I''m not even sure the proper > way I should mock the messages method, so it''ll return a "stub?" of a > collection, or whatever the proper term is. >Can you tell me where you found the basic scaffold spec? I haven''t seen it yet. I''ve been learning by studying the docs from the rspec site. Are you having a problem ensuring that the @messages variable in your controller has an array of messages after a GET? I think I can explain the use of a stub or mock if this is really your question. Thanks, -Anthony