[rspec-users] Question About Cleaning Up Specs?
rick.denatale at gmail.com
Fri Feb 19 20:27:10 EST 2010
On Fri, Feb 19, 2010 at 8:13 PM, Pat Maddox <mailinglists at patmaddox.com> wrote:
> I disagree with the crowd on the basis that these examples are lazy. Very close to what I do though.
> Imagine you had one other example in there:
> it "should assign the post to the view" do
> post :create
> assigns[:post].should == @post
> Then you wouldn't really need the other should_receive examples. Why? Well, there's no way for that object to be returned other than via your User.find().build chain, is there?
Well actually you'd need a User.find().build chain which arranged for
the stub @user to return @posts from a call to posts. <G>
> I would still write the should_receive's, but they would include the arguments I expect the method to receive. That's the point where something could get screwed up.
Right, you would want to prove that you were finding the right user in
this case, although I'd guess in most conventional rails apps these
days you'd actually stub the controllers current_user method to return
@user rather than stubbing User.find
More information about the rspec-users