Skip to content

Instantly share code, notes, and snippets.

@stratigos
Last active April 19, 2018 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stratigos/facb2e67e1b95115ebdc6941bee9ad9e to your computer and use it in GitHub Desktop.
Save stratigos/facb2e67e1b95115ebdc6941bee9ad9e to your computer and use it in GitHub Desktop.
RSpec Helper for Validating Token-based Auth Headers Returned with Request
module RequestSpecHelper::SessionsHelper
# Set single expectation that checks auth headers were returned.
def expect_auth_headers(response)
expect(response.headers.keys).to include('access-token', 'client', 'expiry', 'uid')
end
end
########################################################################
# Include this file in each "Sessions" Request spec, at the top of the file:
include RequestSpecHelper::SessionsHelper
# Or, alternatively, include it in every Request spec, in the `rails_helper.rb` config file:
config.include RequestSpecHelper::SessionsHelper, type: :request
@stratigos
Copy link
Author

Use this helper along with :request specs, when bearer tokens are used for authentication. Works well with the devise_token_auth gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment