-2

When I run the test then I get this an error:

/gems/ruby-2.3.1@app2/gems/webmock-2.1.0/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb:166:in `block in <class:TyphoeusAdapter>': Real HTTP connections are disabled. Unregistered request: HEAD https://api.travis-ci.org/ with headers {'Accept'=>'application/vnd.travis-ci.2+json', 'User-Agent'=>'Travis/1.8.2 (Mac OS X 10.11.4 like Darwin; Ruby 2.3.1-p112; RubyGems 2.5.1) Faraday/0.9.2 Typhoeus/0.8.0'} (WebMock::NetConnectNotAllowedError)

You can stub this request with the following snippet:

stub_request(:head, "https://api.travis-ci.org/").
  with(:headers => {'Accept'=>'application/vnd.travis-ci.2+json', 'User-Agent'=>'Travis/1.8.2 (Mac OS X 10.11.4 like Darwin; Ruby 2.3.1-p112; RubyGems 2.5.1) Faraday/0.9.2 Typhoeus/0.8.0'}).
  to_return(:status => 200, :body => "", :headers => {})

That's what I did to solve this problem:

spec_helper.rb:

require 'webmock/rspec'
require 'capybara/rspec'
require 'factory_girl_rails'

WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
  config.before(:each) do
    stub_request(:any, "https://api.travis-ci.org/")
      .with(:headers => {'Accept'=>'application/vnd.travis-ci.2+json', 'User-Agent'=>'Travis/1.8.2 (Mac OS X 10.11.4 like Darwin; Ruby 2.3.1-p112; RubyGems 2.5.1) Faraday/0.9.2 Typhoeus/0.8.0'})
      .to_return(:status => 200, :body => "", :headers => {})
  end
end

But I still continue to get this error, maybe someone have ideas how to fix it?

UPD: I want to write spec for api requests using webmock gem. But I don't need requests from travis-ci and want to add these requests to "ignore".

  • Can you give us the context? – David Guyon Jun 09 '16 at 08:25
  • What kind of context? I have `webmock` gem and I want to ignore this request from travis. I think I correctly added a "rule" for ignore this request. –  Jun 09 '16 at 08:32
  • I'm just asking for an introduction explaining what you want to do, with which technology and what you tried. Beacuse you are starting with "the test" and I have no idea about what is the context. Apply this update to your post and people will understand and you'll get many answers from the community ;). – David Guyon Jun 09 '16 at 08:38
  • Do you know where those requests come from? Seems just about right that travis would not run any requests in a testsuit, so Im pretty sure they are triggered before the "before(:each)" hook ;) – Ninigi Jun 09 '16 at 09:30
  • This request was from `travis` gem –  Jun 09 '16 at 09:48

1 Answers1

3

It solved my problem:

WebMock.disable_net_connect!(:allow => 'api.travis-ci.org')