diff --git a/lib/rack/test.rb b/lib/rack/test.rb index e4b036e..0b519e9 100644 --- a/lib/rack/test.rb +++ b/lib/rack/test.rb @@ -312,7 +312,7 @@ def env_for(uri, env) multipart = env.has_key?(:multipart) ? env.delete(:multipart) : env['CONTENT_TYPE'].start_with?('multipart/') if params.is_a?(Hash) - if data = build_multipart(params, false, multipart) + if !params.empty? && data = build_multipart(params, false, multipart) env[:input] = data env['CONTENT_LENGTH'] ||= data.length.to_s env['CONTENT_TYPE'] = "#{multipart_content_type(env)}; boundary=#{MULTIPART_BOUNDARY}" diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb index 4524e7a..d71457a 100644 --- a/spec/rack/test_spec.rb +++ b/spec/rack/test_spec.rb @@ -121,6 +121,13 @@ last_request.env['rack.input'].read.must_include 'content-disposition: form-data; name="foo"' end + it 'supports multipart CONTENT_TYPE when using empty :params for POST to be empty body' do + request '/', method: :post, params: {}, 'CONTENT_TYPE'=>'multipart/form-data' + last_request.POST.must_be_empty + last_request.env['rack.input'].rewind + last_request.env['rack.input'].read.must_be_empty + end + it 'supports sending :query_params for POST' do request '/', method: :post, query_params: { 'foo' => 'bar' } last_request.GET['foo'].must_equal 'bar'