HTTP为水豚基本身份验证 [英] HTTP basic auth for Capybara
本文介绍了HTTP为水豚基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写一些RSpec的测试我的Rails 3应用程序,并试图从 Webrat 切换到的水豚。到目前为止好,但应用程序使用HTTP基本身份验证,授权我的管理员用户,任何想法如何,我可以测试与水豚?
I'm writing some RSpec tests for my Rails 3 application and trying to switch from Webrat to Capybara. So far so good but the application uses HTTP basic auth to authorize my admin user, any idea how I can test that with Capybara?
下面是我当前的Webrat步:
Here is my current Webrat step:
it 'should authenticate for admin' do
basic_auth('user', 'secret')
visit '/admin'
response.status.should eql 200
response.status.should_not eql 401
end
我如何做到这一点跟水豚?谢谢!
How do I do this with Capybara? Thanks!
推荐答案
我得到了它使用 page.driver.basic_authorize(姓名,密码)
,而不是工作。
I got it to work using page.driver.basic_authorize(name, password)
instead
的更新的:
目前,一水豚升级后,我用这堆解决方法:
At the moment, after a Capybara upgrade, I'm using this pile of workarounds:
if page.driver.respond_to?(:basic_auth)
page.driver.basic_auth(name, password)
elsif page.driver.respond_to?(:basic_authorize)
page.driver.basic_authorize(name, password)
elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize)
page.driver.browser.basic_authorize(name, password)
else
raise "I don't know how to log in!"
end
这篇关于HTTP为水豚基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文