Rails RSpec Routing: Testing actions in :except do NOT route

routes, rspec, ruby-on-rails

Solution

I don't know why the lambda would fail, but I don't think the rspec-rails dsl is intended to be used like that. Have you tried something like this?

{ :get => "/products/1/edit" }.should_not be_routable

http://relishapp.com/rspec/rspec-rails/docs/routing-specs/be-routable-matcher

So you can't specify what it doesn't route to, but you can specify that it doesn't get routed.

Problem

Fairly simple problem (I'd have thought), but I'm having some issues: In Rails 3.1.0.rc6/RSpec 2.6.0, I'm trying to test the routing of my 'products' resource, routed like this: ``` resources :products, :except => [:edit, :update] ``` The routing for the valid actions works, but I want to ensure that the edit and update routes are not callable. Here's what I'm trying: ``` it "does not route to #edit" do lambda { get("/products/1/edit") }.should raise_error end ``` Failure/Error: lambda { get("/products/1/edit") }.should raise_error expected Exception but nothing was raised # ./spec/routing/products_routing_spec.rb:11:in `block (3 levels) in ' ...And yet, when I run ``` it "does not route to #edit" do get("/products/1/edit").should_not route_to("products#edit", :id => "1") end ``` I get Failure/Error: get("/products/1/edit").should_not route_to("products#edit", :id => "1") ActionController::RoutingError: No route matches "/products/1/edit" Any idea what's going on here? I'm guessing this should be pretty simple, but I can't seem to figure it out.

Original source