RoutingError with RSpec Controller test on Scoped Route

So I have a route that looks like this:

scope "4" do   scope "public" do     scope ":apikey" do       resources :shops     end   end end

And a bunch of controller specs, an example of which looks like this:

describe ShopsController do

  describe "when responding to a GET" do

    context "#new" do       it "should create a new instance of the shop class" do         get :new         @shop.should_not_be_nil       end     end

  end

end

In rake routes, as well as via a web browser, this controller/action works fine. However, RSpec throws:

1) ShopsController when responding to a GET#new should create a new instance of the shop class Failure/Error: get :new ActionController::RoutingError:    No route matches {:controller=>"shops", :action=>"new"} # ./spec/controllers/shops_controller_spec.rb:9:in `block (4 levels) in <top (required)>'

When I remove the scope statements from the route, the tests work fine. Is there a way to "inform" RSpec of the route scopes?

The route requires an api key, so that needs to be included in the args passed to 'get':

get :new, :apikey => "ignore"

As for @shop.should_not be_nil, that's probably going to fail as well once you get past the route issue. To specify that a new instance gets created, you'll need to either interact with the database, e.g.

expect do   get :new, :apikey => "ignore" end.to change(Shop, :count).by(1)

... or mock the message to create the model:

Shop.should_receive(:create) get :new, :apikey => "ignore"

HTH, David