diff options
Diffstat (limited to 'spec/bundler/commands/remove_spec.rb')
-rw-r--r-- | spec/bundler/commands/remove_spec.rb | 112 |
1 files changed, 72 insertions, 40 deletions
diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 9e2586bae6..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", :bundler => "< 3" 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)}" @@ -41,27 +71,29 @@ RSpec.describe "bundle remove" do expect(out).to include("rack was removed.") expect(the_bundle).to_not include_gems "rack" - gemfile_should_be <<-G + 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' @@ -77,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 @@ -98,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 @@ -114,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" @@ -139,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 @@ -159,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 @@ -179,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 @@ -205,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 @@ -224,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 @@ -247,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 @@ -270,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 @@ -293,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 @@ -320,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 @@ -341,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 @@ -353,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" @@ -366,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" @@ -398,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" @@ -459,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 @@ -478,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" @@ -490,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" @@ -503,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" @@ -528,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" @@ -542,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 @@ -575,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 @@ -594,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 @@ -602,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 @@ -631,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 @@ -650,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 @@ -669,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 @@ -689,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" |