路由测试失败:NoMethodError:未定义的方法“值”对于“/the/route”:字符串

发布于 2025-01-03 02:25:58 字数 1282 浏览 3 评论 0原文

我的测试失败了,调试起来非常困难。

我的测试用例是:

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

知道发生了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青丝拂面 2025-01-10 02:25:58

您在 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"))

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"))
|煩躁 2025-01-10 02:25:58

尝试使用散列式路由:

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

Try using a hash-style route:

{ :get => 'parties/new' }.should route_to('parties#new')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文