I’m trying to test the authenticate_or_request_with_http_basic method using Cucumber and Capybara, but it doesn’t work.
Any suggestions?
Authorization Controller:
before_filter :authorize
def show
flash[:notice] = 'Welcome back!'
end
private
def authorize
authenticate_or_request_with_http_basic do |username, password|
username == "admin" && password == "password"
end
end
Cucumber feature:
Scenario: Successful login
When I log in as "admin" with "password"
Then I should see "Welcome back!"
Cucumber step:
When /^I log in as "([^\"]*)" with "([^\"]*)"$/ do |username, password|
visit authorization_path
authorize username, password
end
Error message:
expected there to be content "Welcome back!" in "HTTP Basic: Access denied.\n" (RSpec::Expectations::ExpectationNotMetError)
I also have tried with the following command, but it doesn’t work either:
page.driver.browser.basic_authorize(username, password)
Ok, so – at what point is the information failing to get through. Try adding log/puts statements in appropriate locations to probe this.
If you can see either one in the log/output then at least you’ll know that the
uername/password is getting to that point in the code