2012-02-05 55 views
4

我遇到了一個失敗的測試,我很難調試。路由測試失敗:NoMethodError:「/ the/route」的未定義方法`值':字符串

我的測試情況是:

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

我的路線是:

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

當我運行測試時,我得到以下錯誤:

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

完整的錯誤輸出at:https://gist.github.com/1748264

當我運行耙路線,我看到:

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 

我運行該測試是幾乎相同的測試腳手架產生新:

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

任何想法是怎麼回事?

+0

我正在使用Rails 3.2.1。 – 2012-02-06 08:15:41

+0

我還發現在'before'塊中使用'get'會導致同樣的錯誤。 – 2014-09-30 03:02:01

回答

5

你在get和方法的參數之間加一個空格。不要這樣做。

你有這樣的:

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

當它應該是這樣的:

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

否則它會評價是這樣的:

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

謝謝瑞安,修好了。 – 2012-02-06 05:50:55

1

嘗試使用哈希風格路線:

{ :get => 'parties/new' }.should route_to('parties#new') 
+0

布蘭登,你的解決方案的作品。 :-)如果你對我的代碼失敗的原因感興趣,那是因爲get和左括號之間的空格,正如Ryan Bigg在上面指出的那樣。 – 2012-02-06 05:49:31

相關問題