Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec request.env wrong number of arguments

This is my code:

before(:each) do
  request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key.access_token)
end

My test was supposed to pass but it is displaying this error:

Failure/Error: request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials("#{api_key.access_token}")
 ArgumentError:
   wrong number of arguments (0 for 1..2) 
  • Gems:

    rspec-rails version = 2.14.1.

    rails verison = 4

    mongoid from 'git://github.com/mongoid/mongoid.git'

like image 615
Felippe Raposo Avatar asked Dec 06 '25 04:12

Felippe Raposo


1 Answers

The request method you are accessing in your test is documented at http://rubydoc.info/gems/rack-test/0.6.2/Rack/Test/Session:request and expects 1 or 2 arguments as the error indicates. You're getting an error on request.env because you're invoking request with no arguments.

like image 81
Peter Alfvin Avatar answered Dec 07 '25 20:12

Peter Alfvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!