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)