[英]How do I pass in a parameter called 'controller' in RSpec?
I have a controller that expects a parameter called controller
and the RSpec test I wrote doesn't seem to like the fact that I'm passing in it as a parameter with get
. 我有一个控制器,它期望一个名为controller
的参数,而我编写的RSpec测试似乎不喜欢我将它作为参数传递给get
的事实。
require 'spec_helper'
describe PageHelpsController do
describe 'GET :search' do
it "returns" do
get :search, { :controller => 'employer', :action => 'edit', :edition => 'usa', :anchor => 'collaborator' }
response.status.should be_success
response.should render_template(:partial => 'shared/page_help')
end
end
end
vagrant@debian-squeeze64:/vagrant$ bundle exec rspec spec/controllers/page_helps_controller_spec.rb
F
Failures:
1) PageHelpsController GET :search returns
Failure/Error: Unable to find /vagrant/spec/controllers/page_helps_controller_spec.rb to read failed line
ActionController::RoutingError:
No route matches {:controller=>"employer", :action=>"search", :relative_url_root=>nil, :edition=>"usa"}
# ./spec/controllers/page_helps_controller_spec.rb:11
I'm going to take a shot at this question assuming you created a parameter named controller
. 假设您创建了一个名为controller
的参数,我将试着解决这个问题。
The problem is you are confusing Rails by creating a parameter called controller
. 问题是您通过创建一个称为controller
的参数来混淆Rails。 It's assuming there is a controller called Employer
which of course doesn't exist. 假设存在一个不存在的名为Employer
的控制器。 That is why you are receiving the route error. 这就是为什么您收到路由错误的原因。 To solve this, you will have to change the parameter named controller
to something else. 为了解决这个问题,您将必须将名为controller
的参数更改为其他参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.