如何在RSpec中传入一个名为'controller'的参数?

时间:2012-12-14 00:32:20

标签: ruby-on-rails rspec actioncontroller

我有一个控制器需要一个名为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

1 个答案:

答案 0 :(得分:1)

假设您创建了一个名为controller的参数,我将尝试解决此问题。

问题是你通过创建一个名为controller的参数来混淆Rails。假设有一个名为Employer的控制器当然不存在。这就是您收到路线错误的原因。要解决此问题,您必须将名为controller的参数更改为其他内容。