diff options
Diffstat (limited to 'spec/bundler/commands/remove_spec.rb')
-rw-r--r-- | spec/bundler/commands/remove_spec.rb | 113 |
1 files changed, 73 insertions, 40 deletions
diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 170545f80c..197fcde091 100644 --- a/spec/bundler/commands/remove_spec.rb +++ b/spec/bundler/commands/remove_spec.rb @@ -7,13 +7,43 @@ RSpec.describe "bundle remove" do source "#{file_uri_for(gem_repo1)}" G - bundle "remove", :raise_on_error => false + bundle "remove", raise_on_error: false expect(err).to include("Please specify gems to remove.") end end - context "when --install flag is specified" do + context "after 'bundle install' is run" do + describe "running 'bundle remove GEM_NAME'" do + it "removes it from the lockfile" do + rack_dep = <<~L + + DEPENDENCIES + rack + + L + + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + + gem "rack" + G + + bundle "install" + + expect(lockfile).to include(rack_dep) + + bundle "remove rack" + + expect(gemfile).to eq <<~G + source "#{file_uri_for(gem_repo1)}" + G + expect(lockfile).to_not include(rack_dep) + end + end + end + + context "when --install flag is specified", bundler: "< 3" do it "removes gems from .bundle" do gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -40,27 +70,30 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(the_bundle).to_not include_gems "rack" + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end context "when gem is specified in multiple lines" do it "shows success for removed gem" do + build_git "rack" + gemfile <<-G source '#{file_uri_for(gem_repo1)}' gem 'git' gem 'rack', - git: 'https://github.com/rack/rack', - branch: 'master' + git: "#{lib_path("rack-1.0")}", + branch: 'main' gem 'nokogiri' G bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source '#{file_uri_for(gem_repo1)}' gem 'git' @@ -76,7 +109,7 @@ RSpec.describe "bundle remove" do source "#{file_uri_for(gem_repo1)}" G - bundle "remove rack", :raise_on_error => false + bundle "remove rack", raise_on_error: false expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end @@ -97,7 +130,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rack was removed.") expect(out).to include("rails was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -113,10 +146,10 @@ RSpec.describe "bundle remove" do gem "rspec" G - bundle "remove rails rack minitest", :raise_on_error => false + bundle "remove rails rack minitest", raise_on_error: false expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" gem "rails" @@ -138,7 +171,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -158,7 +191,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -178,7 +211,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" group :test do @@ -204,7 +237,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -223,7 +256,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -246,7 +279,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -269,7 +302,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -292,7 +325,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" group :test do @@ -319,7 +352,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" group :test do @@ -340,10 +373,10 @@ RSpec.describe "bundle remove" do gem "rack"; gem "rails" G - bundle "remove rails", :raise_on_error => false + bundle "remove rails", raise_on_error: false expect(err).to include("Gems could not be removed. rack (>= 0) would also have been removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" gem "rack"; gem "rails" G @@ -352,7 +385,7 @@ RSpec.describe "bundle remove" do context "when some gems could not be removed" do it "shows warning for gems not removed and success for those removed" do - install_gemfile <<-G, :raise_on_error => false + install_gemfile <<-G, raise_on_error: false source "#{file_uri_for(gem_repo1)}" gem"rack" gem"rspec" @@ -365,7 +398,7 @@ RSpec.describe "bundle remove" do expect(out).to include("rails was removed.") expect(out).to include("minitest was removed.") expect(out).to include("rack, rspec could not be removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" gem"rack" gem"rspec" @@ -397,7 +430,7 @@ RSpec.describe "bundle remove" do bundle "remove rspec" expect(out).to include("rspec was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" gem "rack" @@ -458,7 +491,7 @@ RSpec.describe "bundle remove" do eval_gemfile "Gemfile-other" G - bundle "remove rack", :raise_on_error => false + bundle "remove rack", raise_on_error: false expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end @@ -477,11 +510,11 @@ RSpec.describe "bundle remove" do gem "rack" G - bundle "remove rack", :raise_on_error => false + bundle "remove rack", raise_on_error: false expect(out).to include("rack was removed.") expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile-other")} so it could not be removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" eval_gemfile "Gemfile-other" @@ -489,7 +522,7 @@ RSpec.describe "bundle remove" do end end - context "when gems can not be removed from other gemfile" do + context "when gems cannot be removed from other gemfile" do it "shows error" do create_file "Gemfile-other", <<-G gem "rails"; gem "rack" @@ -502,11 +535,11 @@ RSpec.describe "bundle remove" do gem "rack" G - bundle "remove rack", :raise_on_error => false + bundle "remove rack", raise_on_error: false expect(out).to include("rack was removed.") expect(err).to include("Gems could not be removed. rails (>= 0) would also have been removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" eval_gemfile "Gemfile-other" @@ -527,11 +560,11 @@ RSpec.describe "bundle remove" do gem "rails"; gem "rack" G - bundle "remove rack", :raise_on_error => false + bundle "remove rack", raise_on_error: false expect(err).to include("Gems could not be removed. rails (>= 0) would also have been removed.") expect(bundled_app("Gemfile-other").read).to include("gem \"rack\"") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" eval_gemfile "Gemfile-other" @@ -541,7 +574,7 @@ RSpec.describe "bundle remove" do end context "when gem present in gemfiles but could not be removed from one from one of them" do - it "removes gem which can be removed and shows warning for file from which it can not be removed" do + it "removes gem which can be removed and shows warning for file from which it cannot be removed" do create_file "Gemfile-other", <<-G gem "rack" G @@ -574,7 +607,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -593,7 +626,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -601,7 +634,7 @@ RSpec.describe "bundle remove" do context "with gemspec" do it "should not remove the gem" do - build_lib("foo", :path => tmp.join("foo")) do |s| + build_lib("foo", path: tmp.join("foo")) do |s| s.write("foo.gemspec", "") s.add_dependency "rack" end @@ -630,7 +663,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" # gem "rack" might be used in the future @@ -649,7 +682,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" G end @@ -668,7 +701,7 @@ RSpec.describe "bundle remove" do expect(out).to_not include("puma was removed.") expect(out).to include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" gem "puma" # implements interface provided by gem "rack" G @@ -688,7 +721,7 @@ RSpec.describe "bundle remove" do expect(out).to include("puma was removed.") expect(out).to_not include("rack was removed.") - gemfile_should_be <<-G + expect(gemfile).to eq <<~G source "#{file_uri_for(gem_repo1)}" gem "rack" |