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

Resolve net-http adapter deprecation Ruby 3.4 #1081

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Nov 16, 2024

This old constant was deprecated in 2001 and now finally removed. ruby/net-http#189

It fixes this error:

/usr/local/bundle/bundler/gems/webmock-9ff63ac7c845/lib/webmock/http_lib_adapters/net_http.rb:25:in 'Module#remove_const': constant Net::HTTPSession not defined (NameError)

        Net.send(:remove_const, :HTTPSession)
           ^^^^^
	from /usr/local/bundle/bundler/gems/webmock-9ff63ac7c845/lib/webmock/http_lib_adapters/net_http.rb:25:in 'WebMock::HttpLibAdapters::NetHttpAdapter.disable!'

You can test it yourself by adding gem 'net-http', github: 'ruby/net-http' to the gemfile here and running tests.

I assume this will be released with 3.4

@Earlopain
Copy link
Contributor Author

Slight gearshift. The constant will be kept for 3.4 but will warn on removal, see https://bugs.ruby-lang.org/issues/20900. I adapted the code to not warn and handle the const removal.

Comment on lines 46 to 52
def self.remove_silently(mod, const) #:nodoc:
begin
# Don't warn on removing the deprecated constant
verbose, $VERBOSE = $VERBOSE, nil
mod.send(:remove_const, const)
ensure
$VERBOSE = verbose
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

My two cents, WebMock supports Ruby 2.5+, the redundant begin should no longer be necessary.
https://github.com/bblimke/webmock/blob/v3.24.0/webmock.gemspec#L24

Suggested change
def self.remove_silently(mod, const) #:nodoc:
begin
# Don't warn on removing the deprecated constant
verbose, $VERBOSE = $VERBOSE, nil
mod.send(:remove_const, const)
ensure
$VERBOSE = verbose
end
end
def self.remove_silently(mod, const) #:nodoc:
# Don't warn on removing the deprecated constant.
verbose, $VERBOSE = $VERBOSE, nil
mod.send(:remove_const, const)
ensure
$VERBOSE = verbose
end

This old constant was deprecated in 2001 and will now be removed in Ruby 3.5

On Ruby 3.4, removing a deprecated constant will warn:

> /home/user/code/webmock/lib/webmock/http_lib_adapters/net_http.rb:55: warning: constant Net::HTTPSession is deprecated

It fixes this error on Ruby 3.5:
```
/usr/local/bundle/bundler/gems/webmock-9ff63ac7c845/lib/webmock/http_lib_adapters/net_http.rb:25:in 'Module#remove_const': constant Net::HTTPSession not defined (NameError)

        Net.send(:remove_const, :HTTPSession)
           ^^^^^
	from /usr/local/bundle/bundler/gems/webmock-9ff63ac7c845/lib/webmock/http_lib_adapters/net_http.rb:25:in 'WebMock::HttpLibAdapters::NetHttpAdapter.disable!'
```
@Earlopain Earlopain force-pushed the net-http-adapter-ruby-3.4 branch from f58b1f8 to 67c0695 Compare November 19, 2024 11:47
@Earlopain Earlopain changed the title Fix net-http adapter for Ruby 3.4 Resolve net-http adapter deprecation Ruby 3.4 Nov 19, 2024
@Earlopain
Copy link
Contributor Author

@bblimke could you check this out? The next Ruby version is only about 2 weeks away now.

@Uaitt
Copy link

Uaitt commented Dec 27, 2024

Hello 😃,
any update about this?

All Rails apps that try to update to Ruby 3.4.1 will see a warning because of this 😅.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants