我的测试失败,我调试很困难。
我的测试用例是:
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
完整错误输出:https://gist.github.com/1748264
当我运行rake路线时,我看到:
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 :(得分:6)
你在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"))
答案 1 :(得分:1)
尝试使用哈希风格的路线:
{ :get => 'parties/new' }.should route_to('parties#new')