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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With