summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgrim Mittal <agrimmittal97@gmail.com>2018-05-01 03:22:10 +0530
committerAgrim Mittal <agrimmittal97@gmail.com>2018-05-02 16:40:00 +0530
commit9e87a1ca4b0c3002ac2774e4837234cef7e3ce08 (patch)
tree277a895f7069e53ea078738a26235b9c6fa9165d
parent948771063c05a56af8888acf5c01171293371214 (diff)
downloadbundler-9e87a1ca4b0c3002ac2774e4837234cef7e3ce08.tar.gz
Add --skip-install flag to bundle add
-rw-r--r--lib/bundler/cli.rb3
-rw-r--r--lib/bundler/cli/add.rb2
-rw-r--r--spec/commands/add_spec.rb10
3 files changed, 13 insertions, 2 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 1b913024e2..3a15ec6dc5 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -333,7 +333,8 @@ module Bundler
method_option "version", :aliases => "-v", :type => :string
method_option "group", :aliases => "-g", :type => :string
method_option "source", :aliases => "-s", :type => :string
-
+ method_option "skip-install", :type => :boolean, :banner =>
+ "Adds gem to gemfile but does not install it"
def add(gem_name)
require "bundler/cli/add"
Add.new(options.dup, gem_name).run
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb
index 1fcbd22f28..e1a662161e 100644
--- a/lib/bundler/cli/add.rb
+++ b/lib/bundler/cli/add.rb
@@ -19,7 +19,7 @@ module Bundler
dependency = Bundler::Dependency.new(@gem_name, version, @options)
Injector.inject([dependency], :conservative_versioning => @options[:version].nil?) # Perform conservative versioning only when version is not specified
- Installer.install(Bundler.root, Bundler.definition)
+ Installer.install(Bundler.root, Bundler.definition) unless @options["skip-install"]
end
end
end
diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb
index d1f2050aa0..194ff7651b 100644
--- a/spec/commands/add_spec.rb
+++ b/spec/commands/add_spec.rb
@@ -75,11 +75,21 @@ RSpec.describe "bundle add" do
describe "with --source" do
it "adds dependency with specified source" do
bundle "add 'foo' --source='file://#{gem_repo2}'"
+
expect(bundled_app("Gemfile").read).to match(%r{gem "foo", "~> 2.0", :source => "file:\/\/#{gem_repo2}"})
expect(the_bundle).to include_gems "foo 2.0"
end
end
+ describe "with --skip-install" do
+ it "adds gem to Gemfile but is not installed" do
+ bundle "add foo --skip-install --version=2.0"
+
+ expect(bundled_app("Gemfile").read).to match(%r{gem "foo", "= 2.0"})
+ expect(the_bundle).to_not include_gems "foo 2.0"
+ end
+ end
+
it "using combination of short form options works like long form" do
bundle "add 'foo' -s='file://#{gem_repo2}' -g='development' -v='~>1.0'"
expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 1.0", :group => [:development], :source => "file://#{gem_repo2}")