Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created March 6, 2013 12:26
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 oivoodoo/5098963 to your computer and use it in GitHub Desktop.
Save oivoodoo/5098963 to your computer and use it in GitHub Desktop.
Spec for grape with http_basic auth in Rails project.
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
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