> > Lately I've started to write fewer interaction-based specs (like the > example you gave) when dealing with controllers. I tend to just make > the request and let it go all the way down to the database, to make > sure that everything is hooked up properly. The catch is that your > controllers have to be super skinny - you should be able to cover an > action with one or two examples - and have the majority of > permutations be handled by the model (and thus covered with model > specs).
> The way to do this is to not put any business logic in the action, and > the way to do THAT is to metaprogram the action away. > > Our controllers look like this: > > class PostsController < ApplicationController > actions :show, :new, :create > end > > with hooks for stuff like on_successful_create if the default behavior > isn't sufficient. > > I've been doing this for several months, ever since I started to use the make_resourceful plugin. There are several plugins that have this similar goal. The only downside I have run into with this approach is that people newer to rails and MVC in general have a very hard time figuring out what is going on. It is a layer of abstraction that is not for the faint of heart or inexperienced. Other than that I love the approach. > It feels pretty radical at first, but it just takes a bit of > creativity to make it work. I find it to be a very elegant approach. > > I am interested why having this approach has motivated you to take more of a state based approach on testing controllers. Assuming that you have other integration tests (stories) that test the full stack then having the controller specs hit the DB doesn't seem to buy you much and will slow your tests down quite a bit as compared to the interaction-based approach. I know you know this already so I am trying to understand how this newer way of writing controllers is more suited for allowing the specs to hit the db. Skinny controllers have been common practice for quite a while so I don't see how the layer of abstraction of declaring actions like above really changes things on the testing level. Do you feel that interaction-based specs on the controllers are too brittle.. or verbose.. or what? Thanks for sharing :) -Ben _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users