diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2023-02-12 19:19:17 -0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-02-22 08:42:16 +0000 |
commit | 612ebd10c061fefd6e4f1f736a95188bd6ae5146 (patch) | |
tree | d48c8d2e5d2f85bfc0708d2eebfcc2afa7c530f5 /test | |
parent | 3f0f9a7942a90f4dd6069e6074ea6211fe5d0bc5 (diff) |
[rubygems/rubygems] Ensure dependencies are updated by default when running gem exec
https://github.com/rubygems/rubygems/commit/664f3e1e5f
Diffstat (limited to 'test')
-rw-r--r-- | test/rubygems/test_gem_commands_exec_command.rb | 117 |
1 files changed, 109 insertions, 8 deletions
diff --git a/test/rubygems/test_gem_commands_exec_command.rb b/test/rubygems/test_gem_commands_exec_command.rb index 85cc786a02..f9a37b40fb 100644 --- a/test/rubygems/test_gem_commands_exec_command.rb +++ b/test/rubygems/test_gem_commands_exec_command.rb @@ -12,6 +12,12 @@ class TestGemCommandsExecCommand < Gem::TestCase @orig_args = Gem::Command.build_args common_installer_setup + + @gem_home = Gem.dir + @gem_path = Gem.path + + @installed_specs = [] + Gem.post_install {|installer| @installed_specs << installer.spec } end def teardown @@ -22,6 +28,23 @@ class TestGemCommandsExecCommand < Gem::TestCase Gem::Command.build_args = @orig_args end + def invoke(*args) + @ui.outs.truncate(0) + @ui.outs.rewind + @ui.errs.truncate(0) + @ui.errs.rewind + @installed_specs.clear + + @cmd.invoke *args + ensure + Gem::Specification.unresolved_deps.clear + Gem.loaded_specs.clear + Gem.instance_variable_set(:@activated_gem_paths, 0) + Gem.clear_default_specs + Gem.use_paths(@gem_home, @gem_path) + Gem.refresh + end + def test_error_with_no_arguments e = assert_raise Gem::CommandLineError do @cmd.invoke @@ -414,7 +437,7 @@ class TestGemCommandsExecCommand < Gem::TestCase def test_conservative spec_fetcher do |fetcher| - fetcher.gem "a", 1 do |s| + fetcher.download "a", 1 do |s| s.executables = %w[foo] s.files = %w[bin/foo lib/a.rb] @@ -424,16 +447,13 @@ class TestGemCommandsExecCommand < Gem::TestCase end end - util_clear_gems - use_ui @ui do - @cmd.invoke "--verbose", "--conservative", "a" + invoke "--verbose", "--conservative", "a" assert_include @ui.output, "a (>= 0) not available locally" assert_include @ui.output, "a-1 foo" + assert_equal %w[a-1], @installed_specs.map(&:original_name) end - @ui.outs.truncate(0) - spec_fetcher do |fetcher| fetcher.gem "a", 1 do |s| s.executables = %w[foo] @@ -444,7 +464,7 @@ class TestGemCommandsExecCommand < Gem::TestCase end end - fetcher.gem "a", 2 do |s| + fetcher.download "a", 2 do |s| s.executables = %w[foo] s.files = %w[bin/foo lib/a.rb] @@ -455,9 +475,90 @@ class TestGemCommandsExecCommand < Gem::TestCase end use_ui @ui do - @cmd.invoke "--verbose", "--conservative", "a" + invoke "--verbose", "--conservative", "a" assert_not_include @ui.output, "a (>= 0) not available locally" assert_include @ui.output, "a-1 foo" + assert_empty @installed_specs.map(&:original_name) + end + end + + def test_uses_newest_version + spec_fetcher do |fetcher| + fetcher.download "a", 1 do |s| + s.executables = %w[foo] + s.files = %w[bin/foo lib/a.rb] + + write_file File.join(*%W[gems #{s.original_name} bin foo]) do |f| + f << "Gem.ui.say #{s.original_name.dump} + ' ' + File.basename(__FILE__)" + end + end + end + + use_ui @ui do + invoke "a" + assert_include @ui.output, "a-1 foo" + end + + spec_fetcher do |fetcher| + fetcher.download "a", 1 do |s| + s.executables = %w[foo] + s.files = %w[bin/foo lib/a.rb] + + write_file File.join(*%W[gems #{s.original_name} bin foo]) do |f| + f << "Gem.ui.say #{s.original_name.dump} + ' ' + File.basename(__FILE__)" + end + end + + fetcher.download "a", 2 do |s| + s.executables = %w[foo] + s.files = %w[bin/foo lib/a.rb] + + write_file File.join(*%W[gems #{s.original_name} bin foo]) do |f| + f << "Gem.ui.say #{s.original_name.dump} + ' ' + File.basename(__FILE__)" + end + end + end + + use_ui @ui do + invoke "--verbose", "a:2" + refute_predicate @ui, :terminated? + assert_empty @ui.error + assert_include @ui.output, "a-2 foo" + assert_equal %w[a-2], @installed_specs.map(&:original_name) + end + end + + def test_uses_newest_version_of_dependency + spec_fetcher do |fetcher| + fetcher.gem "a", 1 do |s| + s.executables = %w[] + s.files = %w[lib/a.rb] + s.add_runtime_dependency "b" + end + + fetcher.gem "b", 1 do |s| + s.executables = %w[a] + s.files = %w[bin/a lib/a.rb] + + write_file File.join(*%W[gems #{s.original_name} bin a]) do |f| + f << "Gem.ui.say #{s.original_name.dump} + ' ' + File.basename(__FILE__)" + end + end + + fetcher.download "b", 2 do |s| + s.executables = %w[a] + s.files = %w[bin/a lib/a.rb] + + write_file File.join(*%W[gems #{s.original_name} bin a]) do |f| + f << "Gem.ui.say #{s.original_name.dump} + ' ' + File.basename(__FILE__)" + end + end + end + + use_ui @ui do + invoke "a" + assert_include @ui.output, "b-2 a" + assert_equal %w[b-2], @installed_specs.map(&:original_name) end end end |