3

I am getting deprecation warning for my tests but I do not understand how should I refactor my tests in order to be compliant with future rails versions. I get this from multiple tests so attached the most simple example testing that hight_voltage static pages exist.

Here is my test >

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

And here is the deprecation warning.

*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.
Kimmo Hintikka
  • 13,472
  • 7
  • 34
  • 63
  • 1
    http://blog.bigbinary.com/2016/04/19/changes-to-test-controllers-in-rails-5.html – max Sep 23 '16 at 15:18
  • 2
    A good approach would be to start using request specs instead of controller specs. Unfortunately rspec-rails has not quite caught up to the state of the art and still generates controller specs. – max Sep 23 '16 at 15:20
  • Thanks @max I think I need to do some refactoring for all my tests – Kimmo Hintikka Sep 25 '16 at 10:25
  • 1
    If you just want to convert your specs to the new format (vs request specs), use this handy gem: https://github.com/tjgrathwell/rails5-spec-converter – quainjn Dec 15 '16 at 18:02

1 Answers1

5

You have to add "params: " for your params

get :show, params: {id: page}

you can pass more keywords for headers and other config for the request

EDIT: notice that the actual error you copypasted already tells you to do that

"Examples:

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

process :update, method: :post, params: { id: 1 }"

arieljuod
  • 15,460
  • 2
  • 25
  • 36