Created
March 6, 2013 12:26
-
-
Save oivoodoo/5098963 to your computer and use it in GitHub Desktop.
Spec for grape with http_basic auth in Rails project.
This file contains 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 ApiHelper | |
def response | |
last_response | |
end | |
def headers(options = {}) | |
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 | |
end |
This file contains 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
describe Example do | |
include Rack::Test::Methods | |
include ApiHelper | |
def app | |
Example | |
end | |
before do | |
auth_get '/' | |
end | |
it { response.should be_ok } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment