rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.16k stars 1.03k forks source link

Request Specs throw a deprecation warning with Rails 5 #1515

Closed sebastiandeutsch closed 8 years ago

sebastiandeutsch commented 8 years ago

In my spec:

post '/api/v1/authentication', email: @user.email, password: 'foobarbaz', format: :json

will give me the following deprecation warning:

DEPRECATION WARNING: ActionDispatch::IntegrationTest HTTP request methods will accept only
the following keyword arguments in future Rails versions:
params, headers, env, xhr

Examples:

get '/profile',
  params: { id: 1 },
  headers: { 'X-Extra-Header' => '123' },
  env: { 'action_dispatch.custom' => 'custom' },
  xhr: true

I assume ActionDispatch::IntegrationTest should mimic the interface that is proposed by Rails 5.

My Gemfile.lock

GIT
  remote: git://github.com/rack/rack.git
  revision: 7cb3772a03f1b713622f68e178f90a71a66aff0d
  specs:
    rack (2.0.0.alpha)
      json

GIT
  remote: git://github.com/rails/arel.git
  revision: ea2d50706a5f8215ff2346fa562423700b2d2b6e
  specs:
    arel (7.0.0)

GIT
  remote: git://github.com/rails/rails.git
  revision: 0d2675f84f54504e5ba25b2f53b00bac239ef393
  specs:
    actioncable (5.0.0.beta1)
      actionpack (= 5.0.0.beta1)
      celluloid (~> 0.17.2)
      coffee-rails (~> 4.1.0)
      em-hiredis (~> 0.3.0)
      faye-websocket (~> 0.10.0)
      redis (~> 3.0)
      websocket-driver (~> 0.6.1)
    actionmailer (5.0.0.beta1)
      actionpack (= 5.0.0.beta1)
      actionview (= 5.0.0.beta1)
      activejob (= 5.0.0.beta1)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (5.0.0.beta1)
      actionview (= 5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      rack (~> 2.x)
      rack-test (~> 0.6.3)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      globalid (>= 0.3.6)
    activemodel (5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      builder (~> 3.1)
    activerecord (5.0.0.beta1)
      activemodel (= 5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      arel (~> 7.0)
    activesupport (5.0.0.beta1)
      concurrent-ruby (~> 1.0)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      method_source
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    rails (5.0.0.beta1)
      actioncable (= 5.0.0.beta1)
      actionmailer (= 5.0.0.beta1)
      actionpack (= 5.0.0.beta1)
      actionview (= 5.0.0.beta1)
      activejob (= 5.0.0.beta1)
      activemodel (= 5.0.0.beta1)
      activerecord (= 5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      bundler (>= 1.3.0, < 2.0)
      railties (= 5.0.0.beta1)
      sprockets-rails (>= 2.0.0)
    railties (5.0.0.beta1)
      actionpack (= 5.0.0.beta1)
      activesupport (= 5.0.0.beta1)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)

GIT
  remote: git://github.com/rails/sass-rails.git
  revision: 6e4eee736bcbfa5b2962467673c7a51abf434c67
  specs:
    sass-rails (6.0.0)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.4)
      sprockets (>= 4.0)
      sprockets-rails (< 4.0)

GIT
  remote: git://github.com/rails/sprockets-rails.git
  revision: 419958f24fb4ce2d4c86f68f87c5a76767f3aa88
  specs:
    sprockets-rails (3.0.0)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)

GIT
  remote: git://github.com/rails/sprockets.git
  revision: 47ac6ad00408bd1636e522e8977324e5138e74a4
  specs:
    sprockets (4.0.0)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)

GIT
  remote: https://github.com/matthewrudy/oauth2.git
  revision: 0afdc4e5d5b9b70780b817af40013682116a6955
  branch: rack2-with-travis-fix
  specs:
    oauth2 (1.0.0)
      faraday (>= 0.8, < 0.10)
      jwt (~> 1.0, < 1.5.2)
      multi_json (~> 1.3)
      multi_xml (~> 0.5)
      rack (>= 1.0, < 3)

GIT
  remote: https://github.com/rspec/rspec-core.git
  revision: a575b9b740a9af13c9760751aa3da09ffda30db5
  specs:
    rspec-core (3.5.0.pre)
      rspec-support (= 3.5.0.pre)

GIT
  remote: https://github.com/rspec/rspec-expectations.git
  revision: 87376eed1f580682c86ea88448ab0411be238c07
  specs:
    rspec-expectations (3.5.0.pre)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (= 3.5.0.pre)

GIT
  remote: https://github.com/rspec/rspec-mocks.git
  revision: b94e242ebbc51081fc2245e37c574f5d6d02b7f8
  specs:
    rspec-mocks (3.5.0.pre)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (= 3.5.0.pre)

GIT
  remote: https://github.com/rspec/rspec-rails.git
  revision: 7f2b695a2e70af1aa4f78346143e71e926bbccd7
  specs:
    rspec-rails (3.5.0.pre)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (= 3.5.0.pre)
      rspec-expectations (= 3.5.0.pre)
      rspec-mocks (= 3.5.0.pre)
      rspec-support (= 3.5.0.pre)

GIT
  remote: https://github.com/rspec/rspec-support.git
  revision: b0ff0f6e157288c33f8dc6d57f4ee157d43152fa
  specs:
    rspec-support (3.5.0.pre)

GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.4.0)
    bcrypt (3.1.10)
    builder (3.2.2)
    byebug (8.2.1)
    celluloid (0.17.2)
      celluloid-essentials
      celluloid-extras
      celluloid-fsm
      celluloid-pool
      celluloid-supervision
      timers (>= 4.1.1)
    celluloid-essentials (0.20.5)
      timers (>= 4.1.1)
    celluloid-extras (0.20.5)
      timers (>= 4.1.1)
    celluloid-fsm (0.20.5)
      timers (>= 4.1.1)
    celluloid-pool (0.20.5)
      timers (>= 4.1.1)
    celluloid-supervision (0.20.5)
      timers (>= 4.1.1)
    coffee-rails (4.1.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.1.x)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.10.0)
    concurrent-ruby (1.0.0)
    database_cleaner (1.5.0)
    diff-lcs (1.2.5)
    docile (1.1.5)
    em-hiredis (0.3.0)
      eventmachine (~> 1.0)
      hiredis (~> 0.5.0)
    erubis (2.7.0)
    eventmachine (1.0.8)
    execjs (2.6.0)
    factory_girl (4.5.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.5.0)
      factory_girl (~> 4.5.0)
      railties (>= 3.0.0)
    faker (1.3.0)
      i18n (~> 0.5)
    faraday (0.9.2)
      multipart-post (>= 1.2, < 3)
    faye-websocket (0.10.2)
      eventmachine (>= 0.12.0)
      websocket-driver (>= 0.5.1)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    hiredis (0.5.2)
    hitimes (1.2.3)
    i18n (0.7.0)
    jbuilder (2.4.0)
      activesupport (>= 3.0.0, < 5.1)
      multi_json (~> 1.2)
    json (1.8.3)
    jwt (1.5.1)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.3)
      mime-types (>= 1.16, < 3)
    method_source (0.8.2)
    mime-types (2.99)
    mini_portile2 (2.0.0)
    minitest (5.8.3)
    multi_json (1.11.2)
    multi_xml (0.5.5)
    multipart-post (2.0.0)
    nokogiri (1.6.7.1)
      mini_portile2 (~> 2.0.0.rc2)
    oauth (0.4.7)
    pg (0.18.4)
    rack-cors (0.4.0)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.2)
      loofah (~> 2.0)
    rake (10.4.2)
    redis (3.2.2)
    rspec-collection_matchers (1.1.2)
      rspec-expectations (>= 2.99.0.beta1)
    sass (3.4.20)
    simplecov (0.11.1)
      docile (~> 1.1.0)
      json (~> 1.8)
      simplecov-html (~> 0.10.0)
    simplecov-html (0.10.0)
    simplecov-json (0.2)
      json
      simplecov
    simplecov-rcov (0.2.3)
      simplecov (>= 0.4.1)
    sorcery (0.9.1)
      bcrypt (~> 3.1)
      oauth (~> 0.4, >= 0.4.4)
      oauth2 (>= 0.8.0)
    spring (1.6.1)
    thor (0.19.1)
    thread_safe (0.3.5)
    timers (4.1.1)
      hitimes
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    websocket-driver (0.6.3)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.2)

PLATFORMS
  ruby

DEPENDENCIES
  addressable (~> 2.4.0)
  arel!
  bcrypt (~> 3.1)
  byebug
  database_cleaner
  factory_girl_rails (~> 4.0)
  faker
  jbuilder
  jwt (~> 1.5.1)
  oauth (~> 0.4.4)
  oauth2!
  pg (~> 0.18)
  rack!
  rack-cors
  rails!
  rspec-collection_matchers (~> 1.1.2)
  rspec-core!
  rspec-expectations!
  rspec-mocks!
  rspec-rails!
  rspec-support!
  sass-rails!
  simplecov (~> 0.11.1)
  simplecov-json (~> 0.2)
  simplecov-rcov (~> 0.2.3)
  sorcery (~> 0.9.1)
  spring
  sprockets!
  sprockets-rails!
  tzinfo-data

BUNDLED WITH
   1.10.6
JonRowe commented 8 years ago

Thanks for reporting this, we're probably sending extra params to mimic an older behaviour in Rails.

jasnow commented 8 years ago

Try this:

post '/api/v1/authentication', params: { email: @user.email, password: 'foobarbaz', format: :json }
sebastiandeutsch commented 8 years ago

@jasnow you probably mean params: but yes it does the trick. Thanks a lot.

jasnow commented 8 years ago

Fixed

JesusEduardo2028 commented 8 years ago

im getting the same deprecation message after trying to set the headers in the method

get "/items", nil, {"access-token" => @access_token , 'uid' => @user.email}`

also

get "/items", params: {} , {"access-token" => @access_token , 'uid' => @user.email}`

give me this error

syntax error, unexpected '\n', expecting => (SyntaxError)

JonRowe commented 8 years ago

Try:

get "/items", params: {} , headers: {"access-token" => @access_token , 'uid' => @user.email}`

As your second snippet is invalid Ruby.

JesusEduardo2028 commented 8 years ago

thanks, i tried that but the headers did not pass to the get method this worked for me

get "/items", headers: {"access-token" => @access_token , 'uid' => @user.email}

and for both header and params

post '/items', {params: {item: item_hash }, headers:  {"access-token" => @access_token , 'uid' => @user.email}} 
mintthehole commented 7 years ago

What should i do to ignore such errors?

JonRowe commented 7 years ago

@mintthehole you can't ignore such errors, you have to fix them. They're issued by Rails so out of our control.

jwilsjustin commented 7 years ago

Does anyone have a link to the Rails source where this behavior changed?

jwilsjustin commented 7 years ago

Nevermind; I found it: https://github.com/rails/rails/pull/18323/ 🙂

harlantwood commented 6 years ago

@mintthehole not saying it's a good idea, but here is someone's workaround: https://stackoverflow.com/a/43787973/1533892

DreadPirateShawn commented 3 years ago

For those still poking around here -- another subtlety is that this:

get index_path

will trigger the deprecation warning, even though there's (seemingly) no old-style positional parameters provided at all.

Add empty params anyway to remediate the warning, e.g.

get index_path, params: {}