簡體   English   中英

棄用警告:ActionController :: TestCase HTTP請求方法在將來的Rails版本中將僅接受關鍵字參數

[英]DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only keyword arguments in future Rails versions

我的測試收到過時警告,但我不明白如何重構測試才能與將來的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.

您必須為參數添加“ params:”

get :show, params: {id: page}

您可以為標題傳遞更多關鍵字,並為請求傳遞其他配置

編輯:請注意,您復制粘貼的實際錯誤已經告訴您執行此操作

“例子:

獲取:show,參數:{id:1},會話:{user_id:1}

進程:update,方法::post,參數:{id:1}“

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM