Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Faraday warnings #149

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### 0.9.2 (Next)

* [#149](https://github.com/codegram/hyperclient/pull/149): Address Faraday warnings - [@yuki24](https://github.com/yuki24).
* Your contribution here.

### 0.9.1 (2019/08/25)
Expand Down
8 changes: 5 additions & 3 deletions lib/hyperclient/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def connection(options = {}, &block)
block
else
lambda do |conn|
default_faraday_block.call conn
yield conn
default_faraday_block.call(conn, &block)
end
end
else
Expand Down Expand Up @@ -138,11 +137,14 @@ def faraday_block=(value)
#
# Returns a block.
def default_faraday_block
lambda do |connection|
lambda do |connection, &block|
connection.use Faraday::Response::RaiseError
connection.use FaradayMiddleware::FollowRedirects
connection.request :hal_json
connection.response :hal_json, content_type: /\bjson$/

block&.call(connection)

connection.adapter :net_http
connection.options.params_encoder = Faraday::FlatParamsEncoder
end
Expand Down
9 changes: 8 additions & 1 deletion test/hyperclient/entry_point_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ module Hyperclient

it 'can insert additional middleware after a connection has been constructed' do
entry_point.connection.must_be_kind_of Faraday::Connection
entry_point.connection.use :instrumentation

warning = 'WARNING: Unexpected middleware set after the adapter. ' \
"This won't be supported from Faraday 1.0.\n"

assert_output nil, warning do
entry_point.connection.use :instrumentation
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole test will stop working on Faraday >= 1.0. Since this is going to be a breaking change Hyperclient may need to lock the Faraday version to < 1.0.0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean no, we should make the minimum faraday version be 1.0 or test against multiple versions of Faraday and make this conditional.

Copy link
Contributor Author

@yuki24 yuki24 Aug 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just took a stab at it but does not seems like an easy upgrade at least:

Screen Shot 2019-08-25 at 6 27 05 PM

Copy link
Contributor Author

@yuki24 yuki24 Aug 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting a bit off-topic, but just a couple of PRs for Faraday 1.0 and I don't think this is going to be a smooth upgrade:

Even with these branches manually pulled in, I got 25 test failures:

Results of rake test

$ rake test
Run options: --seed 30217

# Running:

.............F.......EE....F.....F....EEEE......EE.........EE....................................EE.......FEE..........EEEEEE...........F.

Fabulous run in 0.082381s, 1675.1435 runs/s, 2597.6864 assertions/s.

  1) Failure:
Hyperclient::EntryPoint::inherited::connection#test_0003_creates a Faraday connection with the default block plus any additional handlers [/Users/yuki/GitHub/hyperclient/test/hyperclient/entry_point_test.rb:185]:
Expected [Faraday::Response::RaiseError, FaradayMiddleware::FollowRedirects, FaradayMiddleware::EncodeHalJson, FaradayMiddleware::ParseHalJson, FaradayMiddleware::OAuth] to include Faraday::Adapter::NetHttp.

  2) Error:
Hyperclient::Link::_head#test_0001_sends a HEAD request with the link url:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:184:in `block (3 levels) in <module:Hyperclient>'

  3) Error:
Hyperclient::Link::_resource#test_0001_builds a resource with the link href representation:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:138:in `block (3 levels) in <module:Hyperclient>'

  4) Failure:
Hyperclient::EntryPoint::default::connection#test_0005_creates a Faraday connection with the default block [/Users/yuki/GitHub/hyperclient/test/hyperclient/entry_point_test.rb:48]:
Expected [Faraday::Response::RaiseError, FaradayMiddleware::FollowRedirects, FaradayMiddleware::EncodeHalJson, FaradayMiddleware::ParseHalJson] to include Faraday::Adapter::NetHttp.

  5) Failure:
Hyperclient::EntryPoint::default::connection#test_0004_can insert additional middleware after a connection has been constructed [/Users/yuki/GitHub/hyperclient/test/hyperclient/entry_point_test.rb:33]:
In stderr.
--- expected
+++ actual
@@ -1,2 +1 @@
-"WARNING: Unexpected middleware set after the adapter. This won't be supported from Faraday 1.0.
-"
+""


  6) Error:
Hyperclient::Link::method_missing::delegation#test_0002_can handle false values in the response:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:289:in `block (4 levels) in <module:Hyperclient>'

  7) Error:
Hyperclient::Link::method_missing::delegation#test_0001_delegates when link key matches:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:278:in `block (4 levels) in <module:Hyperclient>'

  8) Error:
Hyperclient::Link::method_missing::delegation#test_0003_doesn't delegate when link key doesn't match:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:299:in `block (4 levels) in <module:Hyperclient>'

  9) Error:
Hyperclient::Link::method_missing::delegation#test_0004_backtracks when navigating links:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:310:in `block (4 levels) in <module:Hyperclient>'

 10) Error:
Hyperclient::Link::_options#test_0001_sends a OPTIONS request with the link url:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:172:in `block (3 levels) in <module:Hyperclient>'

 11) Error:
Hyperclient::Link::_delete#test_0001_sends a DELETE request with the link url:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:196:in `block (3 levels) in <module:Hyperclient>'

 12) Error:
Hyperclient::Link::_patch#test_0001_sends a PATCH request with the link url and params:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:248:in `block (3 levels) in <module:Hyperclient>'

 13) Error:
Hyperclient::Link::_patch#test_0002_defaults params to an empty hash:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:256:in `block (3 levels) in <module:Hyperclient>'

 14) Error:
Hyperclient::Link::_put#test_0001_sends a PUT request with the link url and params:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:228:in `block (3 levels) in <module:Hyperclient>'

 15) Error:
Hyperclient::Link::_put#test_0002_defaults params to an empty hash:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:236:in `block (3 levels) in <module:Hyperclient>'

 16) Failure:
Hyperclient::new::with an optional block#test_0003_creates a Faraday connection with the default block plus any additional handlers [/Users/yuki/GitHub/hyperclient/test/hyperclient_test.rb:39]:
Expected [Faraday::Response::RaiseError, FaradayMiddleware::FollowRedirects, FaradayMiddleware::EncodeHalJson, FaradayMiddleware::ParseHalJson, FaradayMiddleware::OAuth] to include Faraday::Adapter::NetHttp.

 17) Error:
Hyperclient::Link::get#test_0001_sends a GET request with the link url:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:150:in `block (3 levels) in <module:Hyperclient>'

 18) Error:
Hyperclient::Link::get#test_0002_raises exceptions by default:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:160:in `block (3 levels) in <module:Hyperclient>'

 19) Error:
Hyperclient::Link::_post#test_0001_sends a POST request with the link url and params:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:208:in `block (3 levels) in <module:Hyperclient>'

 20) Error:
Hyperclient::Link::_post#test_0002_defaults params to an empty hash:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:216:in `block (3 levels) in <module:Hyperclient>'

 21) Error:
Hyperclient::Link::method_missing::resource#test_0002_raises an error when the method does not exist in the resource:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:320:in `block (4 levels) in <module:Hyperclient>'

 22) Error:
Hyperclient::Link::method_missing::resource#test_0004_does not delegate to_ary to resource:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:320:in `block (4 levels) in <module:Hyperclient>'

 23) Error:
Hyperclient::Link::method_missing::resource#test_0001_delegates unkown methods to the resource:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:320:in `block (4 levels) in <module:Hyperclient>'

 24) Error:
Hyperclient::Link::method_missing::resource#test_0003_responds to missing methods:
RuntimeError: No such handler: nil
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:243:in `assert_index'
    /Users/yuki/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/faraday-1.0.0.pre.rc1/lib/faraday/rack_builder.rb:135:in `swap'
    /Users/yuki/GitHub/hyperclient/test/test_helper.rb:11:in `stub_request'
    /Users/yuki/GitHub/hyperclient/test/hyperclient/link_test.rb:320:in `block (4 levels) in <module:Hyperclient>'

 25) Failure:
Hyperclient::EntryPoint::custom::connection#test_0003_creates a Faraday connection with the default block [/Users/yuki/GitHub/hyperclient/test/hyperclient/entry_point_test.rb:151]:
Expected [FaradayMiddleware::EncodeJson, FaradayMiddleware::ParseJson] to include Faraday::Adapter::NetHttp.

138 runs, 214 assertions, 5 failures, 20 errors, 0 skips
rake aborted!
Command failed with status (1)

Tasks: TOP => test
(See full trace by running task with --trace)


handlers = entry_point.connection.builder.handlers
handlers.must_include FaradayMiddleware::Instrumentation
end
Expand Down