Last active
April 19, 2018 17:19
-
-
Save stratigos/facb2e67e1b95115ebdc6941bee9ad9e to your computer and use it in GitHub Desktop.
RSpec Helper for Validating Token-based Auth Headers Returned with Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this helper along with
:request
specs, when bearer tokens are used for authentication. Works well with the devise_token_auth gem.