In meinem spec_helper
explodiert, ich webmock Setup wie folgt:Webmock unregistriert Anfrage meinem Test
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
Nun, wenn ich diesen Test laufen einzeln bundle exec rspec spec/stack_client_query_spec.rb
verwenden, ist es passiert.
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
Allerdings, wenn ich die vollständige Testsuite mit bundle exec rspec
laufen, der gleichen Test bläst mit diesem Ausgang bis:
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'})
Es scheint wie ein früherer Test die Anforderung Domäne oder etwas zu überschreiben. Ich bin mir nicht sicher warum? Was mache ich falsch? Wie behebe ich das?
Sie haben für den gesamten Code einzufügen spec anders ist nicht möglich zu sagen, wo das Problem ist –