[前][次][番号順一覧][スレッド一覧]

ruby-changes:57551

From: bronzdoc <ko1@a...>
Date: Thu, 5 Sep 2019 19:40:02 +0900 (JST)
Subject: [ruby-changes:57551] b11cfed4c4 (master): [rubygems/rubygems] Error out if there are multiple gemspecs and no gemspec is specified

https://git.ruby-lang.org/ruby.git/commit/?id=b11cfed4c4

From b11cfed4c4fae51f7111c6cc0a3ec436a9c8faa3 Mon Sep 17 00:00:00 2001
From: bronzdoc <lsagastume1990@g...>
Date: Wed, 21 Aug 2019 23:35:39 -0600
Subject: [rubygems/rubygems] Error out if there are multiple gemspecs and no
 gemspec is specified

https://github.com/rubygems/rubygems/commit/547947bbf0

diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb
index 69203d3..c7d5fd3 100644
--- a/lib/rubygems/commands/build_command.rb
+++ b/lib/rubygems/commands/build_command.rb
@@ -63,11 +63,18 @@ Gems can be saved to a specified filename with the output option: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/build_command.rb#L63
   private
 
   def gem_name
-    get_one_optional_argument || find_gemspecs.first
+    get_one_optional_argument || find_gemspec
   end
 
-  def find_gemspecs
-    Dir.glob("*.gemspec").sort
+  def find_gemspec
+    gemspecs = Dir.glob("*.gemspec").sort
+
+    if gemspecs.size > 1
+      alert_error "Multiple gemspecs found: #{gemspecs}, please specify one"
+      terminate_interaction(1)
+    end
+
+    gemspecs.first
   end
 
   def build_gem(gem_name = get_one_optional_argument)
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 19575dc..7540a05 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -293,19 +293,18 @@ class TestGemCommandsBuildCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_build_command.rb#L293
 
     use_ui @ui do
       Dir.chdir(gemspec_dir) do
-        @cmd.execute
+        assert_raises Gem::MockGemUi::TermError do
+          @cmd.execute
+        end
       end
     end
 
-    output = @ui.output.split("\n")
-    assert_equal "  Successfully built RubyGem", output.shift
-    assert_equal "  Name: another_gem", output.shift
-    assert_equal "  Version: 2", output.shift
-    assert_equal "  File: another_gem-2.gem", output.shift
-    assert_equal [], output
+    gemspecs = ["another_gem-2.gemspec", "some_gem-2.gemspec"]
+    assert_equal "", @ui.output
+    assert_equal @ui.error, "ERROR:  Multiple gemspecs found: #{gemspecs}, please specify one\n"
 
     expected_gem = File.join(gemspec_dir, File.basename(another_gem.cache_file))
-    assert File.exist?(expected_gem)
+    refute File.exist?(expected_gem)
   end
 
   def util_test_build_gem(gem)
@@ -331,29 +330,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_build_command.rb#L330
     assert_equal "this is a summary", spec.summary
   end
 
-  def util_test_build_gem(gem)
-    use_ui @ui do
-      Dir.chdir @tempdir do
-        @cmd.execute
-      end
-    end
-
-    output = @ui.output.split "\n"
-    assert_equal "  Successfully built RubyGem", output.shift
-    assert_equal "  Name: some_gem", output.shift
-    assert_equal "  Version: 2", output.shift
-    assert_equal "  File: some_gem-2.gem", output.shift
-    assert_equal [], output
-
-    gem_file = File.join @tempdir, File.basename(gem.cache_file)
-    assert File.exist?(gem_file)
-
-    spec = Gem::Package.new(gem_file).spec
-
-    assert_equal "some_gem", spec.name
-    assert_equal "this is a summary", spec.summary
-  end
-
   def test_execute_force
     gemspec_file = File.join(@tempdir, @gem.spec_name)
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]