Skip to content

Update Object#stub to call the block passed to the stub - #171

Closed
rwstauner wants to merge 1 commit into
ruby:masterfrom
rwstauner:stub-with-block
Closed

rwstauner wants to merge 1 commit into
ruby:masterfrom
rwstauner:stub-with-block

Conversation

@rwstauner

@rwstauner rwstauner commented Nov 24, 2026 •

Copy link
Copy Markdown

This matches the behavior of the version used in the rubygems helper (the one referenced in the comment when defining conditionally).

Without this if the ruby/ruby test suite loads this definition first it will cause some rubygems tests to fail.

Example:

# Running tests:

[ 8271/39515] TestGemInstaller#test_install_holds_lock_
  1) Error:
TestGemInstaller#test_install_holds_lock_while_replacing_gem_files:
NoMethodError: undefined method 'call' for nil
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_installer.rb:1588:in 'block in TestGemInstaller#test_install_holds_lock_while_replacing_gem_files'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/resolv/test_dns.rb:23:in 'block in Gem.stub'
    /Users/rwstauner/src/github.com/ruby/vm-lock/lib/rubygems/installer.rb:285:in 'Gem::Installer#install'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_installer.rb:1596:in 'block (3 levels) in TestGemInstaller#test_install_holds_lock_while_replacing_gem_files'
    /Users/rwstauner/src/github.com/ruby/vm-lock/lib/rubygems/user_interaction.rb:45:in 'Gem::DefaultUserInteraction.use_ui'
    /Users/rwstauner/src/github.com/ruby/vm-lock/lib/rubygems/user_interaction.rb:68:in 'Gem::DefaultUserInteraction#use_ui'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_installer.rb:1596:in 'block (2 levels) in TestGemInstaller#test_install_holds_lock_while_replacing_gem_files'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/resolv/test_dns.rb:29:in 'Object#stub'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_installer.rb:1595:in 'block in TestGemInstaller#test_install_holds_lock_while_replacing_gem_files'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/helper.rb:1522:in 'Gem::TestCase#build_rake_in'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_installer.rb:1594:in 'TestGemInstaller#test_install_holds_lock_while_replacing_gem_files'

[16216/39515] TestGemCoreExtTCPSocketInit#test_initiali
  2) Error:
TestGemCoreExtTCPSocketInit#test_initialize_forwards_socket_arguments:
NoMethodError: undefined method 'call' for nil
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_core_ext_tcpsocket_init.rb:50:in 'block in TestGemCoreExtTCPSocketIni
t#with_resolved_address'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/resolv/test_dns.rb:23:in 'block in Addrinfo.stub'
    /Users/rwstauner/src/github.com/ruby/vm-lock/lib/rubygems/core_ext/tcpsocket_init.rb:21:in 'CoreExtensions::TCPSocketExt::Initializer#initialize'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_core_ext_tcpsocket_init.rb:23:in 'block in TestGemCoreExtTCPSocketInit#test_initialize_forwards_socket_arguments'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_core_ext_tcpsocket_init.rb:52:in 'block (2 levels) in TestGemCoreExtTCPSocketInit#with_resolved_address'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/resolv/test_dns.rb:29:in 'Object#stub'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_core_ext_tcpsocket_init.rb:51:in 'block in TestGemCoreExtTCPSocketInit#with_resolved_address'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/resolv/test_dns.rb:29:in 'Object#stub'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_core_ext_tcpsocket_init.rb:50:in 'TestGemCoreExtTCPSocketInit#with_resolved_address'
    /Users/rwstauner/src/github.com/ruby/vm-lock/test/rubygems/test_gem_core_ext_tcpsocket_init.rb:22:in 'TestGemCoreExtTCPSocketInit#test_initialize_forwards_socket_arguments'

This matches the behavior of the version used in the rubygems helper
(the one referenced in the comment when defining conditionally).

Without this if the ruby/ruby test suite loads this definition first
it will cause some rubygems tests to fail.
@rwstauner

Copy link
Copy Markdown
Author

looks like an duplicate/alternate for #170

@rwstauner rwstauner closed this Nov 24, 2026
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.

1 participant