Search code examples
ruby-on-railsrspec-railsrails-routing

Route test failing on: NoMethodError: undefined method `values' for "/the/route":String


I'm getting a failing test that I'm having great difficulty debugging.

My test case is:

it "routes to #active" do
  get ("/parties/active").should route_to("parties#active")
end

My route is:

resources :parties do
  get 'active', :on => :collection
end

When I run the test case, I get the following error:

NoMethodError: undefined method `values' for "/parties/active":String

Full error output at: https://gist.github.com/1748264

When I run rake routes, I see:

active_parties GET    /parties/active(.:format)   parties#active
       parties GET    /parties(.:format)          parties#index
               POST   /parties(.:format)          parties#create
     new_party GET    /parties/new(.:format)      parties#new
    edit_party GET    /parties/:id/edit(.:format) parties#edit
         party GET    /parties/:id(.:format)      parties#show
               PUT    /parties/:id(.:format)      parties#update
               DELETE /parties/:id(.:format)      parties#destroy
          root        /                           parties#show

The test I am running is practically identical to the test for new generated by scaffolding:

it "routes to #new" do
  get("/parties/new").should route_to("parties#new")
end

Any idea what's going on?


Solution

  • You're putting a space between get and the arguments for the method. Don't do that.

    You have this:

    it "routes to #active" do
      get ("/parties/active").should route_to("parties#active")
    end
    

    When it should be this:

    it "routes to #active" do
      get("/parties/active").should route_to("parties#active")
    end
    

    Otherwise it's going to evaluate like this:

      get(("/parties/active").should route_to("parties#active"))