ruby on rails - RSpec.configure and the request object -


I have tracks 3.1 application that is being created as a reciprocal API. The scheme is to handle authentication based on the API key, which has passed the authorization via HTTP header on each request. To test this in order RSpec, I wanted to set the request.env ["HTTP_AUTHORIZATION"] in the config.before block: < Pre class = "Lang-rb prettyprint-override"> Configure RSPC. Config | Config.mock_with: rspec config.use_transactional_fixtures = true config.before (: each) authorization header # set API key in request.env ["HTTP_AUTHORIZATION"] = "6db13cc8-815f-42ce-aa9e-446556fe3d72" end end request object does not exist in the code> config.before block.

There is another approach to setting this header out of the included block of each controller test file?

I have not tried it myself but maybe shared example group you can solve your problem Can help:

  shared_examples_for "all API controllers" before (what is: each) request.env ["HTTP_AUTHORIZATION"] = "blah" end # ... also here you can Examining the general functionality of all its API controllers # like the response to the lack of invalid authorization headers or header end OneOfAPIControllers it_should_behave_lik can describe them as "All API Controllers", "It Should Work" ... and End    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -