ruby-changes:57547
From: bronzdoc <ko1@a...>
Date: Thu, 5 Sep 2019 19:20:02 +0900 (JST)
Subject: [ruby-changes:57547] a02da1012b (master): [rubygems/rubygems] Build the first gemspec we found if no gemspec is specified
https://git.ruby-lang.org/ruby.git/commit/?id=a02da1012b From a02da1012bb391ae01affac7454ea28996fd7dbf Mon Sep 17 00:00:00 2001 From: bronzdoc <lsagastume1990@g...> Date: Sun, 18 Aug 2019 14:57:41 -0600 Subject: [rubygems/rubygems] Build the first gemspec we found if no gemspec is specified https://github.com/rubygems/rubygems/commit/ab186266b7 diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index bc37ab9..69203d3 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: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/build_command.rb#L57 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 6d44d48..3edd7d4 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_build_command.rb#L242 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/