In my spec_helper
, I have webmock setup like so:
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.before(:each) do
stub_request(:get, /cdn.\w+.io/).
with(:headers => {'Accept-Encoding'=>'gzip', 'Access-Token'=> ENV['ACCESS_TOKEN'], 'Api-Key'=>ENV['API_KEY'], 'Expect'=>'', 'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'}).
to_return(:status => 200, :body => "", :headers => {})
end
end
Now when I run this test individually using bundle exec rspec spec/stack_client_query_spec.rb
, it passes.
describe "can query for entries by asking for a content_type" do
it "returns a Typhoeus response with queried with a content_type" do
response = create_client.content_type(content_type_uid).get
expect(response).to be_instance_of(Typhoeus::Response)
end
end
However when I run the full test suite using bundle exec rspec
, the same test blows up with this output:
Failure/Error:
response = Typhoeus::Request.new(
endpoint,
headers: { api_key: headers[:api_key], access_token: headers[:access_token],
accept_encoding: "gzip" }
).run
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: GET http://cdn.mycustom.domain/v3/content_types/shirts/entries/ with headers {'Accept-Encoding'=>'gzip', 'Access-Token'=>'bltbdc42da30987971c', 'Api-Key'=>'blt1c501b5fa4b64377', 'Expect'=>'', 'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'}
You can stub this request with the following snippet:
stub_request(:get, "http://cdn.mycustom.domain/v3/content_types/shirts/entries/").
with(:headers => {'Accept-Encoding'=>'gzip', 'Access-Token'=>'bltbdc42da30987971c', 'Api-Key'=>'blt1c501b5fa4b64377', 'Expect'=>'', 'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'}).
to_return(:status => 200, :body => "", :headers => {})
registered request stubs:
stub_request(:get, "/cdn.\w+.io/").
with(:headers => {'Accept-Encoding'=>'gzip', 'Access-Token'=>'bltbdc42da30987971c', 'Api-Key'=>'blt1c501b5fa4b64377', 'Expect'=>'', 'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'})
It seems like an earlier test is overwriting the request domain or something. I am not sure why!? What am I doing wrong? How do I fix this?
Looks like you have stubbed
but the actual request is going to
you can change your stub to