5

I have some rails controllers that use authenticate_or_request_with_http_basic -- how can I set the user/pass in my rspec examples?

I'm surprised to not have been able to find this elsewhere on the web, so maybe I'm using the wrong terms? -- I found some very old things, or what seems to me like very complicated things. Seems like at this point rspec would either have direct support for this, or a tidy idiomatic solution.

2
  • 1
    Did you see this one? stackoverflow.com/questions/8013770/… Commented Feb 25, 2013 at 21:59
  • thanks! that led me to figure out a simpler way... Commented Feb 25, 2013 at 23:07

1 Answer 1

6

this works. thanks to @zetetic pointing me in the right direction

before do
  @request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password")
end
Sign up to request clarification or add additional context in comments.

1 Comment

Using string interpolation: @request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64::encode64('username:password')}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.