faraday 2.5.2 → 2.9.2

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +29 -17
  4. data/Rakefile +6 -1
  5. data/lib/faraday/adapter/test.rb +20 -7
  6. data/lib/faraday/adapter.rb +2 -3
  7. data/lib/faraday/connection.rb +49 -54
  8. data/lib/faraday/encoders/nested_params_encoder.rb +1 -1
  9. data/lib/faraday/error.rb +17 -3
  10. data/lib/faraday/logging/formatter.rb +27 -15
  11. data/lib/faraday/middleware.rb +3 -0
  12. data/lib/faraday/options/connection_options.rb +7 -6
  13. data/lib/faraday/options/env.rb +68 -63
  14. data/lib/faraday/options/proxy_options.rb +7 -3
  15. data/lib/faraday/options/request_options.rb +7 -6
  16. data/lib/faraday/options/ssl_options.rb +51 -50
  17. data/lib/faraday/options.rb +4 -3
  18. data/lib/faraday/rack_builder.rb +0 -1
  19. data/lib/faraday/request/authorization.rb +8 -3
  20. data/lib/faraday/request/instrumentation.rb +3 -1
  21. data/lib/faraday/request/json.rb +18 -3
  22. data/lib/faraday/request.rb +11 -8
  23. data/lib/faraday/response/json.rb +21 -1
  24. data/lib/faraday/response/logger.rb +4 -0
  25. data/lib/faraday/response/raise_error.rb +24 -5
  26. data/lib/faraday/response.rb +2 -1
  27. data/lib/faraday/utils/headers.rb +14 -3
  28. data/lib/faraday/utils.rb +3 -4
  29. data/lib/faraday/version.rb +1 -1
  30. data/spec/faraday/adapter/test_spec.rb +29 -0
  31. data/spec/faraday/connection_spec.rb +17 -2
  32. data/spec/faraday/error_spec.rb +31 -6
  33. data/spec/faraday/middleware_spec.rb +18 -0
  34. data/spec/faraday/options/options_spec.rb +1 -1
  35. data/spec/faraday/options/proxy_options_spec.rb +8 -0
  36. data/spec/faraday/params_encoders/nested_spec.rb +2 -1
  37. data/spec/faraday/request/authorization_spec.rb +35 -0
  38. data/spec/faraday/request/json_spec.rb +88 -0
  39. data/spec/faraday/response/json_spec.rb +89 -0
  40. data/spec/faraday/response/logger_spec.rb +38 -0
  41. data/spec/faraday/response/raise_error_spec.rb +40 -1
  42. data/spec/faraday/response_spec.rb +3 -1
  43. data/spec/faraday/utils/headers_spec.rb +29 -2
  44. data/spec/faraday_spec.rb +10 -4
  45. data/spec/spec_helper.rb +6 -5
  46. metadata +7 -21
@@ -4,7 +4,7 @@ RSpec.describe Faraday::Response do
4
4
  subject { Faraday::Response.new(env) }
5
5
 
6
6
  let(:env) do
7
- Faraday::Env.from(status: 404, body: 'yikes',
7
+ Faraday::Env.from(status: 404, body: 'yikes', url: Faraday::Utils.URI('https://lostisland.github.io/faraday'),
8
8
  response_headers: { 'Content-Type' => 'text/plain' })
9
9
  end
10
10
 
@@ -30,6 +30,7 @@ RSpec.describe Faraday::Response do
30
30
  it { expect(hash[:status]).to eq(subject.status) }
31
31
  it { expect(hash[:response_headers]).to eq(subject.headers) }
32
32
  it { expect(hash[:body]).to eq(subject.body) }
33
+ it { expect(hash[:url]).to eq(subject.env.url) }
33
34
  end
34
35
 
35
36
  describe 'marshal serialization support' do
@@ -45,6 +46,7 @@ RSpec.describe Faraday::Response do
45
46
  it { expect(loaded.env[:body]).to eq(env[:body]) }
46
47
  it { expect(loaded.env[:response_headers]).to eq(env[:response_headers]) }
47
48
  it { expect(loaded.env[:status]).to eq(env[:status]) }
49
+ it { expect(loaded.env[:url]).to eq(env[:url]) }
48
50
  end
49
51
 
50
52
  describe '#on_complete' do
@@ -56,12 +56,21 @@ RSpec.describe Faraday::Utils::Headers do
56
56
  it { expect(subject.delete('content-type')).to be_nil }
57
57
  end
58
58
 
59
- describe '#parse' do
60
- before { subject.parse(headers) }
59
+ describe '#dig' do
60
+ before { subject['Content-Type'] = 'application/json' }
61
+
62
+ it { expect(subject&.dig('Content-Type')).to eq('application/json') }
63
+ it { expect(subject&.dig('CONTENT-TYPE')).to eq('application/json') }
64
+ it { expect(subject&.dig(:content_type)).to eq('application/json') }
65
+ it { expect(subject&.dig('invalid')).to be_nil }
66
+ end
61
67
 
68
+ describe '#parse' do
62
69
  context 'when response headers leave http status line out' do
63
70
  let(:headers) { "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" }
64
71
 
72
+ before { subject.parse(headers) }
73
+
65
74
  it { expect(subject.keys).to eq(%w[Content-Type]) }
66
75
  it { expect(subject['Content-Type']).to eq('text/html') }
67
76
  it { expect(subject['content-type']).to eq('text/html') }
@@ -70,13 +79,31 @@ RSpec.describe Faraday::Utils::Headers do
70
79
  context 'when response headers values include a colon' do
71
80
  let(:headers) { "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://httpbingo.org/\r\n\r\n" }
72
81
 
82
+ before { subject.parse(headers) }
83
+
73
84
  it { expect(subject['location']).to eq('http://httpbingo.org/') }
74
85
  end
75
86
 
76
87
  context 'when response headers include a blank line' do
77
88
  let(:headers) { "HTTP/1.1 200 OK\r\n\r\nContent-Type: text/html\r\n\r\n" }
78
89
 
90
+ before { subject.parse(headers) }
91
+
79
92
  it { expect(subject['content-type']).to eq('text/html') }
80
93
  end
94
+
95
+ context 'when response headers include already stored keys' do
96
+ let(:headers) { "HTTP/1.1 200 OK\r\nX-Numbers: 123\r\n\r\n" }
97
+
98
+ before do
99
+ h = subject
100
+ h[:x_numbers] = 8
101
+ h.parse(headers)
102
+ end
103
+
104
+ it do
105
+ expect(subject[:x_numbers]).to eq('8, 123')
106
+ end
107
+ end
81
108
  end
82
109
  end
data/spec/faraday_spec.rb CHANGED
@@ -18,10 +18,16 @@ RSpec.describe Faraday do
18
18
  end
19
19
 
20
20
  it 'uses method_missing on Faraday if there is no proxyable method' do
21
- expect { Faraday.this_method_does_not_exist }.to raise_error(
22
- NoMethodError,
23
- "undefined method `this_method_does_not_exist' for Faraday:Module"
24
- )
21
+ expected_message =
22
+ if RUBY_VERSION >= '3.4'
23
+ "undefined method 'this_method_does_not_exist' for module Faraday"
24
+ elsif RUBY_VERSION >= '3.3'
25
+ "undefined method `this_method_does_not_exist' for module Faraday"
26
+ else
27
+ "undefined method `this_method_does_not_exist' for Faraday:Module"
28
+ end
29
+
30
+ expect { Faraday.this_method_does_not_exist }.to raise_error(NoMethodError, expected_message)
25
31
  end
26
32
 
27
33
  it 'proxied methods can be accessed' do
data/spec/spec_helper.rb CHANGED
@@ -29,14 +29,15 @@ SimpleCov.start do
29
29
  minimum_coverage_by_file 26
30
30
  end
31
31
 
32
- # Ensure all /lib files are loaded
33
- # so they will be included in the test coverage report.
34
- Dir['./lib/**/*.rb'].sort.each { |file| require file }
35
-
36
32
  require 'faraday'
37
33
  require 'pry'
38
34
 
39
- Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
35
+ # Ensure all /lib files are loaded
36
+ # so they will be included in the test coverage report.
37
+ Dir['./lib/**/*.rb'].each { |file| require file }
38
+
39
+ # Load all Rspec support files
40
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
40
41
 
41
42
  RSpec.configure do |config|
42
43
  # rspec-expectations config goes here. You can use an alternate
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.5.2
4
+ version: 2.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-08-11 00:00:00.000000000 Z
13
+ date: 2024-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday-net_http
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.0'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '3.1'
24
+ version: '3.2'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,21 +31,7 @@ dependencies:
31
31
  version: '2.0'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '3.1'
35
- - !ruby/object:Gem::Dependency
36
- name: ruby2_keywords
37
- requirement: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 0.0.4
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: 0.0.4
34
+ version: '3.2'
49
35
  description:
50
36
  email: technoweenie@gmail.com
51
37
  executables: []
@@ -131,7 +117,7 @@ licenses:
131
117
  - MIT
132
118
  metadata:
133
119
  homepage_uri: https://lostisland.github.io/faraday
134
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.5.2
120
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.9.2
135
121
  source_code_uri: https://github.com/lostisland/faraday
136
122
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
137
123
  post_install_message:
@@ -143,14 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
129
  requirements:
144
130
  - - ">="
145
131
  - !ruby/object:Gem::Version
146
- version: '2.6'
132
+ version: '3.0'
147
133
  required_rubygems_version: !ruby/object:Gem::Requirement
148
134
  requirements:
149
135
  - - ">="
150
136
  - !ruby/object:Gem::Version
151
137
  version: '0'
152
138
  requirements: []
153
- rubygems_version: 3.1.6
139
+ rubygems_version: 3.5.11
154
140
  signing_key:
155
141
  specification_version: 4
156
142
  summary: HTTP/REST API client library.