faraday 2.14.4 → 2.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +11 -5
- data/lib/faraday/connection.rb +23 -16
- data/lib/faraday/encoders/nested_params_encoder.rb +1 -1
- data/lib/faraday/error.rb +29 -2
- data/lib/faraday/logging/formatter.rb +1 -1
- data/lib/faraday/options/proxy_options.rb +2 -2
- data/lib/faraday/options.rb +4 -3
- data/lib/faraday/rack_builder.rb +4 -4
- data/lib/faraday/response/raise_error.rb +7 -1
- data/lib/faraday/response.rb +5 -2
- data/lib/faraday/utils/headers.rb +41 -7
- data/lib/faraday/utils.rb +15 -3
- data/lib/faraday/version.rb +1 -1
- data/spec/external_adapters/faraday_specs_setup.rb +2 -0
- data/spec/support/integration/test_pki.rb +77 -0
- data/spec/support/integration/tls_server.rb +92 -0
- data/spec/support/integration_helper.rb +71 -0
- metadata +7 -31
- data/spec/faraday/adapter/test_spec.rb +0 -460
- data/spec/faraday/adapter_registry_spec.rb +0 -28
- data/spec/faraday/adapter_spec.rb +0 -55
- data/spec/faraday/connection_spec.rb +0 -860
- data/spec/faraday/error_spec.rb +0 -175
- data/spec/faraday/middleware_registry_spec.rb +0 -31
- data/spec/faraday/middleware_spec.rb +0 -213
- data/spec/faraday/options/env_spec.rb +0 -76
- data/spec/faraday/options/options_spec.rb +0 -297
- data/spec/faraday/options/proxy_options_spec.rb +0 -79
- data/spec/faraday/options/request_options_spec.rb +0 -19
- data/spec/faraday/params_encoders/flat_spec.rb +0 -42
- data/spec/faraday/params_encoders/nested_spec.rb +0 -179
- data/spec/faraday/rack_builder_spec.rb +0 -317
- data/spec/faraday/request/authorization_spec.rb +0 -118
- data/spec/faraday/request/instrumentation_spec.rb +0 -74
- data/spec/faraday/request/json_spec.rb +0 -199
- data/spec/faraday/request/url_encoded_spec.rb +0 -93
- data/spec/faraday/request_spec.rb +0 -119
- data/spec/faraday/response/json_spec.rb +0 -206
- data/spec/faraday/response/logger_spec.rb +0 -299
- data/spec/faraday/response/raise_error_spec.rb +0 -286
- data/spec/faraday/response_spec.rb +0 -84
- data/spec/faraday/utils/headers_spec.rb +0 -109
- data/spec/faraday/utils_spec.rb +0 -120
- data/spec/faraday_spec.rb +0 -69
- data/spec/spec_helper.rb +0 -142
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Integration test configuration and helpers
|
|
4
|
+
#
|
|
5
|
+
# This module provides configuration and helpers for integration tests that run
|
|
6
|
+
# against real HTTP services in GitHub Actions service containers.
|
|
7
|
+
#
|
|
8
|
+
# Service URLs are accessed by service name in container jobs (no port mapping needed).
|
|
9
|
+
# See .github/workflows/integration-tests.yml for service configuration.
|
|
10
|
+
|
|
11
|
+
module Faraday
|
|
12
|
+
module IntegrationHelpers
|
|
13
|
+
# Service URLs for GitHub Actions service containers
|
|
14
|
+
# These are accessed by service name when running in container jobs
|
|
15
|
+
HTTPBIN_URL = ENV.fetch('HTTPBIN_URL', 'http://httpbin')
|
|
16
|
+
# Forward proxies (mitmdump); the second one requires Basic credentials
|
|
17
|
+
PROXY_URL = ENV.fetch('PROXY_URL', 'http://proxy:8080')
|
|
18
|
+
AUTH_PROXY_URL = ENV.fetch('AUTH_PROXY_URL', 'http://auth-proxy:8080')
|
|
19
|
+
|
|
20
|
+
# Create a direct Faraday connection to httpbin (no proxy)
|
|
21
|
+
#
|
|
22
|
+
# @param options [Hash] Connection options (merged with defaults)
|
|
23
|
+
# @yield [builder] Middleware stack configuration
|
|
24
|
+
# @return [Faraday::Connection]
|
|
25
|
+
def httpbin_connection(options = {}, &block)
|
|
26
|
+
Faraday.new(HTTPBIN_URL, options, &block)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Generic helper to create a Faraday connection for integration tests
|
|
30
|
+
#
|
|
31
|
+
# @param url [String] Base URL for the connection
|
|
32
|
+
# @param options [Hash] Connection options
|
|
33
|
+
# @yield [builder] Middleware stack configuration
|
|
34
|
+
# @return [Faraday::Connection]
|
|
35
|
+
def create_integration_connection(url, options = {}, &block)
|
|
36
|
+
Faraday.new(url, options, &block)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Configure RSpec for integration tests
|
|
42
|
+
RSpec.configure do |config|
|
|
43
|
+
# Include integration helpers in integration tests
|
|
44
|
+
config.include Faraday::IntegrationHelpers, type: :integration
|
|
45
|
+
|
|
46
|
+
# Tag all integration tests for easy filtering
|
|
47
|
+
# Run with: bundle exec rspec --tag integration
|
|
48
|
+
# Skip with: bundle exec rspec --tag ~integration
|
|
49
|
+
config.define_derived_metadata(file_path: %r{/spec/integration/}) do |metadata|
|
|
50
|
+
metadata[:type] = :integration
|
|
51
|
+
metadata[:integration] = true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Integration tests may take longer than unit tests
|
|
55
|
+
config.around(:each, type: :integration) do |example|
|
|
56
|
+
# Completely disable WebMock for integration tests
|
|
57
|
+
# (WebMock can interfere with streaming even when "allowed")
|
|
58
|
+
WebMock.disable!
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
# Set a reasonable timeout for integration tests (30 seconds)
|
|
62
|
+
Timeout.timeout(30) do
|
|
63
|
+
example.run
|
|
64
|
+
end
|
|
65
|
+
ensure
|
|
66
|
+
# Re-enable WebMock for unit tests
|
|
67
|
+
WebMock.enable!
|
|
68
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: faraday
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.15.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "@technoweenie"
|
|
@@ -20,7 +20,7 @@ dependencies:
|
|
|
20
20
|
version: '2.0'
|
|
21
21
|
- - "<"
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version: '3.
|
|
23
|
+
version: '3.6'
|
|
24
24
|
type: :runtime
|
|
25
25
|
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -30,7 +30,7 @@ dependencies:
|
|
|
30
30
|
version: '2.0'
|
|
31
31
|
- - "<"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '3.
|
|
33
|
+
version: '3.6'
|
|
34
34
|
- !ruby/object:Gem::Dependency
|
|
35
35
|
name: json
|
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -104,37 +104,13 @@ files:
|
|
|
104
104
|
- lib/faraday/utils/params_hash.rb
|
|
105
105
|
- lib/faraday/version.rb
|
|
106
106
|
- spec/external_adapters/faraday_specs_setup.rb
|
|
107
|
-
- spec/faraday/adapter/test_spec.rb
|
|
108
|
-
- spec/faraday/adapter_registry_spec.rb
|
|
109
|
-
- spec/faraday/adapter_spec.rb
|
|
110
|
-
- spec/faraday/connection_spec.rb
|
|
111
|
-
- spec/faraday/error_spec.rb
|
|
112
|
-
- spec/faraday/middleware_registry_spec.rb
|
|
113
|
-
- spec/faraday/middleware_spec.rb
|
|
114
|
-
- spec/faraday/options/env_spec.rb
|
|
115
|
-
- spec/faraday/options/options_spec.rb
|
|
116
|
-
- spec/faraday/options/proxy_options_spec.rb
|
|
117
|
-
- spec/faraday/options/request_options_spec.rb
|
|
118
|
-
- spec/faraday/params_encoders/flat_spec.rb
|
|
119
|
-
- spec/faraday/params_encoders/nested_spec.rb
|
|
120
|
-
- spec/faraday/rack_builder_spec.rb
|
|
121
|
-
- spec/faraday/request/authorization_spec.rb
|
|
122
|
-
- spec/faraday/request/instrumentation_spec.rb
|
|
123
|
-
- spec/faraday/request/json_spec.rb
|
|
124
|
-
- spec/faraday/request/url_encoded_spec.rb
|
|
125
|
-
- spec/faraday/request_spec.rb
|
|
126
|
-
- spec/faraday/response/json_spec.rb
|
|
127
|
-
- spec/faraday/response/logger_spec.rb
|
|
128
|
-
- spec/faraday/response/raise_error_spec.rb
|
|
129
|
-
- spec/faraday/response_spec.rb
|
|
130
|
-
- spec/faraday/utils/headers_spec.rb
|
|
131
|
-
- spec/faraday/utils_spec.rb
|
|
132
|
-
- spec/faraday_spec.rb
|
|
133
|
-
- spec/spec_helper.rb
|
|
134
107
|
- spec/support/disabling_stub.rb
|
|
135
108
|
- spec/support/fake_safe_buffer.rb
|
|
136
109
|
- spec/support/faraday_middleware_subclasses.rb
|
|
137
110
|
- spec/support/helper_methods.rb
|
|
111
|
+
- spec/support/integration/test_pki.rb
|
|
112
|
+
- spec/support/integration/tls_server.rb
|
|
113
|
+
- spec/support/integration_helper.rb
|
|
138
114
|
- spec/support/shared_examples/adapter.rb
|
|
139
115
|
- spec/support/shared_examples/params_encoder.rb
|
|
140
116
|
- spec/support/shared_examples/request_method.rb
|
|
@@ -144,7 +120,7 @@ licenses:
|
|
|
144
120
|
- MIT
|
|
145
121
|
metadata:
|
|
146
122
|
homepage_uri: https://lostisland.github.io/faraday
|
|
147
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.
|
|
123
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.15.1
|
|
148
124
|
source_code_uri: https://github.com/lostisland/faraday
|
|
149
125
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
|
150
126
|
rubygems_mfa_required: 'true'
|
|
@@ -1,460 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Faraday::Adapter::Test do
|
|
4
|
-
let(:stubs) do
|
|
5
|
-
described_class::Stubs.new do |stub|
|
|
6
|
-
stub.get('http://domain.test/hello') do
|
|
7
|
-
[200, { 'Content-Type' => 'text/html' }, 'domain: hello']
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
stub.get('http://wrong.test/hello') do
|
|
11
|
-
[200, { 'Content-Type' => 'text/html' }, 'wrong: hello']
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
stub.get('http://wrong.test/bait') do
|
|
15
|
-
[404, { 'Content-Type' => 'text/html' }]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
stub.get('/hello') do
|
|
19
|
-
[200, { 'Content-Type' => 'text/html' }, 'hello']
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
stub.get('/method-echo') do |env|
|
|
23
|
-
[200, { 'Content-Type' => 'text/html' }, env[:method].to_s]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
stub.get(%r{\A/resources/\d+(?:\?|\z)}) do
|
|
27
|
-
[200, { 'Content-Type' => 'text/html' }, 'show']
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
stub.get(%r{\A/resources/(specified)\z}) do |_env, meta|
|
|
31
|
-
[200, { 'Content-Type' => 'text/html' }, "show #{meta[:match_data][1]}"]
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
let(:connection) do
|
|
37
|
-
Faraday.new do |builder|
|
|
38
|
-
builder.adapter :test, stubs
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
let(:response) { connection.get('/hello') }
|
|
43
|
-
|
|
44
|
-
context 'with simple path sets status' do
|
|
45
|
-
subject { response.status }
|
|
46
|
-
|
|
47
|
-
it { is_expected.to eq 200 }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context 'with simple path sets headers' do
|
|
51
|
-
subject { response.headers['Content-Type'] }
|
|
52
|
-
|
|
53
|
-
it { is_expected.to eq 'text/html' }
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context 'with simple path sets body' do
|
|
57
|
-
subject { response.body }
|
|
58
|
-
|
|
59
|
-
it { is_expected.to eq 'hello' }
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
context 'with host points to the right stub' do
|
|
63
|
-
subject { connection.get('http://domain.test/hello').body }
|
|
64
|
-
|
|
65
|
-
it { is_expected.to eq 'domain: hello' }
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe 'can be called several times' do
|
|
69
|
-
subject { connection.get('/hello').body }
|
|
70
|
-
|
|
71
|
-
it { is_expected.to eq 'hello' }
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe 'can handle regular expression path' do
|
|
75
|
-
subject { connection.get('/resources/1').body }
|
|
76
|
-
|
|
77
|
-
it { is_expected.to eq 'show' }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe 'can handle single parameter block' do
|
|
81
|
-
subject { connection.get('/method-echo').body }
|
|
82
|
-
|
|
83
|
-
it { is_expected.to eq 'get' }
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe 'can handle regular expression path with captured result' do
|
|
87
|
-
subject { connection.get('/resources/specified').body }
|
|
88
|
-
|
|
89
|
-
it { is_expected.to eq 'show specified' }
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context 'with get params' do
|
|
93
|
-
subject { connection.get('/param?a=1').body }
|
|
94
|
-
|
|
95
|
-
before do
|
|
96
|
-
stubs.get('/param?a=1') { [200, {}, 'a'] }
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it { is_expected.to eq 'a' }
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe 'ignoring unspecified get params' do
|
|
103
|
-
before do
|
|
104
|
-
stubs.get('/optional?a=1') { [200, {}, 'a'] }
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context 'with multiple params' do
|
|
108
|
-
subject { connection.get('/optional?a=1&b=1').body }
|
|
109
|
-
|
|
110
|
-
it { is_expected.to eq 'a' }
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context 'with single param' do
|
|
114
|
-
subject { connection.get('/optional?a=1').body }
|
|
115
|
-
|
|
116
|
-
it { is_expected.to eq 'a' }
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context 'without params' do
|
|
120
|
-
subject(:request) { connection.get('/optional') }
|
|
121
|
-
|
|
122
|
-
it do
|
|
123
|
-
expect { request }.to raise_error(
|
|
124
|
-
Faraday::Adapter::Test::Stubs::NotFound
|
|
125
|
-
)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context 'with http headers' do
|
|
131
|
-
before do
|
|
132
|
-
stubs.get('/yo', 'X-HELLO' => 'hello') { [200, {}, 'a'] }
|
|
133
|
-
stubs.get('/yo') { [200, {}, 'b'] }
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
context 'with header' do
|
|
137
|
-
subject do
|
|
138
|
-
connection.get('/yo') { |env| env.headers['X-HELLO'] = 'hello' }.body
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it { is_expected.to eq 'a' }
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context 'without header' do
|
|
145
|
-
subject do
|
|
146
|
-
connection.get('/yo').body
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it { is_expected.to eq 'b' }
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
describe 'different outcomes for the same request' do
|
|
154
|
-
def make_request
|
|
155
|
-
connection.get('/foo')
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
subject(:request) { make_request.body }
|
|
159
|
-
|
|
160
|
-
before do
|
|
161
|
-
stubs.get('/foo') { [200, { 'Content-Type' => 'text/html' }, 'hello'] }
|
|
162
|
-
stubs.get('/foo') { [200, { 'Content-Type' => 'text/html' }, 'world'] }
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
context 'the first request' do
|
|
166
|
-
it { is_expected.to eq 'hello' }
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context 'the second request' do
|
|
170
|
-
before do
|
|
171
|
-
make_request
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
it { is_expected.to eq 'world' }
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
describe 'yielding env to stubs' do
|
|
179
|
-
subject { connection.get('http://foo.com/foo?a=1').body }
|
|
180
|
-
|
|
181
|
-
before do
|
|
182
|
-
stubs.get '/foo' do |env|
|
|
183
|
-
expect(env[:url].path).to eq '/foo'
|
|
184
|
-
expect(env[:url].host).to eq 'foo.com'
|
|
185
|
-
expect(env[:params]['a']).to eq '1'
|
|
186
|
-
expect(env[:request_headers]['Accept']).to eq 'text/plain'
|
|
187
|
-
[200, {}, 'a']
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
connection.headers['Accept'] = 'text/plain'
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it { is_expected.to eq 'a' }
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
describe 'params parsing' do
|
|
197
|
-
subject { connection.get('http://foo.com/foo?a[b]=1').body }
|
|
198
|
-
|
|
199
|
-
context 'with default encoder' do
|
|
200
|
-
before do
|
|
201
|
-
stubs.get '/foo' do |env|
|
|
202
|
-
expect(env[:params]['a']['b']).to eq '1'
|
|
203
|
-
[200, {}, 'a']
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it { is_expected.to eq 'a' }
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
context 'with nested encoder' do
|
|
211
|
-
before do
|
|
212
|
-
stubs.get '/foo' do |env|
|
|
213
|
-
expect(env[:params]['a']['b']).to eq '1'
|
|
214
|
-
[200, {}, 'a']
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
connection.options.params_encoder = Faraday::NestedParamsEncoder
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
it { is_expected.to eq 'a' }
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
context 'with flat encoder' do
|
|
224
|
-
before do
|
|
225
|
-
stubs.get '/foo' do |env|
|
|
226
|
-
expect(env[:params]['a[b]']).to eq '1'
|
|
227
|
-
[200, {}, 'a']
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
connection.options.params_encoder = Faraday::FlatParamsEncoder
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it { is_expected.to eq 'a' }
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
describe 'raising an error if no stub was found' do
|
|
238
|
-
describe 'for request' do
|
|
239
|
-
subject(:request) { connection.get('/invalid') { [200, {}, []] } }
|
|
240
|
-
|
|
241
|
-
it { expect { request }.to raise_error described_class::Stubs::NotFound }
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
describe 'for specified host' do
|
|
245
|
-
subject(:request) { connection.get('http://domain.test/bait') }
|
|
246
|
-
|
|
247
|
-
it { expect { request }.to raise_error described_class::Stubs::NotFound }
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
describe 'for request without specified header' do
|
|
251
|
-
subject(:request) { connection.get('/yo') }
|
|
252
|
-
|
|
253
|
-
before do
|
|
254
|
-
stubs.get('/yo', 'X-HELLO' => 'hello') { [200, {}, 'a'] }
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
it { expect { request }.to raise_error described_class::Stubs::NotFound }
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
describe 'for request with non default params encoder' do
|
|
262
|
-
let(:connection) do
|
|
263
|
-
Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) do |builder|
|
|
264
|
-
builder.adapter :test, stubs
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
let(:stubs) do
|
|
268
|
-
described_class::Stubs.new do |stubs|
|
|
269
|
-
stubs.get('/path?a=x&a=y&a=z') { [200, {}, 'a'] }
|
|
270
|
-
end
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
context 'when all flat param values are correctly set' do
|
|
274
|
-
subject(:request) { connection.get('/path?a=x&a=y&a=z') }
|
|
275
|
-
|
|
276
|
-
it { expect(request.status).to eq 200 }
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
shared_examples 'raise NotFound when params do not satisfy the flat param values' do |params|
|
|
280
|
-
subject(:request) { connection.get('/path', params) }
|
|
281
|
-
|
|
282
|
-
context "with #{params.inspect}" do
|
|
283
|
-
it { expect { request }.to raise_error described_class::Stubs::NotFound }
|
|
284
|
-
end
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { a: %w[x] }
|
|
288
|
-
it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { a: %w[x y] }
|
|
289
|
-
it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { a: %w[x z y] } # NOTE: The order of the value is also compared.
|
|
290
|
-
it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { b: %w[x y z] }
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
describe 'strict_mode' do
|
|
294
|
-
let(:stubs) do
|
|
295
|
-
described_class::Stubs.new(strict_mode: true) do |stubs|
|
|
296
|
-
stubs.get('/strict?a=12&b=xy', 'Authorization' => 'Bearer m_ck', 'X-C' => 'hello') { [200, {}, 'a'] }
|
|
297
|
-
stubs.get('/with_user_agent?a=12&b=xy', authorization: 'Bearer m_ck', 'User-Agent' => 'My Agent') { [200, {}, 'a'] }
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
context 'when params and headers are exactly set' do
|
|
302
|
-
subject(:request) { connection.get('/strict', { a: '12', b: 'xy' }, { authorization: 'Bearer m_ck', x_c: 'hello' }) }
|
|
303
|
-
|
|
304
|
-
it { expect(request.status).to eq 200 }
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
context 'when params and headers are exactly set with a custom user agent' do
|
|
308
|
-
subject(:request) { connection.get('/with_user_agent', { a: '12', b: 'xy' }, { authorization: 'Bearer m_ck', 'User-Agent' => 'My Agent' }) }
|
|
309
|
-
|
|
310
|
-
it { expect(request.status).to eq 200 }
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
shared_examples 'raise NotFound when params do not satisfy the strict check' do |params|
|
|
314
|
-
subject(:request) { connection.get('/strict', params, { 'Authorization' => 'Bearer m_ck', 'X-C' => 'hello' }) }
|
|
315
|
-
|
|
316
|
-
context "with #{params.inspect}" do
|
|
317
|
-
it { expect { request }.to raise_error described_class::Stubs::NotFound }
|
|
318
|
-
end
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '12' }
|
|
322
|
-
it_behaves_like 'raise NotFound when params do not satisfy the strict check', { b: 'xy' }
|
|
323
|
-
it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '123', b: 'xy' }
|
|
324
|
-
it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '12', b: 'xyz' }
|
|
325
|
-
it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '12', b: 'xy', c: 'hello' }
|
|
326
|
-
it_behaves_like 'raise NotFound when params do not satisfy the strict check', { additional: 'special', a: '12', b: 'xy', c: 'hello' }
|
|
327
|
-
|
|
328
|
-
shared_examples 'raise NotFound when headers do not satisfy the strict check' do |path, headers|
|
|
329
|
-
subject(:request) { connection.get(path, { a: 12, b: 'xy' }, headers) }
|
|
330
|
-
|
|
331
|
-
context "with #{headers.inspect}" do
|
|
332
|
-
it { expect { request }.to raise_error described_class::Stubs::NotFound }
|
|
333
|
-
end
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck' }
|
|
337
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { 'X-C' => 'hello' }
|
|
338
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'Hi' }
|
|
339
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Basic m_ck', 'x-c': 'hello' }
|
|
340
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello', x_special: 'special' }
|
|
341
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck' }
|
|
342
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'Unknown' }
|
|
343
|
-
it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'My Agent', x_special: 'special' }
|
|
344
|
-
|
|
345
|
-
context 'when strict_mode is disabled' do
|
|
346
|
-
before do
|
|
347
|
-
stubs.strict_mode = false
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
shared_examples 'does not raise NotFound even when params do not satisfy the strict check' do |params|
|
|
351
|
-
subject(:request) { connection.get('/strict', params, { 'Authorization' => 'Bearer m_ck', 'X-C' => 'hello' }) }
|
|
352
|
-
|
|
353
|
-
context "with #{params.inspect}" do
|
|
354
|
-
it { expect(request.status).to eq 200 }
|
|
355
|
-
end
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
it_behaves_like 'does not raise NotFound even when params do not satisfy the strict check', { a: '12', b: 'xy' }
|
|
359
|
-
it_behaves_like 'does not raise NotFound even when params do not satisfy the strict check', { a: '12', b: 'xy', c: 'hello' }
|
|
360
|
-
it_behaves_like 'does not raise NotFound even when params do not satisfy the strict check', { additional: 'special', a: '12', b: 'xy', c: 'hello' }
|
|
361
|
-
|
|
362
|
-
shared_examples 'does not raise NotFound even when headers do not satisfy the strict check' do |path, headers|
|
|
363
|
-
subject(:request) { connection.get(path, { a: 12, b: 'xy' }, headers) }
|
|
364
|
-
|
|
365
|
-
context "with #{headers.inspect}" do
|
|
366
|
-
it { expect(request.status).to eq 200 }
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello' }
|
|
371
|
-
it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello', x_special: 'special' }
|
|
372
|
-
it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello', user_agent: 'Special Agent' }
|
|
373
|
-
it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'My Agent' }
|
|
374
|
-
it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'My Agent', x_special: 'special' }
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
describe 'body_match?' do
|
|
378
|
-
let(:stubs) do
|
|
379
|
-
described_class::Stubs.new do |stubs|
|
|
380
|
-
stubs.post('/no_check') { [200, {}, 'ok'] }
|
|
381
|
-
stubs.post('/with_string', 'abc') { [200, {}, 'ok'] }
|
|
382
|
-
stubs.post(
|
|
383
|
-
'/with_proc',
|
|
384
|
-
->(request_body) { JSON.parse(request_body, symbolize_names: true) == { x: '!', a: [{ m: [{ a: true }], n: 123 }] } },
|
|
385
|
-
{ content_type: 'application/json' }
|
|
386
|
-
) do
|
|
387
|
-
[200, {}, 'ok']
|
|
388
|
-
end
|
|
389
|
-
end
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
context 'when trying without any args for body' do
|
|
393
|
-
subject(:without_body) { connection.post('/no_check') }
|
|
394
|
-
|
|
395
|
-
it { expect(without_body.status).to eq 200 }
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
context 'when trying with string body stubs' do
|
|
399
|
-
subject(:with_string) { connection.post('/with_string', 'abc') }
|
|
400
|
-
|
|
401
|
-
it { expect(with_string.status).to eq 200 }
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
context 'when trying with proc body stubs' do
|
|
405
|
-
subject(:with_proc) do
|
|
406
|
-
connection.post('/with_proc', JSON.dump(a: [{ n: 123, m: [{ a: true }] }], x: '!'), { 'Content-Type' => 'application/json' })
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
it { expect(with_proc.status).to eq 200 }
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
describe 'request timeout' do
|
|
415
|
-
subject(:request) do
|
|
416
|
-
connection.get('/sleep') do |req|
|
|
417
|
-
req.options.timeout = timeout
|
|
418
|
-
end
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
before do
|
|
422
|
-
stubs.get('/sleep') do
|
|
423
|
-
sleep(0.01)
|
|
424
|
-
[200, {}, '']
|
|
425
|
-
end
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
context 'when request is within timeout' do
|
|
429
|
-
let(:timeout) { 1 }
|
|
430
|
-
|
|
431
|
-
it { expect(request.status).to eq 200 }
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
context 'when request is too slow' do
|
|
435
|
-
let(:timeout) { 0.001 }
|
|
436
|
-
|
|
437
|
-
it 'raises an exception' do
|
|
438
|
-
expect { request }.to raise_error(Faraday::TimeoutError)
|
|
439
|
-
end
|
|
440
|
-
end
|
|
441
|
-
end
|
|
442
|
-
|
|
443
|
-
describe '#clear' do
|
|
444
|
-
it 'removes pending stubs' do
|
|
445
|
-
stubs.clear
|
|
446
|
-
expect { connection.get('/hello') }.to raise_error(described_class::Stubs::NotFound)
|
|
447
|
-
end
|
|
448
|
-
|
|
449
|
-
it 'removes already consumed stubs' do
|
|
450
|
-
expect(connection.get('/hello').body).to eq('hello')
|
|
451
|
-
stubs.clear
|
|
452
|
-
expect { connection.get('/hello') }.to raise_error(described_class::Stubs::NotFound)
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
it 'leaves the stubs empty' do
|
|
456
|
-
stubs.clear
|
|
457
|
-
expect(stubs).to be_empty
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Faraday::AdapterRegistry do
|
|
4
|
-
describe '#initialize' do
|
|
5
|
-
subject(:registry) { described_class.new }
|
|
6
|
-
|
|
7
|
-
it { expect { registry.get(:FinFangFoom) }.to raise_error(NameError) }
|
|
8
|
-
it { expect { registry.get('FinFangFoom') }.to raise_error(NameError) }
|
|
9
|
-
|
|
10
|
-
it 'looks up class by string name' do
|
|
11
|
-
expect(registry.get('Faraday::Connection')).to eq(Faraday::Connection)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'looks up class by symbol name' do
|
|
15
|
-
expect(registry.get(:Faraday)).to eq(Faraday)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'caches lookups with implicit name' do
|
|
19
|
-
registry.set :symbol
|
|
20
|
-
expect(registry.get('symbol')).to eq(:symbol)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'caches lookups with explicit name' do
|
|
24
|
-
registry.set 'string', :name
|
|
25
|
-
expect(registry.get(:name)).to eq('string')
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Faraday::Adapter do
|
|
4
|
-
let(:adapter) { Faraday::Adapter.new }
|
|
5
|
-
let(:request) { {} }
|
|
6
|
-
|
|
7
|
-
context '#request_timeout' do
|
|
8
|
-
it 'gets :read timeout' do
|
|
9
|
-
expect(timeout(:read)).to eq(nil)
|
|
10
|
-
|
|
11
|
-
request[:timeout] = 5
|
|
12
|
-
request[:write_timeout] = 1
|
|
13
|
-
|
|
14
|
-
expect(timeout(:read)).to eq(5)
|
|
15
|
-
|
|
16
|
-
request[:read_timeout] = 2
|
|
17
|
-
|
|
18
|
-
expect(timeout(:read)).to eq(2)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'gets :open timeout' do
|
|
22
|
-
expect(timeout(:open)).to eq(nil)
|
|
23
|
-
|
|
24
|
-
request[:timeout] = 5
|
|
25
|
-
request[:write_timeout] = 1
|
|
26
|
-
|
|
27
|
-
expect(timeout(:open)).to eq(5)
|
|
28
|
-
|
|
29
|
-
request[:open_timeout] = 2
|
|
30
|
-
|
|
31
|
-
expect(timeout(:open)).to eq(2)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'gets :write timeout' do
|
|
35
|
-
expect(timeout(:write)).to eq(nil)
|
|
36
|
-
|
|
37
|
-
request[:timeout] = 5
|
|
38
|
-
request[:read_timeout] = 1
|
|
39
|
-
|
|
40
|
-
expect(timeout(:write)).to eq(5)
|
|
41
|
-
|
|
42
|
-
request[:write_timeout] = 2
|
|
43
|
-
|
|
44
|
-
expect(timeout(:write)).to eq(2)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'attempts unknown timeout type' do
|
|
48
|
-
expect { timeout(:unknown) }.to raise_error(ArgumentError)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def timeout(type)
|
|
52
|
-
adapter.send(:request_timeout, type, request)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|