From 7939b70c1442ee081979e503b8bb8db087763524 Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Tue, 24 Apr 2018 16:42:19 +0200 Subject: [PATCH] Rewind IO-alike request body after it was consumed. Webmock triggers `body.each` twice upon inital request recording: 1. to perform request 2. to record request data into webmock request registry But even without WebMock, generally Body#each must be replayable IMO. --- lib/http/request/body.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/http/request/body.rb b/lib/http/request/body.rb index 690ce28a..82516f4a 100644 --- a/lib/http/request/body.rb +++ b/lib/http/request/body.rb @@ -35,6 +35,7 @@ def each(&block) yield @source elsif @source.respond_to?(:read) IO.copy_stream(@source, ProcIO.new(block)) + @source.rewind if @source.respond_to?(:rewind) elsif @source.is_a?(Enumerable) @source.each(&block) end