“得到” Rails 控制器测试中的方法抛出“没有路由匹配”对于模块范围内的控制器
我似乎无法解决我的范围路由的 rspec 控制器规范中的“get”方法。
我正在确定“访问者”控制器的路由范围,以便它们位于“访问者”模块命名空间内,但位于路由的根部。因此“mysite.com/foo”将转到 Visitor::FooController。
config/routes.rb
scope :module => 'visitor' do
resources :inquiries
end
spec/controllers/visitor/inquiries_controller_spec.rb
require 'spec_helper'
describe Visitor::InquiriesController do
describe 'GET new' do
it 'should render template visitor/inquiries/new' do
get :new
end
end
end
app/controllers/visitor/inquiries_controller.rb
class Visitor::InquiriesController < Visitor::BaseController
def new
end
end
当我运行规范时,出现以下错误。
No route matches {:controller=>"visitor/inquiries", :action=>"new"}
我尝试为 get 添加一些附加参数(例如 :url => 'inquiries/new', :controller => 'inquiries'),但我似乎无法解决这个问题。用我的浏览器点击“查询/新建”效果很好,并显示我的路线正在按预期工作。
我是 rspec 的新手,所以可能有一些我不理解的基本问题。否则,我正在寻找一种方法来解决这个问题,以便我可以测试这些“访客”控制器。任何帮助表示赞赏!
I can't seem to work around the 'get' method in my rspec controller specs for my scoped routes.
I'm scoping the routes for my 'visitor' controllers so that they are within the 'visitor' module namespace, but are at the root of the routing. So 'mysite.com/foo' goes to the Visitor::FooController.
config/routes.rb
scope :module => 'visitor' do
resources :inquiries
end
spec/controllers/visitor/inquiries_controller_spec.rb
require 'spec_helper'
describe Visitor::InquiriesController do
describe 'GET new' do
it 'should render template visitor/inquiries/new' do
get :new
end
end
end
app/controllers/visitor/inquiries_controller.rb
class Visitor::InquiriesController < Visitor::BaseController
def new
end
end
When I run the spec I get the following error.
No route matches {:controller=>"visitor/inquiries", :action=>"new"}
I tried adding some additional parameters for get (e.g. :url => 'inquiries/new', :controller => 'inquiries') but I can't seem to get around this issue. Hitting 'inquiries/new' with my browser works fine and shows that my routes are working as expected.
I'm new to rspec so there may be some fundamental issue I'm not understanding here. Otherwise I'm looking for a way to push past this issues so I can test these 'visitor' controllers. Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我第二天重新启动计算机时,问题就解决了。 Spork 似乎存在某种问题导致了这个问题。我不确定这个问题是否可以删除,但它可能不会为 Stackoverflow 提供很多价值。
The problem was fixed when I restarted my computer the next day. There seemed to be some sort of issue with Spork that was causing the problem. I'm not sure if this question can be removed, but it probably doesn't provide a lot of value to Stackoverflow.
查看你的 config/routes.rb
取消注释以下行:匹配 ':controller(/:action(/:id(.:format)))'
现在应该可以了
Have a look to your config/routes.rb
uncomment follow line: match ':controller(/:action(/:id(.:format)))'
Now it should works