diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-27 10:05:04 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-27 10:05:04 +0000 |
commit | 85d461456c154d7b4a72b20369e0d65d7880ce02 (patch) | |
tree | 21e1be2c786c8040a426841768e046fb4dc365b1 /test/rubygems/test_gem_commands_build_command.rb | |
parent | 3a83ba90c35833bab757998def36cfe872dec461 (diff) | |
download | ruby-85d461456c154d7b4a72b20369e0d65d7880ce02.tar.gz |
Merge master branch from rubygems upstream.
* It's preparation to release RubyGems 3.0.0.beta2 and Ruby 2.6.0
preview 3.
* https://github.com/rubygems/rubygems/compare/v3.0.0.beta1...fad2eb15a282b19dfcb4b48bc95b8b39ebb4511f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_commands_build_command.rb')
-rw-r--r-- | test/rubygems/test_gem_commands_build_command.rb | 95 |
1 files changed, 84 insertions, 11 deletions
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 19ca03bb70..8048f3e8f5 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -9,13 +9,35 @@ class TestGemCommandsBuildCommand < Gem::TestCase def setup super + readme_file = File.join(@tempdir, 'README.md') + + File.open readme_file, 'w' do |f| + f.write 'My awesome gem' + end + @gem = util_spec 'some_gem' do |s| s.rubyforge_project = 'example' + s.license = 'AGPL-3.0' + s.files = ['README.md'] end @cmd = Gem::Commands::BuildCommand.new end + def test_handle_options + @cmd.handle_options %w[--force --strict] + + assert @cmd.options[:force] + assert @cmd.options[:strict] + end + + def test_handle_options_defaults + @cmd.handle_options [] + + refute @cmd.options[:force] + refute @cmd.options[:strict] + end + def test_execute gemspec_file = File.join(@tempdir, @gem.spec_name) @@ -23,7 +45,55 @@ class TestGemCommandsBuildCommand < Gem::TestCase gs.write @gem.to_ruby end - util_test_build_gem @gem, gemspec_file + @cmd.options[:args] = [gemspec_file] + + util_test_build_gem @gem + end + + def test_execute_strict_without_warnings + gemspec_file = File.join(@tempdir, @gem.spec_name) + + File.open gemspec_file, 'w' do |gs| + gs.write @gem.to_ruby + end + + @cmd.options[:strict] = true + @cmd.options[:args] = [gemspec_file] + + util_test_build_gem @gem + end + + def test_execute_strict_with_warnings + bad_gem = util_spec 'some_bad_gem' do |s| + s.rubyforge_project = 'example' + s.files = ['README.md'] + end + + gemspec_file = File.join(@tempdir, bad_gem.spec_name) + + File.open gemspec_file, 'w' do |gs| + gs.write bad_gem.to_ruby + end + + @cmd.options[:args] = [gemspec_file] + @cmd.options[:strict] = true + + use_ui @ui do + Dir.chdir @tempdir do + assert_raises Gem::InvalidSpecificationException do + @cmd.execute + end + end + end + + error = @ui.error.split "\n" + assert_equal "WARNING: licenses is empty, but is recommended. Use a license identifier from", error.shift + assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.", error.shift + assert_equal "WARNING: See http://guides.rubygems.org/specification-reference/ for help", error.shift + assert_equal [], error + + gem_file = File.join @tempdir, File.basename(@gem.cache_file) + refute File.exist?(gem_file) end def test_execute_bad_spec @@ -67,9 +137,14 @@ class TestGemCommandsBuildCommand < Gem::TestCase def test_execute_outside_dir gemspec_dir = File.join @tempdir, 'build_command_gem' gemspec_file = File.join gemspec_dir, @gem.spec_name + readme_file = File.join gemspec_dir, 'README.md' FileUtils.mkdir_p gemspec_dir + File.open readme_file, 'w' do |f| + f.write "My awesome gem" + end + File.open gemspec_file, 'w' do |gs| gs.write @gem.to_ruby end @@ -103,12 +178,12 @@ class TestGemCommandsBuildCommand < Gem::TestCase gs.write @gem.to_ruby end - util_test_build_gem @gem, gemspec_file - end - - def util_test_build_gem(gem, gemspec_file, check_licenses=true) @cmd.options[:args] = [gemspec_file] + util_test_build_gem @gem + end + + def util_test_build_gem(gem) use_ui @ui do Dir.chdir @tempdir do @cmd.execute @@ -122,10 +197,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase assert_equal " File: some_gem-2.gem", output.shift assert_equal [], output - if check_licenses - assert_match "WARNING: licenses is empty", @ui.error - end - gem_file = File.join @tempdir, File.basename(gem.cache_file) assert File.exist?(gem_file) @@ -147,7 +218,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase @cmd.options[:args] = [gemspec_file] @cmd.options[:force] = true - util_test_build_gem @gem, gemspec_file, false + util_test_build_gem @gem end CERT_FILE = cert_path 'public3072' @@ -169,7 +240,9 @@ class TestGemCommandsBuildCommand < Gem::TestCase gs.write spec.to_ruby end - util_test_build_gem spec, gemspec_file + @cmd.options[:args] = [gemspec_file] + + util_test_build_gem spec trust_dir.trust_cert OpenSSL::X509::Certificate.new(File.read(CERT_FILE)) |