12

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/

Community
  • 1
  • 1
ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

11

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.

Andrew Farrell
  • 2,368
  • 2
  • 22
  • 25
kaimonster
  • 341
  • 4
  • 10