summaryrefslogtreecommitdiff
path: root/spec/support/unicorn.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/unicorn.rb')
-rw-r--r--spec/support/unicorn.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/support/unicorn.rb b/spec/support/unicorn.rb
new file mode 100644
index 00000000000..0b01fc9e26c
--- /dev/null
+++ b/spec/support/unicorn.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+REQUEST_CLASSES = [
+ ::Grape::Request,
+ ::Rack::Request
+].freeze
+
+def request_body_class
+ return ::Unicorn::TeeInput if defined?(::Unicorn)
+
+ Class.new(StringIO) do
+ def string
+ raise NotImplementedError, '#string is only valid under Puma which uses StringIO, use #read instead'
+ end
+ end
+end
+
+RSpec.configure do |config|
+ config.before(:each, :unicorn) do
+ REQUEST_CLASSES.each do |request_class|
+ allow_any_instance_of(request_class)
+ .to receive(:body).and_wrap_original do |m, *args|
+ request_body_class.new(m.call(*args).read)
+ end
+ end
+ end
+end