Testing route with proc --- possible and how?

I have this route (Rails 3) which handles redirecting shortened urls:

handles the shortened url lookup

match ‘:hash’ => redirect { |params|
Sharing.get_url_path_by_short_url(params[:hash]) }, :constraints => {
=> /[a-zA-Z0-9]{7}/ }

It works correctly at the ui. However am having trouble getting a spec
working for it. Note that in the UI the user must be logged in to get to
url, but the traffic first hits the directed route and then app
handles if the user is not logged in.

In spec/routing/routing_spec.rb (note that all necessary test data for
it to
pass is set up and verified):

describe “Shorter URL redirect” do
it “routes GET ‘STU1VWX’ to stations/1” do
{ :get => “/”, :hash => “STU1VWX” }.should route_to(
:controller => “stations”,
:action => “show”,
:params => {:id => 1} )

The problem is that I get this error:

 Failure/Error: { :get => "/", :hash => "STU1VWX" }.should route_to(
   The recognized options <{"controller"=>"sessions", 

did not match <{“controller”=>“stations”, “action”=>“show”,
“params”=>{:id=>1}}>, difference: <{“controller”=>“stations”,
“action”=>“show”, “params”=>{:id=>1}}>.

sessions#new is our root url. So I see that by calling :get => ‘/’ the
seems to be ignored. I have confirmed this by changing the root url and
the new root path show in the error above.

Note that if I change the test to:

{ :get => "STU1VWX" }.should route_to(  ...


{ :get => "/STU1VWX" }.should route_to(  ...

I get a ‘no route matches’ exception

I have a few conjectures as to that is happening:

  • The dynamic route is ignored (i.e. the :hash parameter is being
    ignored). Calling in debugger
    “Rails.application.routes.recognize_path(‘STU1VWX’)” returns a no
    matches exception.
  • The way routes is being tested that the proc on the route does not
    run eventhough the route is seen
  • I need to handle authentication (this would confuse me a bit as it
    would seem that on a routes test we should just be testing the output
    of the

If anyone can give me some ideas I would appreciate it.