[rspec-users] When to use Factories, Mock Models, Mocks & Stubs

J. B. Rainsberger jbrainsberger at gmail.com
Wed Feb 3 12:21:18 EST 2010

2010/2/3 Nicolás Sanguinetti <godfoca at gmail.com>:
> On Wed, Feb 3, 2010 at 2:07 PM,  <me at franklakatos.com> wrote:
>> I absolutely love the idea of encapsulated the daisy chained calls
>> (c_u.comp.project) into a controller methods so all i gotta do is stub that
>> out.
> Oooh, I hate that one :)
> You're adding lots of small methods that actually don't define how the
> class should behave, IMO.
> In fact, how a client or project is related to a user is a
> responsibility of the models, not the controllers.
> I would much rather turn
> @client = current_user.company.clients.find(params[:project][:client_id])
> @project = @client.projects.build(params[:project])
> into
> @client = current_user.find_client(params[:project][:client_id])
> @project = @client.projects.new(params[:project])
> And add the helper method on the models.

I strongly agree. Extracting the methods to the controller is merely
an intermediate step. If the methods belong on other objects, then
that tends to become clear soon enough.
J. B. (Joe) Rainsberger :: http://www.jbrains.ca ::
Diaspar Software Services :: http://www.diasparsoftware.com
Author, JUnit Recipes
2005 Gordon Pask Award for contribution to Agile practice :: Agile
2010: Learn. Practice. Explore.

More information about the rspec-users mailing list