我一直在尝试使用 RSpec 测试 OmniAuth,但尚未成功。
In spec_helper.rb
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:twitter, {:uid => '12345'})
and in spec/requests/static_pages_spec.rb
describe "for signed-in users" do
before do
visit "auth/twitter"
end
it { should have_content("Log out") }
end
我收到以下错误。
Failure/Error: visit "auth/twitter"
ActionView::Template::Error:
Real HTTP connections are disabled. Unregistered request:
根据官方文件要求auth/twitter
应该重定向到auth/twitter/callback
。为什么它尝试建立 HTTP 连接?
我已阅读以下网页和问题,但找不到测试失败的原因。
http://blog.zerosum.org/2011/03/19/easy-rails-outh-integration-testing.html http://blog.zerosum.org/2011/03/19/easy-rails-outh-integration-testing.html
https://github.com/intridea/omniauth/wiki/Integration-Testing https://github.com/intridea/omniauth/wiki/Integration-Testing
omniauth-facebook 和使用 rspec 进行测试 https://stackoverflow.com/questions/12575610/omniauth-facebook-and-testing-with-rspec
http://blog.plataformatec.com.br/2010/12/acceptance-tests-for-omniauth/ http://blog.plataformatec.com.br/2010/12/acceptance-tests-for-omniauth/
正如 dfedde 所暗示的那样,WebMock 在集成测试中阻止 HTTP 请求,但您可以存根请求或调用WebMock.allow_net_connect!
将测试配置为正常运行。查看尝试让 selenium 在 Rails 3 中工作 - “WebMock::NetConnectNotAllowedError” https://stackoverflow.com/questions/5980856/trying-to-get-selenium-working-in-rails-3-webmocknetconnectnotallowederror or https://github.com/bblimke/webmock https://github.com/bblimke/webmock了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)