2016-09-23 34 views
2

我得到了我的测试的弃用警告,但我不明白我应该如何重构我的测试以符合未来的rails版本。我从多个测试中得到这个结果,所以附加了最简单的示例hight_voltage静态页面存在的示例。DEPRECATION警告:ActionController :: TestCase HTTP请求方法将在未来的Rails版本中只接受关键字参数

这里是我的测试>

describe HighVoltage::PagesController, '#show' do 
    %w(about conditions).each do |page| 
    context "on GET to /pages/#{page}" do 
     before do 
     get :show, id: page 
     end 

     it { should respond_with(:success) } 
     it { should render_template(page) } 
    end 
    end 
end 

这里是弃用警告。

*DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only 
keyword arguments in future Rails versions. 

Examples: 

get :show, params: { id: 1 }, session: { user_id: 1 } 
process :update, method: :post, params: { id: 1 } 
(called from block (4 levels) in <top (required)> at /Users/kimmo/Documents/care-city/spec/controllers/pages_controller_spec.rb:5) 
DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only 
keyword arguments in future Rails versions. 
+1

http://blog.bigbinary.com /2016/04/19/changes-to-test-controllers-in-rails-5.html – max

+2

一个好方法是开始使用请求规格而不是控制器规格。不幸的是,rspec-rails还没有完全赶上现有技术,并且仍然生成控制器规格。 – max

+0

谢谢@max我认为我需要为我的所有测试做一些重构 –

回答

3

您必须添加“PARAMS:”你PARAMS

get :show, params: {id: page} 

你可以通过页眉和其他配置更多关键字,请求

编辑:注意实际的错误你copypasted已经告诉你这么做

“示例:

get:sh流,则params:{ID:1},会话:{USER_ID:1}

过程:更新,方法::交,则params:{ID:1}”

相关问题