diff options
author | Agrim Mittal <agrimmittal97@gmail.com> | 2018-06-04 12:45:01 +0530 |
---|---|---|
committer | Agrim Mittal <agrimmittal97@gmail.com> | 2018-06-28 15:35:16 +0530 |
commit | aebcec1efda24cad20024f5d6fb4d961b0715582 (patch) | |
tree | 81781acf520d2c6a636326a293601ed9f8885616 | |
parent | 16ac04d9cacd2e509faf0ed53d5b46ad0e537a1f (diff) | |
download | bundler-aebcec1efda24cad20024f5d6fb4d961b0715582.tar.gz |
Add gemfile error when gem is not present
-rw-r--r-- | lib/bundler/cli.rb | 6 | ||||
-rw-r--r-- | lib/bundler/injector.rb | 9 | ||||
-rw-r--r-- | man/bundle-remove.ronn | 2 | ||||
-rw-r--r-- | spec/commands/remove_spec.rb | 22 |
4 files changed, 19 insertions, 20 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 517833bc73..5bc6d956ea 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -166,12 +166,12 @@ module Bundler Check.new(options).run end - desc "remove [GEMS]", "Removes the gem from gemfile" + desc "remove [GEMS] [OPTIONS]", "Removes the gem from gemfile" long_desc <<-D - Removes gems from the Gemfile. If a gem is not found, Bundler prints a error message and if gem could not be removed due to any reason Bundler warns the user. + Removes gems from the Gemfile. If a gem is not found, Bundler prints a error message and if gem could not be removed due to any reason Bundler displays warning. D method_option "install", :type => :boolean, :banner => - "Removes gems from bundle" + "Runs 'bundle install' after removing the gems from the gemfile" def remove(*gems) require "bundler/cli/remove" Remove.new(gems, options).run diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 740b12f24a..ff1f876c6e 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -69,7 +69,7 @@ module Bundler # remove gems from each gemfiles we have definition.gemfiles.each do |path| - deps = evaluate_gemfile(path) + deps = remove_deps(path) show_warning("No gems were removed from the gemfile.") if deps.empty? @@ -128,7 +128,7 @@ module Bundler # evalutes a gemfile to remove the specified gem # from it. - def evaluate_gemfile(gemfile_path) + def remove_deps(gemfile_path) # get initial snap shot of the gemfile initial_gemfile = IO.readlines(gemfile_path) @@ -170,8 +170,7 @@ module Bundler deleted_dep = builder.dependencies.find {|d| d.name == gem_name } if deleted_dep.nil? - show_warning "`#{gem_name}` is not specified in Gemfile so not removed." - next + raise GemfileError, "`#{gem_name}` is not specified in Gemfile so could not be removed." end builder.dependencies.delete(deleted_dep) @@ -186,7 +185,7 @@ module Bundler # @param [Pathname] gemfile_path The Gemfile from which to remove dependencies. def remove_gems_from_gemfile(gems, gemfile_path) # store patterns of all gems to be removed - patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\((['"])#{Regexp.union(gems)}\2\)/ + patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/ # remove lines which match the regex new_gemfile = IO.readlines(gemfile_path).reject {|line| line.match(patterns) } diff --git a/man/bundle-remove.ronn b/man/bundle-remove.ronn index 38a8673764..6421ab3ef9 100644 --- a/man/bundle-remove.ronn +++ b/man/bundle-remove.ronn @@ -14,7 +14,7 @@ If gem could not be removed due to any reason Bundler warns the user. ## OPTIONS * `--install`: - Remove gems from bundle. + Runs 'bundle install' after removing the gems from the gemfile. Example: diff --git a/spec/commands/remove_spec.rb b/spec/commands/remove_spec.rb index e256deeada..f64ae179c9 100644 --- a/spec/commands/remove_spec.rb +++ b/spec/commands/remove_spec.rb @@ -52,10 +52,9 @@ RSpec.describe "bundle remove" do source "file://#{gem_repo1}" G - bundle! "remove rack" + bundle "remove rack" - expect(out).to include("`rack` is not specified in Gemfile so not removed.") - expect(out).to include("No gems were removed from the gemfile") + expect(out).to include("`rack` is not specified in Gemfile so could not be removed.") end end end @@ -90,13 +89,14 @@ RSpec.describe "bundle remove" do gem "rspec" G - bundle! "remove rails rack minitest" - expect(out).to include("rails (>= 0) was removed.") - expect(out).to include("minitest (>= 0) was removed.") - expect(out).to include("`rack` is not specified in Gemfile so not removed.") + bundle "remove rails rack minitest" + + expect(out).to include("`rack` is not specified in Gemfile so could not be removed.") gemfile_should_be <<-G source "file://#{gem_repo1}" + gem "rails" + gem "minitest" gem "rspec" G end @@ -410,9 +410,9 @@ RSpec.describe "bundle remove" do eval_gemfile "Gemfile-other" G - bundle! "remove rack" + bundle "remove rack" - expect(out).to include("`rack` is not specified in Gemfile so not removed.") + expect(out).to include("`rack` is not specified in Gemfile so could not be removed.") end end @@ -429,10 +429,10 @@ RSpec.describe "bundle remove" do gem "rack" G - bundle! "remove rack" + bundle "remove rack" expect(out).to include("rack (>= 0) was removed.") - expect(out).to include("`rack` is not specified in Gemfile so not removed.") + expect(out).to include("`rack` is not specified in Gemfile so could not be removed.") gemfile_should_be <<-G source "file://#{gem_repo1}" |