Skip to content

Commit f2c856c

Browse files
committed
Add support for Faraday 2.x.
1 parent e446423 commit f2c856c

File tree

13 files changed

+59
-46
lines changed

13 files changed

+59
-46
lines changed

.github/workflows/test.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ jobs:
99
matrix:
1010
entry:
1111
- { ruby: '3.2' }
12-
- { ruby: '2.7', faraday: '0.9.0' }
13-
- { ruby: '2.7', faraday: '0.17.0' }
14-
- { ruby: '2.7', faraday: '~> 1.0' }
15-
- { ruby: 'jruby-9.3' }
12+
- { ruby: '2.7' }
1613
- { ruby: 'ruby-head', allowed-failure: true }
1714
- { ruby: 'jruby-head', allowed-failure: true }
18-
name: test (${{ matrix.entry.ruby }}, ${{ matrix.entry.faraday || 'default' }})
19-
env:
20-
FARADAY_VERSION: ${{ matrix.entry.faraday }}
15+
name: test (${{ matrix.entry.ruby }})
2116
steps:
2217
- uses: actions/checkout@v3
2318
- uses: ruby/setup-ruby@v1

.rubocop_todo.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-02-16 15:23:43 UTC using RuboCop version 1.45.1.
3+
# on 2024-02-01 15:09:00 UTC using RuboCop version 1.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -35,16 +35,17 @@ Lint/RedundantSafeNavigation:
3535
Exclude:
3636
- 'lib/hyperclient/link.rb'
3737

38-
# Offense count: 2
38+
# Offense count: 3
3939
# This cop supports unsafe autocorrection (--autocorrect-all).
4040
# Configuration parameters: EnforcedStyle.
4141
# SupportedStyles: nested, compact
4242
Style/ClassAndModuleChildren:
4343
Exclude:
4444
- 'features/steps/api_navigation.rb'
4545
- 'features/steps/default_config.rb'
46+
- 'features/support/env.rb'
4647

47-
# Offense count: 4
48+
# Offense count: 5
4849
# Configuration parameters: AllowedConstants.
4950
Style/Documentation:
5051
Exclude:
@@ -53,4 +54,5 @@ Style/Documentation:
5354
- 'features/steps/api_navigation.rb'
5455
- 'features/steps/default_config.rb'
5556
- 'features/support/api.rb'
57+
- 'features/support/env.rb'
5658
- 'features/support/fixtures.rb'

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
## Changelog
22

3-
### 1.1.0 (Next)
3+
### 2.0.0 (Next)
44

55
* [#268](https://github.com/codegram/hyperclient/pull/268): Replace Travis-CI with GHA - [@dblock](https://github.com/dblock).
66
* [#269](https://github.com/codegram/hyperclient/pull/269): Re-add code coverage - [@dblock](https://github.com/dblock).
77
* [#270](https://github.com/codegram/hyperclient/pull/270): Upgrade Rubocop to 1.45 - [@dblock](https://github.com/dblock).
88
* [#271](https://github.com/codegram/hyperclient/pull/271): Test against Ruby 3.2 - [@dblock](https://github.com/dblock).
9+
* [#285](https://github.com/codegram/hyperclient/pull/285): Support Faraday 2.x - [@dblock](https://github.com/dblock).
910
* Your contribution here.
1011

1112
### 1.0.1 (2021/01/02)

Gemfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
source 'https://rubygems.org'
22

3-
gem 'faraday', ENV['FARADAY_VERSION'] if ENV['FARADAY_VERSION'] && !ENV['FARADAY_VERSION'].empty?
4-
53
gemspec
64

75
group :development do
@@ -25,6 +23,7 @@ end
2523
group :test do
2624
gem 'danger-changelog', '~> 0.6.0'
2725
gem 'danger-toc', '~> 0.2.0'
26+
gem 'faraday-follow_redirects'
2827
gem 'minitest'
2928
gem 'mocha'
3029
gem 'rack-test'

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Hyperclient constructs a connection using typical [Faraday](http://github.com/lo
5050
```ruby
5151
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
5252
client.connection do |conn|
53-
conn.use Faraday::Request::OAuth
53+
conn.use Faraday::Request::Instrumentation
5454
end
5555
end
5656
```
@@ -60,7 +60,7 @@ You can pass options to the Faraday connection block in the `connection` block:
6060
```ruby
6161
api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
6262
client.connection(ssl: { verify: false }) do |conn|
63-
conn.use Faraday::Request::OAuth
63+
conn.use Faraday::Request::Instrumentation
6464
end
6565
end
6666
```

features/steps/api_navigation.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
4343
end
4444

4545
step 'I should be able to access it\'s title and body' do
46-
@post._attributes.title.wont_equal nil
47-
@post._attributes.body.wont_equal nil
46+
assert_kind_of String, @post._attributes.title
47+
assert_kind_of String, @post._attributes.body
4848
end
4949

5050
step 'I should also be able to access it\'s embedded comments' do
5151
comment = @post._embedded.comments.first
52-
comment._attributes.title.wont_equal nil
52+
assert_kind_of String, comment._attributes.title
5353
end
5454

5555
step 'I should be able to navigate to next page' do

features/steps/default_config.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Spinach::Features::DefaultConfig < Spinach::FeatureSteps
2525
end
2626

2727
step 'it should have been parsed as JSON' do
28-
@posts._attributes.total_posts.to_i.must_equal 4
29-
@posts._attributes['total_posts'].to_i.must_equal 4
28+
assert_equal 4, @posts._attributes.total_posts.to_i
29+
assert_equal 4, @posts._attributes['total_posts'].to_i
3030
end
3131
end

features/support/env.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
require 'minitest/spec'
1+
require 'minitest'
22
require 'webmock'
33
WebMock.enable!
44
require 'hyperclient'
5+
6+
Minitest::Spec.new nil if defined?(Minitest::Spec)
7+
Spinach.config[:failure_exceptions] << Minitest::Assertion
8+
9+
class Spinach::FeatureSteps
10+
include Minitest::Assertions
11+
attr_accessor :assertions
12+
13+
def initialize(*args)
14+
super(*args)
15+
self.assertions = 0
16+
end
17+
end

hyperclient.gemspec

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Gem::Specification.new do |gem|
1313
gem.version = Hyperclient::VERSION
1414

1515
gem.add_dependency 'addressable'
16-
gem.add_dependency 'faraday', '>= 0.9.0'
17-
gem.add_dependency 'faraday_hal_middleware'
18-
gem.add_dependency 'faraday_middleware'
16+
gem.add_dependency 'faraday', '>= 2'
17+
gem.add_dependency 'faraday_hal_middleware', '>= 0.2'
1918
gem.metadata['rubygems_mfa_required'] = 'true'
2019
end

lib/hyperclient/entry_point.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'faraday_middleware'
1+
require 'faraday/follow_redirects'
22
require 'faraday_hal_middleware'
33

44
module Hyperclient
@@ -20,7 +20,7 @@ def message
2020
#
2121
# client = Hyperclient::EntryPoint.new('http://my.api.org') do |entry_point|
2222
# entry_point.connection do |conn|
23-
# conn.use Faraday::Request::OAuth
23+
# conn.use Faraday::Request::Instrumentation
2424
# end
2525
# entry_point.headers['Access-Token'] = 'token'
2626
# end
@@ -138,7 +138,7 @@ def faraday_block=(value)
138138
def default_faraday_block
139139
lambda do |connection, &block|
140140
connection.use Faraday::Response::RaiseError
141-
connection.use FaradayMiddleware::FollowRedirects
141+
connection.use Faraday::FollowRedirects::Middleware
142142
connection.request :hal_json
143143
connection.response :hal_json, content_type: /\bjson$/
144144

test/hyperclient/entry_point_test.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ module Hyperclient
2626

2727
it 'can insert additional middleware after a connection has been constructed' do
2828
_(entry_point.connection).must_be_kind_of Faraday::Connection
29-
entry_point.connection.use :instrumentation
29+
entry_point.connection.use Faraday::Request::Instrumentation
3030
handlers = entry_point.connection.builder.handlers
31-
_(handlers).must_include FaradayMiddleware::Instrumentation
31+
_(handlers).must_include Faraday::Request::Instrumentation
3232
end
3333

3434
it 'creates a Faraday connection with the default block' do
3535
handlers = entry_point.connection.builder.handlers
3636

3737
_(handlers).must_include Faraday::Response::RaiseError
38-
_(handlers).must_include FaradayMiddleware::FollowRedirects
39-
_(handlers).must_include FaradayMiddleware::EncodeHalJson
40-
_(handlers).must_include FaradayMiddleware::ParseHalJson
38+
_(handlers).must_include Faraday::FollowRedirects::Middleware
39+
_(handlers).must_include Faraday::HalJson::Request
40+
_(handlers).must_include Faraday::HalJson::Response
4141

4242
_(entry_point.connection.options.params_encoder).must_equal Faraday::FlatParamsEncoder
4343
end
@@ -137,9 +137,9 @@ module Hyperclient
137137
it 'creates a Faraday connection with the default block' do
138138
handlers = entry_point.connection.builder.handlers
139139
_(handlers).wont_include Faraday::Response::RaiseError
140-
_(handlers).wont_include FaradayMiddleware::FollowRedirects
141-
_(handlers).must_include FaradayMiddleware::EncodeJson
142-
_(handlers).must_include FaradayMiddleware::ParseJson
140+
_(handlers).wont_include Faraday::FollowRedirects
141+
_(handlers).must_include Faraday::Request::Json
142+
_(handlers).must_include Faraday::Response::Json
143143
end
144144
end
145145
end
@@ -148,7 +148,7 @@ module Hyperclient
148148
let(:entry_point) do
149149
EntryPoint.new 'http://my.api.org' do |entry_point|
150150
entry_point.connection do |conn|
151-
conn.use Faraday::Request::OAuth
151+
conn.use Faraday::Request::Instrumentation
152152
end
153153
entry_point.headers['Access-Token'] = 'token'
154154
end
@@ -168,11 +168,11 @@ module Hyperclient
168168
it 'creates a Faraday connection with the default block plus any additional handlers' do
169169
handlers = entry_point.connection.builder.handlers
170170

171-
_(handlers).must_include Faraday::Request::OAuth
171+
_(handlers).must_include Faraday::Request::Instrumentation
172172
_(handlers).must_include Faraday::Response::RaiseError
173-
_(handlers).must_include FaradayMiddleware::FollowRedirects
174-
_(handlers).must_include FaradayMiddleware::EncodeHalJson
175-
_(handlers).must_include FaradayMiddleware::ParseHalJson
173+
_(handlers).must_include Faraday::FollowRedirects::Middleware
174+
_(handlers).must_include Faraday::HalJson::Request
175+
_(handlers).must_include Faraday::HalJson::Response
176176

177177
_(entry_point.connection.options.params_encoder).must_equal Faraday::FlatParamsEncoder
178178
end

test/hyperclient_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
let(:client) do
1414
Hyperclient.new('http://api.example.org') do |client|
1515
client.connection(default: true) do |conn|
16-
conn.use Faraday::Request::OAuth
16+
conn.use Faraday::Request::Instrumentation
1717
end
1818
client.headers['Access-Token'] = 'token'
1919
end
@@ -31,11 +31,11 @@
3131

3232
it 'creates a Faraday connection with the default block plus any additional handlers' do
3333
handlers = client.connection.builder.handlers
34-
_(handlers).must_include Faraday::Request::OAuth
34+
_(handlers).must_include Faraday::Request::Instrumentation
3535
_(handlers).must_include Faraday::Response::RaiseError
36-
_(handlers).must_include FaradayMiddleware::FollowRedirects
37-
_(handlers).must_include FaradayMiddleware::EncodeHalJson
38-
_(handlers).must_include FaradayMiddleware::ParseHalJson
36+
_(handlers).must_include Faraday::FollowRedirects::Middleware
37+
_(handlers).must_include Faraday::HalJson::Request
38+
_(handlers).must_include Faraday::HalJson::Response
3939
end
4040
end
4141
end

test/test_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717

1818
require 'minitest/autorun'
1919
require 'minitest/pride'
20+
require 'minitest/unit'
2021
require 'mocha/minitest'
2122
require 'json'
2223

23-
MiniTest::Test.class_eval do
24+
require 'faraday'
25+
require 'faraday/request/instrumentation'
26+
27+
MiniTest::Assertions.class_eval do
2428
def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block)
2529
adapter_handler = conn.builder.handlers.find { |h| h.klass < Faraday::Adapter }
2630
if adapter_handler

0 commit comments

Comments
 (0)