From 069cce3d4bddb4248ba0e6a1de675cd7c2e3f048 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Mon, 20 Feb 2017 23:00:19 +0530 Subject: [PATCH 1/8] bundle inject can be used with few options --- lib/bundler/cli.rb | 6 +++++- lib/bundler/cli/inject.rb | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 208f21c74b9..80332de3c21 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -465,10 +465,14 @@ def platform end desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile" + method_option "source", :type => :string, :banner => + "Use the specific source for the gem" + method_option "group", :type => :string, :banner => + "Put the gem into specific group" def inject(name, version) SharedHelpers.major_deprecation "The `inject` command has been replaced by the `add` command" require "bundler/cli/inject" - Inject.new(options, name, version).run + Inject.new(options.dup, name, version).run end desc "lock", "Creates a lockfile without installing" diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb index cf35e4985b4..8f0a26f9104 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -31,7 +31,8 @@ def run if added.any? Bundler.ui.confirm "Added to Gemfile:" - Bundler.ui.confirm added.map {|g| " #{g}" }.join("\n") + Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, + :source => '#{g.source}'" }.join("\n") else Bundler.ui.confirm "All gems were already present in the Gemfile" end From 67ee37f4bf17c0c27b112ef650b0a514ae04dd2f Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Tue, 21 Feb 2017 11:06:23 +0530 Subject: [PATCH 2/8] test cases added --- lib/bundler/cli/inject.rb | 3 +-- spec/commands/inject_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb index 8f0a26f9104..a515a69258f 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -31,8 +31,7 @@ def run if added.any? Bundler.ui.confirm "Added to Gemfile:" - Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, - :source => '#{g.source}'" }.join("\n") + Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, :source => '#{g.source}'" }.join("\n") else Bundler.ui.confirm "All gems were already present in the Gemfile" end diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index dd5e22498b4..2a5e8880f01 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -52,6 +52,29 @@ end end + context "use source and group options" do + it "add gem with source in gemfile" do + bundle "inject 'bootstrap' '>0' --source=https://rubygems.org" + gemfile = bundled_app("Gemfile").read + str = "gem 'bootstrap', '> 0', :source => 'https://rubygems.org'" + expect(gemfile).to match(/str/) + end + + it "add gem with group in gemfile" do + bundle "inject 'rack-obama' '>0' --group=development" + gemfile = bundled_app("Gemfile").read + str = "gem 'rack-obama', '> 0', :group => [:development]" + expect(gemfile).to match(/str/) + end + + it "add gem with source and group in gemfile" do + bundle "inject 'rails' '>0' --source=https://rubygems.org --group=development" + gemfile = bundled_app("Gemfile").read + str = "gem 'rails', '> 0', :group => [:development], :source => 'https://rubygems.org'" + expect(gemfile).to match(/str/) + end + end + context "when frozen" do before do bundle "install" From b78a3f0bfe73a988704ccb45dc04d3cea19e6db7 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Tue, 21 Feb 2017 15:16:12 +0530 Subject: [PATCH 3/8] minor changes --- lib/bundler/cli.rb | 4 ++-- spec/commands/inject_spec.rb | 23 +++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 80332de3c21..9ae53c0142b 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -466,9 +466,9 @@ def platform desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile" method_option "source", :type => :string, :banner => - "Use the specific source for the gem" + "Install gem from the given source" method_option "group", :type => :string, :banner => - "Put the gem into specific group" + "Install gem into a bundler group" def inject(name, version) SharedHelpers.major_deprecation "The `inject` command has been replaced by the `add` command" require "bundler/cli/inject" diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index 2a5e8880f01..53cc0a1ae44 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -52,26 +52,21 @@ end end - context "use source and group options" do - it "add gem with source in gemfile" do - bundle "inject 'bootstrap' '>0' --source=https://rubygems.org" + context "with source option" do + it "add gem with source option in gemfile" do + bundle "inject 'bootstrap' '>0' --source=https://ruby.taobao.org/" gemfile = bundled_app("Gemfile").read - str = "gem 'bootstrap', '> 0', :source => 'https://rubygems.org'" - expect(gemfile).to match(/str/) + str = "gem 'bootstrap', '> 0', :source => 'https://ruby.taobao.org/'" + expect(gemfile).to include str end + end - it "add gem with group in gemfile" do + context "with group option" do + it "add gem with group option in gemfile" do bundle "inject 'rack-obama' '>0' --group=development" gemfile = bundled_app("Gemfile").read str = "gem 'rack-obama', '> 0', :group => [:development]" - expect(gemfile).to match(/str/) - end - - it "add gem with source and group in gemfile" do - bundle "inject 'rails' '>0' --source=https://rubygems.org --group=development" - gemfile = bundled_app("Gemfile").read - str = "gem 'rails', '> 0', :group => [:development], :source => 'https://rubygems.org'" - expect(gemfile).to match(/str/) + expect(gemfile).to include str end end From 9f64468216c169692a943ab1927bd7ae306f88d5 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Thu, 23 Feb 2017 01:16:33 +0530 Subject: [PATCH 4/8] failed testcase fixed --- spec/commands/inject_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index 53cc0a1ae44..4fe505d28ca 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -54,9 +54,9 @@ context "with source option" do it "add gem with source option in gemfile" do - bundle "inject 'bootstrap' '>0' --source=https://ruby.taobao.org/" + bundle "inject 'foo' '>0' --source file://#{gem_repo1}" gemfile = bundled_app("Gemfile").read - str = "gem 'bootstrap', '> 0', :source => 'https://ruby.taobao.org/'" + str = "gem 'foo', '> 0', :source => 'file://#{gem_repo1}'" expect(gemfile).to include str end end From d73d78cb7754b77d3c196d6abb25146b8021af70 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Thu, 23 Feb 2017 01:28:56 +0530 Subject: [PATCH 5/8] using source.dump --- lib/bundler/cli/inject.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb index a515a69258f..c398038d49a 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -31,7 +31,7 @@ def run if added.any? Bundler.ui.confirm "Added to Gemfile:" - Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, :source => '#{g.source}'" }.join("\n") + Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, :source => '#{g.source.dump}'" }.join("\n") else Bundler.ui.confirm "All gems were already present in the Gemfile" end From cfe4eccfc33a8f6372a7197ffae95c15e023df95 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Fri, 24 Mar 2017 11:56:58 +0530 Subject: [PATCH 6/8] multiple groups testcase added and confirmation msg added --- lib/bundler/cli/inject.rb | 10 ++++++++-- spec/commands/inject_spec.rb | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb index c398038d49a..b17292643f5 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -6,7 +6,7 @@ def initialize(options, name, version) @options = options @name = name @version = version || last_version_number - @group = options[:group] + @group = options[:group].split(",") unless options[:group].nil? @source = options[:source] @gems = [] end @@ -31,7 +31,13 @@ def run if added.any? Bundler.ui.confirm "Added to Gemfile:" - Bundler.ui.confirm added.map {|g| " #{g}, group => #{g.groups.inspect}, :source => '#{g.source.dump}'" }.join("\n") + Bundler.ui.confirm(added.map do |d| + name = "'#{d.name}'" + requirement = ", '#{d.requirement}'" + group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default) + source = ", :source => '#{d.source}'" unless d.source.nil? + %(gem #{name}#{requirement}#{group}#{source}) + end.join("\n")) else Bundler.ui.confirm "All gems were already present in the Gemfile" end diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index 4fe505d28ca..fb7b68e31d0 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -68,6 +68,13 @@ str = "gem 'rack-obama', '> 0', :group => [:development]" expect(gemfile).to include str end + + it "add gem with multiple group in gemfile" do + bundle "inject 'rack-obama' '>0' --group=development,test" + gemfile = bundled_app("Gemfile").read + str = "gem 'rack-obama', '> 0', :group => [:development, :test]" + expect(gemfile).to include str + end end context "when frozen" do From 1f466c04a6d3ea54abfafc4d5fde0a17717ade55 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Thu, 30 Mar 2017 09:22:00 +0530 Subject: [PATCH 7/8] minor change: typo fixed --- spec/commands/inject_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index fb7b68e31d0..f39818b04ef 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -69,7 +69,7 @@ expect(gemfile).to include str end - it "add gem with multiple group in gemfile" do + it "add gem with multiple groups in gemfile" do bundle "inject 'rack-obama' '>0' --group=development,test" gemfile = bundled_app("Gemfile").read str = "gem 'rack-obama', '> 0', :group => [:development, :test]" From 1754e5019fe7f97db6d24f11bba8768d1dca7772 Mon Sep 17 00:00:00 2001 From: shekharrajak Date: Wed, 5 Apr 2017 10:19:04 +0530 Subject: [PATCH 8/8] writing groups instead of group in the Gemfile --- lib/bundler/injector.rb | 9 ++++++++- spec/commands/inject_spec.rb | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 787d95fd9ca..7c78486dacd 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -51,7 +51,14 @@ def new_gem_lines @new_deps.map do |d| name = "'#{d.name}'" requirement = ", '#{d.requirement}'" - group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default) + if d.groups != Array(:default) + group = + if d.groups.size == 1 + ", :group => #{d.groups.inspect}" + else + ", :groups => #{d.groups.inspect}" + end + end source = ", :source => '#{d.source}'" unless d.source.nil? %(gem #{name}#{requirement}#{group}#{source}) end.join("\n") diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index f39818b04ef..5c711b32a0b 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -72,7 +72,7 @@ it "add gem with multiple groups in gemfile" do bundle "inject 'rack-obama' '>0' --group=development,test" gemfile = bundled_app("Gemfile").read - str = "gem 'rack-obama', '> 0', :group => [:development, :test]" + str = "gem 'rack-obama', '> 0', :groups => [:development, :test]" expect(gemfile).to include str end end