spec/vcr/library_hooks/fakeweb_spec.rb in vcr-2.2.2 vs spec/vcr/library_hooks/fakeweb_spec.rb in vcr-2.2.3
- old
+ new
@@ -16,21 +16,12 @@
def directly_stub_request(method, url, response_body)
::FakeWeb.register_uri(method, url, :body => response_body)
end
- it_behaves_like 'a hook into an HTTP library', :fakeweb, 'net/http' do
- before(:each) do
- VCR::LibraryHooks::FakeWeb::RequestHandler.already_seen_requests.clear
- end
+ it_behaves_like 'a hook into an HTTP library', :fakeweb, 'net/http'
- after(:each) do
- # assert that we are cleaning up the global state after every request
- VCR::LibraryHooks::FakeWeb::RequestHandler.already_seen_requests.to_a.should eq([])
- end
- end
-
describe "some specific Net::HTTP edge cases" do
before(:each) do
VCR.stub(:real_http_connections_allowed? => true)
end
@@ -92,9 +83,27 @@
VCR.configuration.ignore_request { |r| true }
ignored_body = make_post_request.body
ignored_body.should_not eq(recorded_body)
ignored_body.should match(/Response \d+/)
+ end
+
+ context 'when the same Net::HTTP request object is used twice' do
+ let(:uri) { URI("http://localhost:#{VCR::SinatraApp.port}/foo") }
+ let(:http) { Net::HTTP.new(uri.host, uri.port) }
+
+ it 'raises an UnhandledHTTPRequestError when using a cassette that only recorded one request' do
+ VCR.use_cassette("new_cassette", :record => :once) do
+ request = Net::HTTP::Get.new(uri.request_uri)
+ http.request(request)
+ end
+
+ VCR.use_cassette("new_cassette", :record => :once) do
+ request = Net::HTTP::Get.new(uri.request_uri)
+ http.request(request)
+ http.request(request)
+ end
+ end
end
end
describe "VCR.configuration.after_library_hooks_loaded hook" do
let(:run_hook) { $fakeweb_after_loaded_hook.conditionally_invoke }