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.
Testing Basic Auth with httpbin The endpoint for Basic Auth is /basic-auth/{user}/{passwd} . For example, if you go to http://httpbin.org/basic-auth/foo/bar you'll see a prompt and you can authenticate using the username foo and the password bar .
RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.
The word describe is an RSpec keyword. It is used to define an “Example Group”. You can think of an “Example Group” as a collection of tests. The describe keyword can take a class name and/or string argument.
this works. thanks to @zetetic pointing me in the right direction
before do
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password")
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With