those who knows more say the idea is to keep in the example only what is important for the example (but they surely say it even better than me) which is what you are doing +1,
greetings, joaquin 2010/2/18 Matt Wynne <m...@mattwynne.net> > > On 18 Feb 2010, at 16:25, m...@franklakatos.com wrote: > > I know we are suppose to keep specs obvious and readable, but is it normal >> (or there any opposition) to stubbing every method call that you needed in a >> before block and simply over-riding the same method with a should_receive in >> the actual tested it()? >> >> Example >> >> describe "#create" do >> it "should find a user" >> @user = mock_model(User) >> User.should_receive(:find).and_return @user >> @posts = [] >> @post = mock_model(Post) >> @posts.stub(:build).and_return @post >> post "create" >> end >> >> it "should build a post from that user" do >> @user = mock_model(User) >> User.stub(:find).and_return @user >> @posts = [] >> @post = mock_model(Post) >> @posts.should_receive(:build).and_return @post >> post "create" >> end >> end >> >> ... would become .. >> >> >> describe "#create" do >> before do >> @user = mock_model(User) >> User.stub(:find).and_return @user >> @posts = [] >> @post = mock_model(Post) >> @posts.stub(:build).and_return @post >> end >> >> it "should find a user" >> User.should_receive(:find).and_return @user >> post "create" >> end >> >> it "should build a post from that user" do >> @posts.should_receive(:build).and_return @post >> post "create" >> end >> end >> >> Note that I stubbed both method calls in the before, but only >> should_require'd them in the appropriate it()? >> >> Let me know if that's good practice >> > > That's exactly what I do. > > > >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users@rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > cheers, > Matt > > http://mattwynne.net > +447974 430184 > > > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > -- www.least-significant-bit.com
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users