"Real HTTP connections are disabled" error when trying test OmniAuth with RSpec
As dfedde implies, WebMock blocks HTTP requests in integration tests, but you can either stub the request or call WebMock.allow_net_connect!
to configure the tests to run as normal. Check out Trying to get selenium working in rails 3 - "WebMock::NetConnectNotAllowedError" or https://github.com/bblimke/webmock for details.
Related videos on Youtube
Comments
-
ironsand over 1 year
I've been trying to test OmniAuth with RSpec, but yet it have not worked.
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
And I get following error.
Failure/Error: visit "auth/twitter" ActionView::Template::Error: Real HTTP connections are disabled. Unregistered request:
According to the official document a request to
auth/twitter
should be redirect toauth/twitter/callback
. Why does it try to have HTTP connection?I've read following web pages and questions, but I couldn't find why the test failed.
http://blog.zerosum.org/2011/03/19/easy-rails-outh-integration-testing.html https://github.com/intridea/omniauth/wiki/Integration-Testing omniauth-facebook and testing with rspec http://blog.plataformatec.com.br/2010/12/acceptance-tests-for-omniauth/