Basic http authentication using rspec and rack-test.
Hello.
Example how to use basic http authentication for the sinatra or grape api rspec tests:
def headers(options = {})
# Using gem 'choices' for define different auth
# configuration based on env.
username = options.fetch(:username, Rails.configuration.auth.username)
password = options.fetch(:password, Rails.configuration.auth.password)
{ 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(username, password) }
end
def auth_get(route, params = {})
get route, params, headers
end
Written by Alexandr Korsak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#