Rails Controller Specs with users, roles and nested routes

I’ve long put off testing my controllers because of user authentication and nested controllers, dealing with stubs, etc. But today, a fully working test! As background, Advertisers have many trackers and the routes look like this: ActionController::Routing::Routes.draw do |map| map.resources :advertisers do |advertisers| advertisers.resources :trackers end end To set everything up in the specs, I included all the files in the spec/support directory and used Mocha as my mock framework Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f} Spec::Runner.configure do |config| config.mock_with :mocha end Then I set up my factories (rather than fixtures) using Factory Girl ...

March 3, 2010 · 3 min · Mark Simoneau