[rspec-users] Dreading Controller Specs

Rahoul Baruah baz at madeofstone.net
Tue Oct 21 15:57:46 EDT 2008

Hash: SHA1

On 21 Oct 2008, at 16:51, Matt Wynne wrote:

> Doesn't this just end up shifting the ugly mocking code into the  
> Presenter specs though?
> The stock answer to this question is to move this logic down into  
> the model layer, so that the interface the Presenter / Controller  
> uses to work with the database is simpler. This is what people call  
> 'listening to your tests' - if it's hard to mock, it's probably  
> indicative of a problem in your design.
> However, I worry about this 'skinny controller, fat model' advice,  
> it still doesn't feel like the final answer. To me, ActiveRecord  
> classes already have too many responsibilities, without making them  
> also orchestrate calls to other models.
> I have been thinking about this a lot lately, and I am starting to  
> feel like I also need a Service layer between the Controller /  
> Presenters and the 'Data Access Layer' (Models) to orchestrate the  
> work.

Personally I dislike the name "Presenter" - and much prefer Service,  
Builder or Adapter depending upon what its doing; everyone else seems  
to call it a presenter however.

But the point of the "Presenter/Service/Whatever" is precisely so that  
neither the controller nor the models have to orchestrate the calls  
between associated models.  If you think of it that way then I think  
it deals with your points above:

* the presenter/service's role is to coordinate the models - so its  
specs are purely about mocking the associations and the calls  
inbetween them
* the presenter/service isn't a model (not ActiveRecord::Base) - so  
it's not adding extra responsibilities to the models
* it is pretty much a service layer sat between controllers and models

Rahoul Baruah
Web design and development: http://www.3hv.co.uk/
Nottingham Forest: http://www.eighteensixtyfive.co.uk/
Serious Rails Hosting: http://www.brightbox.co.uk/
Lifecast: http://www.madeofstone.net/

Version: GnuPG v1.4.8 (Darwin)


More information about the rspec-users mailing list