-
Notifications
You must be signed in to change notification settings - Fork 968
/
adapter.rb
110 lines (80 loc) · 2.39 KB
/
adapter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
shared_examples 'an adapter' do |**options|
before { skip } if options[:skip]
context 'with SSL enabled' do
before { ENV['SSL'] = 'yes' }
include_examples 'adapter examples', options
end
context 'with SSL disabled' do
before { ENV['SSL'] = 'no' }
include_examples 'adapter examples'
end
end
shared_examples 'adapter examples' do |**options|
include Faraday::StreamingResponseChecker
let(:adapter) { described_class.name.split('::').last }
let(:conn_options) { { headers: { 'X-Faraday-Adapter' => adapter } }.merge(options[:conn_options] || {}) }
let(:adapter_options) do
return [] unless options[:adapter_options]
if options[:adapter_options].is_a?(Array)
options[:adapter_options]
else
[options[:adapter_options]]
end
end
let(:protocol) { ssl_mode? ? 'https' : 'http' }
let(:remote) { "#{protocol}://example.com" }
let(:conn) do
conn_options[:ssl] ||= {}
conn_options[:ssl][:ca_file] ||= ENV['SSL_FILE']
Faraday.new(remote, conn_options) do |conn|
conn.request :multipart
conn.request :url_encoded
conn.response :raise_error
conn.adapter described_class, *adapter_options
end
end
let!(:request_stub) { stub_request(http_method, remote) }
after do
expect(request_stub).to have_been_requested unless request_stub.disabled?
end
on_feature :connect_method do
describe '#connect' do
let(:http_method) { :connect }
it_behaves_like 'a request method', :connect
end
end
describe '#delete' do
let(:http_method) { :delete }
it_behaves_like 'a request method', :delete
end
describe '#get' do
let(:http_method) { :get }
it_behaves_like 'a request method', :get
end
describe '#head' do
let(:http_method) { :head }
it_behaves_like 'a request method', :head
end
describe '#options' do
let(:http_method) { :options }
it_behaves_like 'a request method', :options
end
describe '#patch' do
let(:http_method) { :patch }
it_behaves_like 'a request method', :patch
end
describe '#post' do
let(:http_method) { :post }
it_behaves_like 'a request method', :post
end
describe '#put' do
let(:http_method) { :put }
it_behaves_like 'a request method', :put
end
on_feature :trace_method do
describe '#trace' do
let(:http_method) { :trace }
it_behaves_like 'a request method', :trace
end
end
end