[rspec-users] Speccing module which should be included in controller

Harm harmaarts at gmail.com
Wed Mar 18 08:03:55 EDT 2009

Dear all,

I have a module ApiAccessControl which is included in all controllers
which deal with the API. It sees if the users is valid, logs etc etc.

I want to see if this module does what it is supposed to but I dont
want to test that in every single controller dealing with the API. So
I created a file api_access_control_spec.rb with this content:

require File.dirname(__FILE__) + '/../spec_helper'

class ApiAccessControlTestController < ApplicationController
  include ApiAccessControl

describe ApiAccessControlTestController do
  describe "without valid credentials" do
    it "should respond with a 401 Unauthorized on the GET 'index'" do
      get "index"
      response.response_code.should == 401

This works by the grace that my routes file has a fallback map.connect
':controller/:action/:id'. I never use that fallback only for this
particular test. Is there anyway to get rid of this entry in my

I tried something like this is a before block:
ActionController::Routing::RouteSet.new.add_route("index", :controller
=> "api_access_control_test", :action => "index")

But that doesn't seem to work. How do you guys test this sort of


More information about the rspec-users mailing list