[rspec-users] How to Spec a Module to be used in a Controller

Matt Wynne matt at mattwynne.net
Thu Oct 23 07:00:20 EDT 2008


I want to be able to factor out bits of a controller's behaviour into  
modules, and spec them independently. E.g. modules like Authentication  
and ExceptionHandling that are mixed into ApplicationController.

In my spec, I create a FakeController class which inherits from  
ActionController::Base, and mix in the module.

This is working OK, but I'm struggling with the routing so that I can  
use the integration session #get method to spin up my FakeController.  
I have to set up the routing for this FakeController in a  
before(:all), then reload the default routing in after(:all) so as not  
to pollute the other specs.

Is this how other people do this? Is there a trick that I'm missing?

cheers,
Matt


More information about the rspec-users mailing list