[rubygems/rubygems] Use shorthand hash syntax for bundle add

https://github.com/rubygems/rubygems/commit/9691097036
This commit is contained in:
Sean Collins 2025-03-03 15:12:53 -07:00 committed by Hiroshi SHIBATA
parent afbc6649cd
commit 8acf0d7bcc
Notes: git 2025-03-10 03:44:00 +00:00
2 changed files with 28 additions and 28 deletions

View File

@ -108,17 +108,17 @@ module Bundler
end end
if d.groups != Array(:default) if d.groups != Array(:default)
group = d.groups.size == 1 ? ", :group => #{d.groups.first.inspect}" : ", :groups => #{d.groups.inspect}" group = d.groups.size == 1 ? ", group: #{d.groups.first.inspect}" : ", groups: #{d.groups.inspect}"
end end
source = ", :source => \"#{d.source}\"" unless d.source.nil? source = ", source: \"#{d.source}\"" unless d.source.nil?
path = ", :path => \"#{d.path}\"" unless d.path.nil? path = ", path: \"#{d.path}\"" unless d.path.nil?
git = ", :git => \"#{d.git}\"" unless d.git.nil? git = ", git: \"#{d.git}\"" unless d.git.nil?
github = ", :github => \"#{d.github}\"" unless d.github.nil? github = ", github: \"#{d.github}\"" unless d.github.nil?
branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil? branch = ", branch: \"#{d.branch}\"" unless d.branch.nil?
ref = ", :ref => \"#{d.ref}\"" unless d.ref.nil? ref = ", ref: \"#{d.ref}\"" unless d.ref.nil?
glob = ", :glob => \"#{d.glob}\"" unless d.glob.nil? glob = ", glob: \"#{d.glob}\"" unless d.glob.nil?
require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil? require_path = ", require: #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil?
%(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{glob}#{require_path}) %(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{glob}#{require_path})
end.join("\n") end.join("\n")

View File

@ -88,25 +88,25 @@ RSpec.describe "bundle add" do
describe "with --require" do describe "with --require" do
it "adds the require param for the gem" do it "adds the require param for the gem" do
bundle "add 'foo' --require=foo/engine" bundle "add 'foo' --require=foo/engine"
expect(bundled_app_gemfile.read).to match(%r{gem "foo",(?: .*,) :require => "foo\/engine"}) expect(bundled_app_gemfile.read).to match(%r{gem "foo",(?: .*,) require: "foo\/engine"})
end end
it "converts false to a boolean" do it "converts false to a boolean" do
bundle "add 'foo' --require=false" bundle "add 'foo' --require=false"
expect(bundled_app_gemfile.read).to match(/gem "foo",(?: .*,) :require => false/) expect(bundled_app_gemfile.read).to match(/gem "foo",(?: .*,) require: false/)
end end
end end
describe "with --group" do describe "with --group" do
it "adds dependency for the specified group" do it "adds dependency for the specified group" do
bundle "add 'foo' --group='development'" bundle "add 'foo' --group='development'"
expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :group => :development/) expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", group: :development/)
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
it "adds dependency to more than one group" do it "adds dependency to more than one group" do
bundle "add 'foo' --group='development, test'" bundle "add 'foo' --group='development, test'"
expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :groups => \[:development, :test\]/) expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", groups: \[:development, :test\]/)
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -115,7 +115,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified source" do it "adds dependency with specified source" do
bundle "add 'foo' --source='https://gem.repo2'" bundle "add 'foo' --source='https://gem.repo2'"
expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", :source => "https://gem.repo2"}) expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", source: "https://gem.repo2"})
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -124,7 +124,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified path" do it "adds dependency with specified path" do
bundle "add 'foo' --path='#{lib_path("foo-2.0")}'" bundle "add 'foo' --path='#{lib_path("foo-2.0")}'"
expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :path => "#{lib_path("foo-2.0")}"/) expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", path: "#{lib_path("foo-2.0")}"/)
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -133,7 +133,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified git source" do it "adds dependency with specified git source" do
bundle "add foo --git=#{lib_path("foo-2.0")}" bundle "add foo --git=#{lib_path("foo-2.0")}"
expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/) expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", git: "#{lib_path("foo-2.0")}"/)
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -146,7 +146,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified git source and branch" do it "adds dependency with specified git source and branch" do
bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test" bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test"
expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/) expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", git: "#{lib_path("foo-2.0")}", branch: "test"/)
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -155,7 +155,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified git source and branch" do it "adds dependency with specified git source and branch" do
bundle "add foo --git=#{lib_path("foo-2.0")} --ref=#{revision_for(lib_path("foo-2.0"))}" bundle "add foo --git=#{lib_path("foo-2.0")} --ref=#{revision_for(lib_path("foo-2.0"))}"
expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2\.0", :git => "#{lib_path("foo-2.0")}", :ref => "#{revision_for(lib_path("foo-2.0"))}"/) expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2\.0", git: "#{lib_path("foo-2.0")}", ref: "#{revision_for(lib_path("foo-2.0"))}"/)
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -164,7 +164,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified github source" do it "adds dependency with specified github source" do
bundle "add rake --github=ruby/rake" bundle "add rake --github=ruby/rake"
expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake"}) expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", github: "ruby\/rake"})
end end
end end
@ -172,7 +172,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified github source and branch" do it "adds dependency with specified github source and branch" do
bundle "add rake --github=ruby/rake --branch=master" bundle "add rake --github=ruby/rake --branch=master"
expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :branch => "master"}) expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", github: "ruby\/rake", branch: "master"})
end end
end end
@ -180,7 +180,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified github source and ref" do it "adds dependency with specified github source and ref" do
bundle "add rake --github=ruby/rake --ref=5c60da8" bundle "add rake --github=ruby/rake --ref=5c60da8"
expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :ref => "5c60da8"}) expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", github: "ruby\/rake", ref: "5c60da8"})
end end
end end
@ -188,7 +188,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified git source" do it "adds dependency with specified git source" do
bundle "add foo --git=#{lib_path("foo-2.0")} --glob='./*.gemspec'" bundle "add foo --git=#{lib_path("foo-2.0")} --glob='./*.gemspec'"
expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :glob => "\./\*\.gemspec"}) expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", git: "#{lib_path("foo-2.0")}", glob: "\./\*\.gemspec"})
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -201,7 +201,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified git source and branch" do it "adds dependency with specified git source and branch" do
bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test --glob='./*.gemspec'" bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test --glob='./*.gemspec'"
expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test", :glob => "\./\*\.gemspec"}) expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2.0", git: "#{lib_path("foo-2.0")}", branch: "test", glob: "\./\*\.gemspec"})
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -210,7 +210,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified git source and branch" do it "adds dependency with specified git source and branch" do
bundle "add foo --git=#{lib_path("foo-2.0")} --ref=#{revision_for(lib_path("foo-2.0"))} --glob='./*.gemspec'" bundle "add foo --git=#{lib_path("foo-2.0")} --ref=#{revision_for(lib_path("foo-2.0"))} --glob='./*.gemspec'"
expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2\.0", :git => "#{lib_path("foo-2.0")}", :ref => "#{revision_for(lib_path("foo-2.0"))}", :glob => "\./\*\.gemspec"}) expect(bundled_app_gemfile.read).to match(%r{gem "foo", "~> 2\.0", git: "#{lib_path("foo-2.0")}", ref: "#{revision_for(lib_path("foo-2.0"))}", glob: "\./\*\.gemspec"})
expect(the_bundle).to include_gems "foo 2.0" expect(the_bundle).to include_gems "foo 2.0"
end end
end end
@ -219,7 +219,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified github source" do it "adds dependency with specified github source" do
bundle "add rake --github=ruby/rake --glob='./*.gemspec'" bundle "add rake --github=ruby/rake --glob='./*.gemspec'"
expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :glob => "\.\/\*\.gemspec"}) expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", github: "ruby\/rake", glob: "\.\/\*\.gemspec"})
end end
end end
@ -227,7 +227,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified github source and branch" do it "adds dependency with specified github source and branch" do
bundle "add rake --github=ruby/rake --branch=master --glob='./*.gemspec'" bundle "add rake --github=ruby/rake --branch=master --glob='./*.gemspec'"
expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :branch => "master", :glob => "\.\/\*\.gemspec"}) expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", github: "ruby\/rake", branch: "master", glob: "\.\/\*\.gemspec"})
end end
end end
@ -235,7 +235,7 @@ RSpec.describe "bundle add" do
it "adds dependency with specified github source and ref" do it "adds dependency with specified github source and ref" do
bundle "add rake --github=ruby/rake --ref=5c60da8 --glob='./*.gemspec'" bundle "add rake --github=ruby/rake --ref=5c60da8 --glob='./*.gemspec'"
expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", :github => "ruby\/rake", :ref => "5c60da8", :glob => "\.\/\*\.gemspec"}) expect(bundled_app_gemfile.read).to match(%r{gem "rake", "~> 13\.\d+", github: "ruby\/rake", ref: "5c60da8", glob: "\.\/\*\.gemspec"})
end end
end end
@ -250,7 +250,7 @@ RSpec.describe "bundle add" do
it "using combination of short form options works like long form" do it "using combination of short form options works like long form" do
bundle "add 'foo' -s='https://gem.repo2' -g='development' -v='~>1.0'" bundle "add 'foo' -s='https://gem.repo2' -g='development' -v='~>1.0'"
expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "https://gem.repo2") expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 1.0", group: :development, source: "https://gem.repo2")
expect(the_bundle).to include_gems "foo 1.1" expect(the_bundle).to include_gems "foo 1.1"
end end