Testing an action behind HTTP Authentication


I'm writing an integration test and would like to make sure that, with
the correct credentials, I get the proper response. The problem is I
don't know how to use the 'get' method to attach the username and
password to the request.

For example, when using RSpec's Story tests..

  When("I request the user information for that user's id") do
    get "/api/users/#{@user.id}"

Gives me a 401 Unauthorized response because that request isn't

Any help would be appreciated, thanks!

~ Jason C

Take a look at


There is a method at line 268,

  def login(action, username, password, header = 'HTTP_AUTHORIZATION')
    @request.env[header] = "Basic #{Base64.encode64(username << ':' <<
    get action

Maybe you can use the complete plugin (
http://svn.codahale.com/simple_http_auth )?


Thanks Stephan! That worked!