diff options
author | bronzdoc <lsagastume1990@gmail.com> | 2019-08-18 14:57:41 -0600 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-09-05 18:42:56 +0900 |
commit | a02da1012bb391ae01affac7454ea28996fd7dbf (patch) | |
tree | 87315c1f855573e776e92c039eae3ac328bd2f7a | |
parent | bcf51dd76332bc28ee75494c51828a36774ff99f (diff) | |
download | ruby-a02da1012bb391ae01affac7454ea28996fd7dbf.tar.gz |
[rubygems/rubygems] Build the first gemspec we found if no gemspec is specified
https://github.com/rubygems/rubygems/commit/ab186266b7
-rw-r--r-- | lib/rubygems/commands/build_command.rb | 10 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_build_command.rb | 39 |
2 files changed, 48 insertions, 1 deletions
diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index bc37ab9a94..69203d3ebc 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -57,11 +57,19 @@ Gems can be saved to a specified filename with the output option: end def execute - build_gem + build_gem(gem_name) end private + def gem_name + get_one_optional_argument || find_gemspecs.first + end + + def find_gemspecs + Dir.glob("*.gemspec").sort + end + def build_gem(gem_name = get_one_optional_argument) gemspec = File.exist?(gem_name) ? gem_name : "#{gem_name}.gemspec" diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index 6d44d48c13..3edd7d4e4b 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -242,6 +242,45 @@ class TestGemCommandsBuildCommand < Gem::TestCase util_test_build_gem @gem end + def test_execute_without_gem_name + some_gem = util_spec "some_gem" do |s| + s.license = "AGPL-3.0" + s.files = ["README.md"] + end + + gemspec_dir = File.join(@tempdir, "build_command_gem") + gemspec_file = File.join(gemspec_dir, some_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(some_gem.to_ruby) + end + + @cmd.options[:args] = [] + + use_ui @ui do + Dir.chdir(gemspec_dir) 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 + + some_gem = File.join(gemspec_dir, File.basename(some_gem.cache_file)) + assert File.exist?(some_gem) + end + def util_test_build_gem(gem) use_ui @ui do Dir.chdir @tempdir do |