From 2b1d186a08a7b3887cada8b34adb310f184eaf2b Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 07:28:41 -0700 Subject: [PATCH 01/13] add tests for connection methods --- spec/faraday/connection_methods_spec.rb | 89 +++++++++++++++++++++++++ spec/faraday/connection_spec.rb | 20 ------ 2 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 spec/faraday/connection_methods_spec.rb diff --git a/spec/faraday/connection_methods_spec.rb b/spec/faraday/connection_methods_spec.rb new file mode 100644 index 000000000..3a8868f92 --- /dev/null +++ b/spec/faraday/connection_methods_spec.rb @@ -0,0 +1,89 @@ +describe 'making requests with' do + let(:conn) do + Faraday::Connection.new( + url: "http://example.com", + headers: { 'faraday-conn': '1' }, + ) + end + + let(:method) { nil } + + shared_examples 'method with query' do + it 'makes request with path' do + stubbed = stub_request(method, 'http://example.com/a?a=1') + conn.send(method, '/a', a: 1) + expect(stubbed).to have_been_made.once + end + + it 'makes request with block' do + stubbed = stub_request(method, 'http://example.com/a?a=1') + conn.send(method, '/a') do |req| + req.params[:a] = 1 + end + expect(stubbed).to have_been_made.once + end + end + + shared_examples 'method with body' do + it 'makes request with path' do + stubbed = stub_request(method, 'http://example.com/a') + res = conn.send(method, '/a', a: 1) + expect(res.env.request_body).to eq('a=1') + expect(stubbed).to have_been_made.once + end + + it 'makes request with block' do + stubbed = stub_request(method, 'http://example.com/a?a=1') + res = conn.send(method, '/a', a: 1) do |req| + req.params[:a] = 1 + end + expect(res.env.request_body).to eq('a=1') + expect(stubbed).to have_been_made.once + end + end + + context '#delete' do + let(:method) { :delete } + it_behaves_like 'method with query' + end + + context '#get' do + let(:method) { :get } + it_behaves_like 'method with query' + end + + context '#head' do + let(:method) { :head } + it_behaves_like 'method with query' + end + + context '#options' do + let(:method) { :options } + it_behaves_like 'method with query' + + it 'returns connection options with no args' do + expect(conn.options).to be_a(Faraday::Options) + end + + it 'makes request with nil path' do + stubbed = stub_request(method, 'http://example.com') + conn.send(method, nil) + expect(stubbed).to have_been_made.once + end + end + + context '#patch' do + let(:method) { :patch } + it_behaves_like 'method with body' + end + + context '#post' do + let(:method) { :post } + it_behaves_like 'method with body' + end + + context '#put' do + let(:method) { :put } + it_behaves_like 'method with body' + end +end diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb index b2842d16a..331a61265 100644 --- a/spec/faraday/connection_spec.rb +++ b/spec/faraday/connection_spec.rb @@ -611,26 +611,6 @@ def encoder.encode(params) end end - context 'with options' do - let(:url) { 'http://example.com' } - - it 'returns connection options with no args' do - expect(conn.options).to be_a(Faraday::Options) - end - - it 'makes request with path' do - stubbed = stub_request(:options, 'http://example.com/a?a=1') - conn.options('/a', a: 1) - expect(stubbed).to have_been_made.once - end - - it 'makes request with nil path' do - stubbed = stub_request(:options, 'http://example.com') - conn.options(nil) - expect(stubbed).to have_been_made.once - end - end - context 'with default params encoder' do let!(:stubbed) { stub_request(:get, 'http://example.com?color%5B%5D=red&color%5B%5D=blue') } after { expect(stubbed).to have_been_made.once } From f53f717d5d886b557760ef86f8a2195243efdab1 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 07:30:03 -0700 Subject: [PATCH 02/13] support trace and connect methods --- lib/faraday.rb | 2 +- lib/faraday/connection.rb | 2 +- spec/faraday/connection_methods_spec.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/faraday.rb b/lib/faraday.rb index 03153f8e7..73bf7433e 100644 --- a/lib/faraday.rb +++ b/lib/faraday.rb @@ -19,7 +19,7 @@ # module Faraday VERSION = "0.15.3" - METHODS_WITH_QUERY = %w[get head delete] + METHODS_WITH_QUERY = %w[get head delete connect trace] METHODS_WITH_BODY = %w[post put patch] class << self diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index ac9038f92..3ff88aacc 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -12,7 +12,7 @@ module Faraday # class Connection # A Set of allowed HTTP verbs. - METHODS = Set.new [:get, :post, :put, :delete, :head, :patch, :options] + METHODS = Set.new [:get, :post, :put, :delete, :head, :patch, :options, :trace, :connect] # @return [Hash] URI query unencoded key/value pairs. attr_reader :params diff --git a/spec/faraday/connection_methods_spec.rb b/spec/faraday/connection_methods_spec.rb index 3a8868f92..24ef70725 100644 --- a/spec/faraday/connection_methods_spec.rb +++ b/spec/faraday/connection_methods_spec.rb @@ -42,6 +42,11 @@ end end + context '#connect' do + let(:method) { :connect } + it_behaves_like 'method with query' + end + context '#delete' do let(:method) { :delete } it_behaves_like 'method with query' @@ -86,4 +91,9 @@ let(:method) { :put } it_behaves_like 'method with body' end + + context '#trace' do + let(:method) { :trace } + it_behaves_like 'method with query' + end end From 0a6e8e59793fbf7dbf4dc905638a717a09578321 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 07:33:32 -0700 Subject: [PATCH 03/13] document #connect and #trace --- lib/faraday/connection.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb index 3ff88aacc..1ea4163da 100644 --- a/lib/faraday/connection.rb +++ b/lib/faraday/connection.rb @@ -159,6 +159,36 @@ def headers=(hash) # @yield [Faraday::Request] for further request customizations # @return [Faraday::Response] + # @!method connect(url = nil, params = nil, headers = nil) + # Makes a CONNECT HTTP request without a body. + # @!scope class + # + # @param url [String] The optional String base URL to use as a prefix for all + # requests. Can also be the options Hash. + # @param params [Hash] Hash of URI query unencoded key/value pairs. + # @param headers [Hash] unencoded HTTP header key/value pairs. + # + # @example + # conn.connect '/items/1' + # + # @yield [Faraday::Request] for further request customizations + # @return [Faraday::Response] + + # @!method trace(url = nil, params = nil, headers = nil) + # Makes a TRACE HTTP request without a body. + # @!scope class + # + # @param url [String] The optional String base URL to use as a prefix for all + # requests. Can also be the options Hash. + # @param params [Hash] Hash of URI query unencoded key/value pairs. + # @param headers [Hash] unencoded HTTP header key/value pairs. + # + # @example + # conn.connect '/items/1' + # + # @yield [Faraday::Request] for further request customizations + # @return [Faraday::Response] + # @!visibility private METHODS_WITH_QUERY.each do |method| class_eval <<-RUBY, __FILE__, __LINE__ + 1 From a66fd30ad188571ae0922a970746bac574c8ec7d Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 07:40:32 -0700 Subject: [PATCH 04/13] test request bodies on methods with query --- spec/faraday/connection_methods_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/faraday/connection_methods_spec.rb b/spec/faraday/connection_methods_spec.rb index 24ef70725..d6699ff64 100644 --- a/spec/faraday/connection_methods_spec.rb +++ b/spec/faraday/connection_methods_spec.rb @@ -11,15 +11,18 @@ shared_examples 'method with query' do it 'makes request with path' do stubbed = stub_request(method, 'http://example.com/a?a=1') - conn.send(method, '/a', a: 1) + res = conn.send(method, '/a', a: 1) + expect(res.env.request_body).to be_nil expect(stubbed).to have_been_made.once end it 'makes request with block' do stubbed = stub_request(method, 'http://example.com/a?a=1') - conn.send(method, '/a') do |req| + res = conn.send(method, '/a') do |req| req.params[:a] = 1 + req.body = 'body' end + expect(res.env.request_body).to eq('body') expect(stubbed).to have_been_made.once end end From 830ef844b3fabeb41deb33a80cf0c6ad389c71ec Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 08:13:35 -0700 Subject: [PATCH 05/13] don't expect options requests to have a request body --- lib/faraday/options/env.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/faraday/options/env.rb b/lib/faraday/options/env.rb index 197a5d598..f28326cf1 100644 --- a/lib/faraday/options/env.rb +++ b/lib/faraday/options/env.rb @@ -53,7 +53,7 @@ class Env < Options.new(:method, :request_body, :url, :request, :request_headers # A Set of HTTP verbs that typically send a body. If no body is set for # these requests, the Content-Length header is set to 0. - MethodsWithBodies = Set.new [:post, :put, :patch, :options] + MethodsWithBodies = Set.new Faraday::METHODS_WITH_BODY options :request => RequestOptions, :request_headers => Utils::Headers, :response_headers => Utils::Headers @@ -169,4 +169,4 @@ def self.member_set @member_set ||= Set.new(members) end end -end \ No newline at end of file +end From 276d013dcff03b2727553357f60c1ac28f406c94 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 08:26:35 -0700 Subject: [PATCH 06/13] symbols are not strings --- lib/faraday/options/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/faraday/options/env.rb b/lib/faraday/options/env.rb index f28326cf1..4d2126f1c 100644 --- a/lib/faraday/options/env.rb +++ b/lib/faraday/options/env.rb @@ -53,7 +53,7 @@ class Env < Options.new(:method, :request_body, :url, :request, :request_headers # A Set of HTTP verbs that typically send a body. If no body is set for # these requests, the Content-Length header is set to 0. - MethodsWithBodies = Set.new Faraday::METHODS_WITH_BODY + MethodsWithBodies = Set.new [:post, :put, :patch] options :request => RequestOptions, :request_headers => Utils::Headers, :response_headers => Utils::Headers From ac688f5fffa1959ac6331e714d283e23734a72dd Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 08:45:21 -0700 Subject: [PATCH 07/13] add specs for connect/trace, organize all request method specs --- spec/support/shared_examples/adapter.rb | 57 +++++++++++++++---------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/spec/support/shared_examples/adapter.rb b/spec/support/shared_examples/adapter.rb index e4fa76500..0a768bdbe 100644 --- a/spec/support/shared_examples/adapter.rb +++ b/spec/support/shared_examples/adapter.rb @@ -4,7 +4,7 @@ context 'with SSL enabled' do before { ENV['SSL'] = 'yes' } include_examples 'adapter examples', options - end + end context 'with SSL disabled' do before { ENV['SSL'] = 'no' } @@ -50,6 +50,18 @@ expect(request_stub).to have_been_requested unless request_stub.disabled? end + describe '#connect' do + let(:http_method) { :connect } + + it_behaves_like 'a request method', :connect + end + + describe '#delete' do + let(:http_method) { :delete } + + it_behaves_like 'a request method', :delete + end + describe '#get' do let(:http_method) { :get } @@ -66,22 +78,16 @@ end end - describe '#post' do - let(:http_method) { :post } - - it_behaves_like 'a request method', :post - end - - describe '#put' do - let(:http_method) { :put } + describe '#head' do + let(:http_method) { :head } - it_behaves_like 'a request method', :put + it_behaves_like 'a request method', :head end - describe '#delete' do - let(:http_method) { :delete } + describe '#options' do + let(:http_method) { :options } - it_behaves_like 'a request method', :delete + it_behaves_like 'a request method', :options end describe '#patch' do @@ -90,16 +96,21 @@ it_behaves_like 'a request method', :patch end - describe '#head' do - let(:http_method) { :head } + describe '#post' do + let(:http_method) { :post } - it_behaves_like 'a request method', :head + it_behaves_like 'a request method', :post + end + + describe '#put' do + let(:http_method) { :put } + + it_behaves_like 'a request method', :put end - # TODO: Enable after adding API for options method - # describe '#options' do - # let(:http_method) { :options } - # - # it_behaves_like 'a request method' - # end -end \ No newline at end of file + describe '#trace' do + let(:http_method) { :trace } + + it_behaves_like 'a request method', :trace + end +end From 297adb3a2ab9b1ec306adc90aab8b17f2d54a0a4 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 08:55:27 -0700 Subject: [PATCH 08/13] add more tests around request body behavior --- .../support/shared_examples/request_method.rb | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/support/shared_examples/request_method.rb b/spec/support/shared_examples/request_method.rb index e11a83854..5574bfafd 100644 --- a/spec/support/shared_examples/request_method.rb +++ b/spec/support/shared_examples/request_method.rb @@ -44,10 +44,27 @@ # end # end + it 'sends request body' do + request_stub.with(Hash[:body, "test"]) + res = if query_or_body == :body + conn.public_send(http_method, '/', 'test') + else + conn.public_send(http_method, '/') do |req| + req.body = 'test' + end + end + expect(res.env.request_body).to eq('test') + end + it 'sends url encoded parameters' do payload = { name: 'zack' } request_stub.with(Hash[query_or_body, payload]) - conn.public_send(http_method, '/', payload) + res = conn.public_send(http_method, '/', payload) + if query_or_body == :query + expect(res.env.request_body).to be_nil + else + expect(res.env.request_body).to eq('name=zack') + end end it 'sends url encoded nested parameters' do @@ -176,4 +193,4 @@ expect { conn.public_send(http_method, '/') }.to raise_error(Faraday::ProxyAuthError) end -end \ No newline at end of file +end From 6cf1ab354af0b4f2ae7cd301f58d6d721bd0640e Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 09:30:53 -0700 Subject: [PATCH 09/13] only run that test on adapters that support a body on GET requests --- spec/support/shared_examples/adapter.rb | 12 +----------- spec/support/shared_examples/request_method.rb | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/spec/support/shared_examples/adapter.rb b/spec/support/shared_examples/adapter.rb index 0a768bdbe..5d8a79be0 100644 --- a/spec/support/shared_examples/adapter.rb +++ b/spec/support/shared_examples/adapter.rb @@ -4,7 +4,7 @@ context 'with SSL enabled' do before { ENV['SSL'] = 'yes' } include_examples 'adapter examples', options - end + end context 'with SSL disabled' do before { ENV['SSL'] = 'no' } @@ -66,16 +66,6 @@ let(:http_method) { :get } it_behaves_like 'a request method', :get - - on_feature :body_on_get do - it 'handles request body' do - body = { bodyrock: 'true' } - request_stub.with(body: body) - conn.get('/') do |req| - req.body = body - end - end - end end describe '#head' do diff --git a/spec/support/shared_examples/request_method.rb b/spec/support/shared_examples/request_method.rb index 5574bfafd..461a80368 100644 --- a/spec/support/shared_examples/request_method.rb +++ b/spec/support/shared_examples/request_method.rb @@ -44,16 +44,18 @@ # end # end - it 'sends request body' do - request_stub.with(Hash[:body, "test"]) - res = if query_or_body == :body - conn.public_send(http_method, '/', 'test') - else - conn.public_send(http_method, '/') do |req| - req.body = 'test' + on_feature :body_on_get do + it 'sends request body' do + request_stub.with(Hash[:body, "test"]) + res = if query_or_body == :body + conn.public_send(http_method, '/', 'test') + else + conn.public_send(http_method, '/') do |req| + req.body = 'test' + end end + expect(res.env.request_body).to eq('test') end - expect(res.env.request_body).to eq('test') end it 'sends url encoded parameters' do From 95125f6398901e3c941cec4e56ae7805ffd40762 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 09:43:33 -0700 Subject: [PATCH 10/13] add spec feature flags since patron is strict --- spec/faraday/adapter/excon_spec.rb | 4 ++-- spec/faraday/adapter/httpclient_spec.rb | 4 ++-- spec/faraday/adapter/net_http_persistent_spec.rb | 2 +- spec/faraday/adapter/net_http_spec.rb | 4 ++-- spec/faraday/adapter/typhoeus_spec.rb | 4 ++-- spec/support/shared_examples/adapter.rb | 16 ++++++++++------ 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/spec/faraday/adapter/excon_spec.rb b/spec/faraday/adapter/excon_spec.rb index f3faed49e..267e41f87 100644 --- a/spec/faraday/adapter/excon_spec.rb +++ b/spec/faraday/adapter/excon_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::Excon do - features :body_on_get, :reason_phrase_parse + features :body_on_get, :reason_phrase_parse, :trace_method, :connect_method it_behaves_like 'an adapter' @@ -12,4 +12,4 @@ expect(conn.data[:debug_request]).to be_truthy end -end \ No newline at end of file +end diff --git a/spec/faraday/adapter/httpclient_spec.rb b/spec/faraday/adapter/httpclient_spec.rb index 3167af3b7..6b7df22fc 100644 --- a/spec/faraday/adapter/httpclient_spec.rb +++ b/spec/faraday/adapter/httpclient_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::HTTPClient do - features :body_on_get, :reason_phrase_parse, :compression + features :body_on_get, :reason_phrase_parse, :compression, :trace_method, :connect_method it_behaves_like 'an adapter' @@ -30,4 +30,4 @@ expect(conn.options[:bind][:host]).to eq(host) expect(conn.options[:bind][:port]).to eq(port) end -end \ No newline at end of file +end diff --git a/spec/faraday/adapter/net_http_persistent_spec.rb b/spec/faraday/adapter/net_http_persistent_spec.rb index 6a702185d..adbb4622e 100644 --- a/spec/faraday/adapter/net_http_persistent_spec.rb +++ b/spec/faraday/adapter/net_http_persistent_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::NetHttpPersistent do - features :body_on_get, :reason_phrase_parse, :compression + features :body_on_get, :reason_phrase_parse, :compression, :trace_method, :connect_method it_behaves_like 'an adapter' diff --git a/spec/faraday/adapter/net_http_spec.rb b/spec/faraday/adapter/net_http_spec.rb index df6d129e9..b92720fa7 100644 --- a/spec/faraday/adapter/net_http_spec.rb +++ b/spec/faraday/adapter/net_http_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::NetHttp do - features :body_on_get, :reason_phrase_parse, :compression, :streaming + features :body_on_get, :reason_phrase_parse, :compression, :streaming, :trace_method, :connect_method it_behaves_like 'an adapter' @@ -45,4 +45,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/faraday/adapter/typhoeus_spec.rb b/spec/faraday/adapter/typhoeus_spec.rb index c62b527eb..a0a91b13a 100644 --- a/spec/faraday/adapter/typhoeus_spec.rb +++ b/spec/faraday/adapter/typhoeus_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::Typhoeus do - features :body_on_get, :parallel + features :body_on_get, :parallel, :trace_method, :connect_method it_behaves_like 'an adapter' -end \ No newline at end of file +end diff --git a/spec/support/shared_examples/adapter.rb b/spec/support/shared_examples/adapter.rb index 5d8a79be0..2041fab26 100644 --- a/spec/support/shared_examples/adapter.rb +++ b/spec/support/shared_examples/adapter.rb @@ -50,10 +50,12 @@ expect(request_stub).to have_been_requested unless request_stub.disabled? end - describe '#connect' do - let(:http_method) { :connect } + on_feature :connect_method do + describe '#connect' do + let(:http_method) { :connect } - it_behaves_like 'a request method', :connect + it_behaves_like 'a request method', :connect + end end describe '#delete' do @@ -98,9 +100,11 @@ it_behaves_like 'a request method', :put end - describe '#trace' do - let(:http_method) { :trace } + on_feature :trace_method do + describe '#trace' do + let(:http_method) { :trace } - it_behaves_like 'a request method', :trace + it_behaves_like 'a request method', :trace + end end end From 1c00020f40550c5ef68a2a7ebf9ac3d62f1c984c Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 09:49:27 -0700 Subject: [PATCH 11/13] Remove redundant tests in favor of the adapter-specific ones --- spec/faraday/connection_methods_spec.rb | 102 ------------------------ 1 file changed, 102 deletions(-) delete mode 100644 spec/faraday/connection_methods_spec.rb diff --git a/spec/faraday/connection_methods_spec.rb b/spec/faraday/connection_methods_spec.rb deleted file mode 100644 index d6699ff64..000000000 --- a/spec/faraday/connection_methods_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -describe 'making requests with' do - let(:conn) do - Faraday::Connection.new( - url: "http://example.com", - headers: { 'faraday-conn': '1' }, - ) - end - - let(:method) { nil } - - shared_examples 'method with query' do - it 'makes request with path' do - stubbed = stub_request(method, 'http://example.com/a?a=1') - res = conn.send(method, '/a', a: 1) - expect(res.env.request_body).to be_nil - expect(stubbed).to have_been_made.once - end - - it 'makes request with block' do - stubbed = stub_request(method, 'http://example.com/a?a=1') - res = conn.send(method, '/a') do |req| - req.params[:a] = 1 - req.body = 'body' - end - expect(res.env.request_body).to eq('body') - expect(stubbed).to have_been_made.once - end - end - - shared_examples 'method with body' do - it 'makes request with path' do - stubbed = stub_request(method, 'http://example.com/a') - res = conn.send(method, '/a', a: 1) - expect(res.env.request_body).to eq('a=1') - expect(stubbed).to have_been_made.once - end - - it 'makes request with block' do - stubbed = stub_request(method, 'http://example.com/a?a=1') - res = conn.send(method, '/a', a: 1) do |req| - req.params[:a] = 1 - end - expect(res.env.request_body).to eq('a=1') - expect(stubbed).to have_been_made.once - end - end - - context '#connect' do - let(:method) { :connect } - it_behaves_like 'method with query' - end - - context '#delete' do - let(:method) { :delete } - it_behaves_like 'method with query' - end - - context '#get' do - let(:method) { :get } - it_behaves_like 'method with query' - end - - context '#head' do - let(:method) { :head } - it_behaves_like 'method with query' - end - - context '#options' do - let(:method) { :options } - it_behaves_like 'method with query' - - it 'returns connection options with no args' do - expect(conn.options).to be_a(Faraday::Options) - end - - it 'makes request with nil path' do - stubbed = stub_request(method, 'http://example.com') - conn.send(method, nil) - expect(stubbed).to have_been_made.once - end - end - - context '#patch' do - let(:method) { :patch } - it_behaves_like 'method with body' - end - - context '#post' do - let(:method) { :post } - it_behaves_like 'method with body' - end - - context '#put' do - let(:method) { :put } - it_behaves_like 'method with body' - end - - context '#trace' do - let(:method) { :trace } - it_behaves_like 'method with query' - end -end From 59e9308d1e16574327f6b7916d411e6f90f552f4 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 21 Feb 2019 09:51:15 -0700 Subject: [PATCH 12/13] link Faraday::Env::MethodsWithBodies with Faraday::METHODS_WITH_BODY --- lib/faraday/options/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/faraday/options/env.rb b/lib/faraday/options/env.rb index 4d2126f1c..a5096a1c9 100644 --- a/lib/faraday/options/env.rb +++ b/lib/faraday/options/env.rb @@ -53,7 +53,7 @@ class Env < Options.new(:method, :request_body, :url, :request, :request_headers # A Set of HTTP verbs that typically send a body. If no body is set for # these requests, the Content-Length header is set to 0. - MethodsWithBodies = Set.new [:post, :put, :patch] + MethodsWithBodies = Set.new(Faraday::METHODS_WITH_BODY.map(&:to_sym)) options :request => RequestOptions, :request_headers => Utils::Headers, :response_headers => Utils::Headers From 3ec3d0b3eba71d6b6d2f1fb114929ab22d90e841 Mon Sep 17 00:00:00 2001 From: iMacTia Date: Mon, 25 Feb 2019 13:44:41 +0000 Subject: [PATCH 13/13] Renames `body_on_get` feature to `request_body_on_query_methods`. --- spec/faraday/adapter/excon_spec.rb | 2 +- spec/faraday/adapter/httpclient_spec.rb | 2 +- spec/faraday/adapter/net_http_persistent_spec.rb | 2 +- spec/faraday/adapter/net_http_spec.rb | 2 +- spec/faraday/adapter/typhoeus_spec.rb | 2 +- spec/support/shared_examples/request_method.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/faraday/adapter/excon_spec.rb b/spec/faraday/adapter/excon_spec.rb index 267e41f87..1691ed73e 100644 --- a/spec/faraday/adapter/excon_spec.rb +++ b/spec/faraday/adapter/excon_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::Excon do - features :body_on_get, :reason_phrase_parse, :trace_method, :connect_method + features :request_body_on_query_methods, :reason_phrase_parse, :trace_method, :connect_method it_behaves_like 'an adapter' diff --git a/spec/faraday/adapter/httpclient_spec.rb b/spec/faraday/adapter/httpclient_spec.rb index 6b7df22fc..503b296d7 100644 --- a/spec/faraday/adapter/httpclient_spec.rb +++ b/spec/faraday/adapter/httpclient_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::HTTPClient do - features :body_on_get, :reason_phrase_parse, :compression, :trace_method, :connect_method + features :request_body_on_query_methods, :reason_phrase_parse, :compression, :trace_method, :connect_method it_behaves_like 'an adapter' diff --git a/spec/faraday/adapter/net_http_persistent_spec.rb b/spec/faraday/adapter/net_http_persistent_spec.rb index adbb4622e..69c21ed9c 100644 --- a/spec/faraday/adapter/net_http_persistent_spec.rb +++ b/spec/faraday/adapter/net_http_persistent_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::NetHttpPersistent do - features :body_on_get, :reason_phrase_parse, :compression, :trace_method, :connect_method + features :request_body_on_query_methods, :reason_phrase_parse, :compression, :trace_method, :connect_method it_behaves_like 'an adapter' diff --git a/spec/faraday/adapter/net_http_spec.rb b/spec/faraday/adapter/net_http_spec.rb index b92720fa7..42fcf2538 100644 --- a/spec/faraday/adapter/net_http_spec.rb +++ b/spec/faraday/adapter/net_http_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::NetHttp do - features :body_on_get, :reason_phrase_parse, :compression, :streaming, :trace_method, :connect_method + features :request_body_on_query_methods, :reason_phrase_parse, :compression, :streaming, :trace_method, :connect_method it_behaves_like 'an adapter' diff --git a/spec/faraday/adapter/typhoeus_spec.rb b/spec/faraday/adapter/typhoeus_spec.rb index a0a91b13a..f41187c17 100644 --- a/spec/faraday/adapter/typhoeus_spec.rb +++ b/spec/faraday/adapter/typhoeus_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Faraday::Adapter::Typhoeus do - features :body_on_get, :parallel, :trace_method, :connect_method + features :request_body_on_query_methods, :parallel, :trace_method, :connect_method it_behaves_like 'an adapter' end diff --git a/spec/support/shared_examples/request_method.rb b/spec/support/shared_examples/request_method.rb index 461a80368..498a2cabf 100644 --- a/spec/support/shared_examples/request_method.rb +++ b/spec/support/shared_examples/request_method.rb @@ -44,7 +44,7 @@ # end # end - on_feature :body_on_get do + on_feature :request_body_on_query_methods do it 'sends request body' do request_stub.with(Hash[:body, "test"]) res = if query_or_body == :body