弃用警告:ActionController :: TestCase HTTP请求方法在将来的Rails版本中只接受关键字参数

时间:2016-09-23 14:57:24

标签: ruby-on-rails rspec ruby-on-rails-5 high-voltage

我正在为我的测试获得弃用警告,但我不明白我应该如何重构我的测试以符合未来的rails版本。我从多个测试中得到了这个,所以附上了hight_voltage静态页面存在的最简单的示例测试。

这是我的测试>

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 个答案:

答案 0 :(得分:4)

你必须为你的参数添加“params:”

get :show, params: {id: page}

您可以为请求传递更多关键字和其他配置

编辑:请注意,您复制的实际错误已经告诉您这样做

“例子:

get:show,params:{id:1},session:{user_id:1}

进程:更新,方法:: post,params:{id:1}“