Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Real HTTP connections are disabled" error when trying test OmniAuth with RSpec

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 to auth/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/

like image 757
ironsand Avatar asked Dec 09 '13 03:12

ironsand


1 Answers

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.

like image 172
kaimonster Avatar answered Sep 30 '22 14:09

kaimonster