Skip to content

Resolve net-http adapter deprecation Ruby 3.4#1081

Merged
koic merged 1 commit into
bblimke:masterfrom
Earlopain:net-http-adapter-ruby-3.4
Feb 6, 2025
Merged

Resolve net-http adapter deprecation Ruby 3.4#1081
koic merged 1 commit into
bblimke:masterfrom
Earlopain:net-http-adapter-ruby-3.4

Conversation

@Earlopain

@Earlopain Earlopain commented Nov 16, 2024

Copy link
Copy Markdown
Contributor

Closes #1088

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
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
Contributor Author

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

@Uaitt

Uaitt commented Dec 27, 2024

Copy link
Copy Markdown

Hello 😃,
any update about this?

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

@koic

koic commented Jan 14, 2025

Copy link
Copy Markdown
Collaborator

@bblimke Thank you for your maintenance efforts. Ruby 3.4.1 has been released. Could you release this at your convenience?

@simi

simi commented Feb 2, 2025

Copy link
Copy Markdown

🙏 for release, change looks good and was successfully tested with rubygems.org codebase.

@koic koic merged commit 2b963cb into bblimke:master Feb 6, 2025
@koic

koic commented Feb 6, 2025

Copy link
Copy Markdown
Collaborator

WebMock 3.25.0 has been released. Thank you.

@gstokkink

Copy link
Copy Markdown

@koic thanks for taking over maintenance, much appreciated!

JamieMagee added a commit to dependabot/dependabot-core that referenced this pull request Sep 9, 2025
This resolves the deprecation warning

```
warning: constant Net::HTTPSession is deprecated
```

See:
- bblimke/webmock#1088
- bblimke/webmock#1081
- ruby/net-http#189
JamieMagee added a commit to dependabot/dependabot-core that referenced this pull request Sep 9, 2025
This resolves the deprecation warning

```
warning: constant Net::HTTPSession is deprecated
```

See:
- bblimke/webmock#1088
- bblimke/webmock#1081
- ruby/net-http#189
JamieMagee added a commit to dependabot/dependabot-core that referenced this pull request Sep 11, 2025
This resolves the deprecation warning

```
warning: constant Net::HTTPSession is deprecated
```

See:
- bblimke/webmock#1088
- bblimke/webmock#1081
- ruby/net-http#189
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.

warning: constant Net::HTTPSession is deprecated

5 participants