diff options
Diffstat (limited to 'test/rubygems/test_gem_commands_setup_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_setup_command.rb | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index dd688a4421..8eedb6c03a 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -8,7 +8,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase if File.exist?(bundler_gemspec) BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1] else - BUNDLER_VERS = "2.0.1".freeze + BUNDLER_VERS = "2.0.1" end def setup @@ -18,7 +18,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.options[:document] = [] filelist = %w[ - bin/gem + exe/gem lib/rubygems.rb lib/rubygems/requirement.rb lib/rubygems/ssl_certs/rubygems.org/foo.pem @@ -31,17 +31,14 @@ class TestGemCommandsSetupCommand < Gem::TestCase bundler/lib/bundler/man/gemfile.5 bundler/lib/bundler/man/gemfile.5.ronn bundler/lib/bundler/templates/.circleci/config.yml - bundler/lib/bundler/templates/.travis.yml ] create_dummy_files(filelist) - gemspec = Gem::Specification.new - gemspec.author = "Us" - gemspec.name = "bundler" - gemspec.version = BUNDLER_VERS - gemspec.bindir = "exe" - gemspec.executables = ["bundle", "bundler"] + gemspec = util_spec "bundler", BUNDLER_VERS do |s| + s.bindir = "exe" + s.executables = ["bundle", "bundler"] + end File.open "bundler/bundler.gemspec", "w" do |io| io.puts gemspec.to_ruby @@ -69,7 +66,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.execute - assert_match %r{\A#!}, File.read(gem_bin_path) + assert_match(/\A#!/, File.read(gem_bin_path)) end def test_execute_no_regenerate_binstubs @@ -92,7 +89,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.execute - assert_match %r{\Arequire}, File.read(gem_plugin_path) + assert_match(/\Arequire/, File.read(gem_plugin_path)) end def test_execute_no_regenerate_plugins @@ -115,7 +112,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.execute - assert_match %r{\Arequire}, File.read(gem_plugin_path) + assert_match(/\Arequire/, File.read(gem_plugin_path)) end def test_execute_informs_about_installed_executables @@ -140,13 +137,13 @@ class TestGemCommandsSetupCommand < Gem::TestCase @cmd.options[:env_shebang] = true @cmd.execute - ruby_exec = sprintf Gem.default_exec_format, "ruby" + ruby_exec = format Gem.default_exec_format, "ruby" - bin_env = win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " " - assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_gem_bin_path) - assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_bundle_bin_path) - assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(default_bundler_bin_path) - assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_bin_path) + bin_env = Gem.win_platform? ? "" : %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } + " " + assert_match(/\A#!\s*#{bin_env}#{ruby_exec}/, File.read(default_gem_bin_path)) + assert_match(/\A#!\s*#{bin_env}#{ruby_exec}/, File.read(default_bundle_bin_path)) + assert_match(/\A#!\s*#{bin_env}#{ruby_exec}/, File.read(default_bundler_bin_path)) + assert_match(/\A#!\s*#{bin_env}#{ruby_exec}/, File.read(gem_bin_path)) end def test_destdir_flag_does_not_try_to_write_to_the_default_gem_home @@ -162,6 +159,23 @@ class TestGemCommandsSetupCommand < Gem::TestCase end end + def test_destdir_flag_regenerates_binstubs + # install to destdir + destdir = File.join(@tempdir, "foo") + gem_bin_path = gem_install "destdir-only-gem", install_dir: destdir + + # change binstub manually + write_file gem_bin_path do |io| + io.puts "I changed it!" + end + + @cmd.options[:destdir] = destdir + @cmd.options[:prefix] = "/" + @cmd.execute + + assert_match(/\A#!/, File.read(gem_bin_path)) + end + def test_files_in assert_equal %w[rubygems.rb rubygems/requirement.rb rubygems/ssl_certs/rubygems.org/foo.pem], @cmd.files_in("lib").sort @@ -180,7 +194,6 @@ class TestGemCommandsSetupCommand < Gem::TestCase assert_path_exist File.join(dir, "bundler/b.rb") assert_path_exist File.join(dir, "bundler/templates/.circleci/config.yml") - assert_path_exist File.join(dir, "bundler/templates/.travis.yml") end end @@ -416,7 +429,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase end end - def gem_install(name) + def gem_install(name, **options) gem = util_spec name do |s| s.executables = [name] s.files = %W[bin/#{name}] @@ -424,8 +437,8 @@ class TestGemCommandsSetupCommand < Gem::TestCase write_file File.join @tempdir, "bin", name do |f| f.puts "#!/usr/bin/ruby" end - install_gem gem - File.join @gemhome, "bin", name + install_gem gem, **options + File.join options[:install_dir] || @gemhome, "bin", name end def gem_install_with_plugin(name) @@ -433,7 +446,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase s.files = %W[lib/rubygems_plugin.rb] end write_file File.join @tempdir, "lib", "rubygems_plugin.rb" do |f| - f.puts "require '#{gem.plugins.first}'" + f.puts "# do nothing" end install_gem gem |