[rspec-users] Could anyone please help with rspec/nested resource behavior checking?

Fischer, Daniel daniel at danielfischer.com
Thu May 31 04:31:47 EDT 2007


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


More information about the rspec-users mailing list