In Rails (some versions at least), nil responds to `:load` (via ActiveSupport::Dependencies::Loadable mixin).
Enable default json decoder to work in this case
This PR fixes the following test failure using Ruby 3.3.0dev:
```console
$ ruby -v
ruby 3.3.0dev (2023-08-14T15:48:39Z master 52837fcec2) [x86_64-darwin22]
$ bundle exec rspec spec/faraday_spec.rb
Randomized with seed 57031
Faraday
has a version number
proxies to default_connection
uses method_missing on Faraday if there is no proxyable method (FAILED - 1)
proxies methods that exist on the default_connection
proxied methods can be accessed
Failures:
1) Faraday proxies to default_connection uses method_missing on Faraday if there is no proxyable method
Failure/Error:
expect { Faraday.this_method_does_not_exist }.to raise_error(
NoMethodError, expected_message
)
expected NoMethodError with "undefined method `this_method_does_not_exist' for Faraday:Module",
got #<NoMethodError: undefined method `this_method_does_not_exist' for module Faraday> with backtrace:
# ./lib/faraday.rb:147:in `method_missing'
# ./spec/faraday_spec.rb:27:in `block (4 levels) in <top (required)>'
# ./spec/faraday_spec.rb:27:in `block (3 levels) in <top (required)>'
# ./spec/faraday_spec.rb:27:in `block (3 levels) in <top (required)>'
```
That error message has been changed by https://github.com/ruby/ruby/commit/e7b8d32e in Ruby 3.3.0dev.
cf. https://bugs.ruby-lang.org/issues/18285
So the test error message is changed:
Ruby 3.2 or lower:
```
undefined method `this_method_does_not_exist' for Faraday:Module
```
Ruby 3.3.0dev:
```
NoMethodError: undefined method `this_method_does_not_exist' for module Faraday
```
Previously, `Faraday::Request::Json` doesn't encode the value `false`
while it encodes `true` to `"true"`.
This patch fixes the inconsistent behavior to make the middleware encode
`false` to `"false"`.
Utils.URI can be configured to use a different parser and return an object that "behaves like a URI". However, `opaque` is not available in other objects (e.g. Addressable::URI), so in this instance we need to use URI.
Fixes#1484
Previously, the Faraday testing adapter compared the request body to the
stubbed body just by calling `#==` if the stubbed body is present.
Sometimes, I want to check the equality between request and stubbed body
in more advanced ways. For example, there is a case that I want to check
only the parts of the body are actually passed to Faraday instance like
this:
```ruby
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
stub.post('/foo', '{"name:"YK","created_at":"ANY STRING IS OK"}') { [200, {}, ''] }
end
connection.post('/foo', JSON.dump(name: 'YK', created_at: Time.now))
stubs.verify_stubbed_calls
```
In this case, it's difficult to make tests always pass with
`"created_at"` because the value is dynamic. So, I came up with an idea
to pass a proc as a stubbed value and compare bodies, inside the proc:
```ruby
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
check = -> (request_body) { JSON.parse(request_body).slice('name') == { 'name' => 'YK' } }
stub.post('/foo', check) { [200, {}, ''] }
end
connection.post('/foo', JSON.dump(name: 'YK', created_at: Time.now))
stubs.verify_stubbed_calls
```
I believe this would be flexible but compatible with the previous behavior.