[英]ruby-on-rails: mocking a route in functional test
I have a route in my routes.rb file: 我的routes.rb文件中有一条路由:
map.connect 'login', :controller => 'users', :action => 'login'
and I have a partial being rendered in a view as: 并且在视图中有部分渲染为:
login_path
This view gets called in the functional test of the controller. 该视图在控制器的功能测试中被调用。
However, in the functional test I get the error: 但是,在功能测试中,我得到了错误:
ActionView::TemplateError: undefined local variable or method `login_path' for #<ActionView::Base:0x4762c90>
1) What's the best way of mocking it for the test? 1)模拟测试的最佳方法是什么?
2) Does this indicate a design flaw? 2)这是否表示设计缺陷?
map.connect
will add an unnamed route. map.connect
将添加一个未命名的路线。 What you probably want in your routes.rb
is: 您可能在routes.rb
想要的是:
map.login 'login', :controller => 'users', :action => 'login'
That will create the named routes login_path
and login_url
for you. 这将为您创建命名路由login_path
和login_url
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.