diff options
Diffstat (limited to 'spec/bundler/update')
| -rw-r--r-- | spec/bundler/update/force_spec.rb | 30 | ||||
| -rw-r--r-- | spec/bundler/update/gemfile_spec.rb | 47 | ||||
| -rw-r--r-- | spec/bundler/update/gems/fund_spec.rb | 50 | ||||
| -rw-r--r-- | spec/bundler/update/gems/post_install_spec.rb | 28 | ||||
| -rw-r--r-- | spec/bundler/update/git_spec.rb | 217 | ||||
| -rw-r--r-- | spec/bundler/update/path_spec.rb | 5 |
6 files changed, 236 insertions, 141 deletions
diff --git a/spec/bundler/update/force_spec.rb b/spec/bundler/update/force_spec.rb new file mode 100644 index 0000000000..325f58088a --- /dev/null +++ b/spec/bundler/update/force_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +RSpec.describe "bundle update" do + before :each do + install_gemfile <<-G + source "https://gem.repo1" + gem "myrack" + G + end + + it "re-installs installed gems with --force" do + myrack_lib = default_bundle_path("gems/myrack-1.0.0/lib/myrack.rb") + myrack_lib.open("w") {|f| f.write("blah blah blah") } + bundle :update, force: true + + expect(out).to include "Installing myrack 1.0.0" + expect(myrack_lib.open(&:read)).to eq("MYRACK = '1.0.0'\n") + expect(the_bundle).to include_gems "myrack 1.0.0" + end + + it "re-installs installed gems with --redownload" do + myrack_lib = default_bundle_path("gems/myrack-1.0.0/lib/myrack.rb") + myrack_lib.open("w") {|f| f.write("blah blah blah") } + bundle :update, redownload: true + + expect(out).to include "Installing myrack 1.0.0" + expect(myrack_lib.open(&:read)).to eq("MYRACK = '1.0.0'\n") + expect(the_bundle).to include_gems "myrack 1.0.0" + end +end diff --git a/spec/bundler/update/gemfile_spec.rb b/spec/bundler/update/gemfile_spec.rb new file mode 100644 index 0000000000..f8849640b6 --- /dev/null +++ b/spec/bundler/update/gemfile_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +RSpec.describe "bundle update" do + context "with --gemfile" do + it "finds the gemfile" do + gemfile bundled_app("NotGemfile"), <<-G + source "https://gem.repo1" + gem 'myrack' + G + + bundle :install, gemfile: bundled_app("NotGemfile") + bundle :update, gemfile: bundled_app("NotGemfile"), all: true + + # Specify BUNDLE_GEMFILE for `the_bundle` + # to retrieve the proper Gemfile + ENV["BUNDLE_GEMFILE"] = "NotGemfile" + expect(the_bundle).to include_gems "myrack 1.0.0" + end + end + + context "with gemfile set via config" do + before do + gemfile bundled_app("NotGemfile"), <<-G + source "https://gem.repo1" + gem 'myrack' + G + + bundle_config "gemfile #{bundled_app("NotGemfile")}" + bundle :install + end + + it "uses the gemfile to update" do + bundle "update", all: true + bundle "list" + + expect(out).to include("myrack (1.0.0)") + end + + it "uses the gemfile while in a subdirectory" do + bundled_app("subdir").mkpath + bundle "update", all: true, dir: bundled_app("subdir") + bundle "list", dir: bundled_app("subdir") + + expect(out).to include("myrack (1.0.0)") + end + end +end diff --git a/spec/bundler/update/gems/fund_spec.rb b/spec/bundler/update/gems/fund_spec.rb new file mode 100644 index 0000000000..a5624d3e0a --- /dev/null +++ b/spec/bundler/update/gems/fund_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +RSpec.describe "bundle update" do + before do + build_repo2 do + build_gem "has_funding_and_other_metadata" do |s| + s.metadata = { + "bug_tracker_uri" => "https://example.com/user/bestgemever/issues", + "changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md", + "documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1", + "homepage_uri" => "https://bestgemever.example.io", + "mailing_list_uri" => "https://groups.example.com/bestgemever", + "funding_uri" => "https://example.com/has_funding_and_other_metadata/funding", + "source_code_uri" => "https://example.com/user/bestgemever", + "wiki_uri" => "https://example.com/user/bestgemever/wiki", + } + end + + build_gem "has_funding", "1.2.3" do |s| + s.metadata = { + "funding_uri" => "https://example.com/has_funding/funding", + } + end + end + + gemfile <<-G + source "https://gem.repo2" + gem 'has_funding_and_other_metadata' + gem 'has_funding', '< 2.0' + G + + bundle :install + end + + context "when listed gems are updated" do + before do + gemfile <<-G + source "https://gem.repo2" + gem 'has_funding_and_other_metadata' + gem 'has_funding' + G + + bundle :update, all: true + end + + it "displays fund message" do + expect(out).to include("2 installed gems you directly depend on are looking for funding.") + end + end +end diff --git a/spec/bundler/update/gems/post_install_spec.rb b/spec/bundler/update/gems/post_install_spec.rb index 2fb3547806..9c71f6e0e3 100644 --- a/spec/bundler/update/gems/post_install_spec.rb +++ b/spec/bundler/update/gems/post_install_spec.rb @@ -5,22 +5,22 @@ RSpec.describe "bundle update" do before do gemfile <<-G - source "file://#{gem_repo1}" - gem 'rack', "< 1.0" + source "https://gem.repo1" + gem 'myrack', "< 1.0" gem 'thin' G - bundle! "config #{config}" if config + bundle "config set #{config}" if config - bundle! :install + bundle :install end shared_examples "a config observer" do context "when ignore post-install messages for gem is set" do - let(:config) { "ignore_messages.rack true" } + let(:config) { "ignore_messages.myrack true" } it "doesn't display gem's post-install message" do - expect(out).not_to include("Rack's post install message") + expect(out).not_to include("Myrack's post install message") end end @@ -35,8 +35,8 @@ RSpec.describe "bundle update" do shared_examples "a post-install message outputter" do it "should display post-install messages for updated gems" do - expect(out).to include("Post-install message from rack:") - expect(out).to include("Rack's post install message") + expect(out).to include("Post-install message from myrack:") + expect(out).to include("Myrack's post install message") end it "should not display the post-install message for non-updated gems" do @@ -47,12 +47,12 @@ RSpec.describe "bundle update" do context "when listed gem is updated" do before do gemfile <<-G - source "file://#{gem_repo1}" - gem 'rack' + source "https://gem.repo1" + gem 'myrack' gem 'thin' G - bundle! :update, :all => bundle_update_requires_all? + bundle :update, all: true end it_behaves_like "a post-install message outputter" @@ -62,12 +62,12 @@ RSpec.describe "bundle update" do context "when dependency triggers update" do before do gemfile <<-G - source "file://#{gem_repo1}" - gem 'rack-obama' + source "https://gem.repo1" + gem 'myrack-obama' gem 'thin' G - bundle! :update, :all => bundle_update_requires_all? + bundle :update, all: true end it_behaves_like "a post-install message outputter" diff --git a/spec/bundler/update/git_spec.rb b/spec/bundler/update/git_spec.rb index 52c4fc0957..526e988ab7 100644 --- a/spec/bundler/update/git_spec.rb +++ b/spec/bundler/update/git_spec.rb @@ -4,48 +4,51 @@ RSpec.describe "bundle update" do describe "git sources" do it "floats on a branch when :branch is used" do build_git "foo", "1.0" - update_git "foo", :branch => "omg" + update_git "foo", branch: "omg" install_gemfile <<-G + source "https://gem.repo1" git "#{lib_path("foo-1.0")}", :branch => "omg" do gem 'foo' end G - update_git "foo", :branch => "omg" do |s| + update_git "foo" do |s| s.write "lib/foo.rb", "FOO = '1.1'" end - bundle "update", :all => bundle_update_requires_all? + bundle "update", all: true expect(the_bundle).to include_gems "foo 1.1" end it "updates correctly when you have like craziness" do - build_lib "activesupport", "3.0", :path => lib_path("rails/activesupport") - build_git "rails", "3.0", :path => lib_path("rails") do |s| + build_lib "activesupport", "3.0", path: lib_path("rails/activesupport") + build_git "rails", "3.0", path: lib_path("rails") do |s| s.add_dependency "activesupport", "= 3.0" end - install_gemfile! <<-G + install_gemfile <<-G + source "https://gem.repo1" gem "rails", :git => "#{lib_path("rails")}" G - bundle! "update rails" + bundle "update rails" expect(the_bundle).to include_gems "rails 3.0", "activesupport 3.0" end it "floats on a branch when :branch is used and the source is specified in the update" do - build_git "foo", "1.0", :path => lib_path("foo") - update_git "foo", :branch => "omg", :path => lib_path("foo") + build_git "foo", "1.0", path: lib_path("foo") + update_git "foo", branch: "omg", path: lib_path("foo") install_gemfile <<-G + source "https://gem.repo1" git "#{lib_path("foo")}", :branch => "omg" do gem 'foo' end G - update_git "foo", :branch => "omg", :path => lib_path("foo") do |s| + update_git "foo", path: lib_path("foo") do |s| s.write "lib/foo.rb", "FOO = '1.1'" end @@ -54,18 +57,19 @@ RSpec.describe "bundle update" do expect(the_bundle).to include_gems "foo 1.1" end - it "floats on master when updating all gems that are pinned to the source even if you have child dependencies" do - build_git "foo", :path => lib_path("foo") - build_gem "bar", :to_bundle => true do |s| + it "floats on main when updating all gems that are pinned to the source even if you have child dependencies" do + build_git "foo", path: lib_path("foo") + build_gem "bar", to_bundle: true do |s| s.add_dependency "foo" end install_gemfile <<-G + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo")}" gem "bar" G - update_git "foo", :path => lib_path("foo") do |s| + update_git "foo", path: lib_path("foo") do |s| s.write "lib/foo.rb", "FOO = '1.1'" end @@ -75,48 +79,55 @@ RSpec.describe "bundle update" do end it "notices when you change the repo url in the Gemfile" do - build_git "foo", :path => lib_path("foo_one") - build_git "foo", :path => lib_path("foo_two") + build_git "foo", path: lib_path("foo_one") + build_git "foo", path: lib_path("foo_two") install_gemfile <<-G + source "https://gem.repo1" gem "foo", "1.0", :git => "#{lib_path("foo_one")}" G - FileUtils.rm_rf lib_path("foo_one") + FileUtils.rm_r lib_path("foo_one") install_gemfile <<-G + source "https://gem.repo1" gem "foo", "1.0", :git => "#{lib_path("foo_two")}" G - expect(err).to lack_errors + expect(err).to be_empty expect(out).to include("Fetching #{lib_path}/foo_two") expect(out).to include("Bundle complete!") end it "fetches tags from the remote" do build_git "foo" - @remote = build_git("bar", :bare => true) - update_git "foo", :remote => @remote.path - update_git "foo", :push => "master" + @remote = build_git("bar", bare: true) + update_git "foo", remote: @remote.path + update_git "foo", push: "main" install_gemfile <<-G + source "https://gem.repo1" gem 'foo', :git => "#{@remote.path}" G # Create a new tag on the remote that needs fetching - update_git "foo", :tag => "fubar" - update_git "foo", :push => "fubar" + update_git "foo", tag: "fubar" + update_git "foo", push: "fubar" gemfile <<-G + source "https://gem.repo1" gem 'foo', :git => "#{@remote.path}", :tag => "fubar" G - bundle "update", :all => bundle_update_requires_all? - expect(exitstatus).to eq(0) if exitstatus + bundle "update", all: true + expect(err).to be_empty end describe "with submodules" do before :each do + # CVE-2022-39253: https://lore.kernel.org/lkml/xmqq4jw1uku5.fsf@gitster.g/ + system(*%W[git config --global protocol.file.allow always]) + build_repo4 do build_gem "submodule" do |s| s.write "lib/submodule.rb", "puts 'GEM'" @@ -131,15 +142,13 @@ RSpec.describe "bundle update" do s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0") + git "commit -m \"submodulator\"", lib_path("has_submodule-1.0") end it "it unlocks the source when submodules are added to a git source" do install_gemfile <<-G - source "file:#{gem_repo4}" + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}" do gem "has_submodule" end @@ -149,7 +158,7 @@ RSpec.describe "bundle update" do expect(out).to eq("GEM") install_gemfile <<-G - source "file:#{gem_repo4}" + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}", :submodules => true do gem "has_submodule" end @@ -159,25 +168,25 @@ RSpec.describe "bundle update" do expect(out).to eq("GIT") end - it "unlocks the source when submodules are removed from git source", :git => ">= 2.9.0" do - install_gemfile! <<-G - source "file:#{gem_repo4}" + it "unlocks the source when submodules are removed from git source", git: ">= 2.9.0" do + install_gemfile <<-G + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}", :submodules => true do gem "has_submodule" end G - run! "require 'submodule'" + run "require 'submodule'" expect(out).to eq("GIT") - install_gemfile! <<-G - source "file:#{gem_repo4}" + install_gemfile <<-G + source "https://gem.repo4" git "#{lib_path("has_submodule-1.0")}" do gem "has_submodule" end G - run! "require 'submodule'" + run "require 'submodule'" expect(out).to eq("GEM") end end @@ -186,91 +195,80 @@ RSpec.describe "bundle update" do build_git "foo", "1.0" install_gemfile <<-G + source "https://gem.repo1" gem "foo", :git => "#{lib_path("foo-1.0")}" G - lib_path("foo-1.0").join(".git").rmtree + FileUtils.rm_rf lib_path("foo-1.0").join(".git") - bundle :update, :all => bundle_update_requires_all? - expect(last_command.bundler_err).to include(lib_path("foo-1.0").to_s). + bundle :update, all: true, raise_on_error: false + expect(err).to include(lib_path("foo-1.0").to_s). and match(/Git error: command `git fetch.+has failed/) end it "should not explode on invalid revision on update of gem by name" do - build_git "rack", "0.8" + build_git "myrack", "0.8" - build_git "rack", "0.8", :path => lib_path("local-rack") do |s| - s.write "lib/rack.rb", "puts :LOCAL" + build_git "myrack", "0.8", path: lib_path("local-myrack") do |s| + s.write "lib/myrack.rb", "puts :LOCAL" end install_gemfile <<-G - source "file://#{gem_repo1}" - gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" + source "https://gem.repo1" + gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main" G - bundle %(config local.rack #{lib_path("local-rack")}) - bundle "update rack" + bundle %(config set local.myrack #{lib_path("local-myrack")}) + bundle "update myrack" expect(out).to include("Bundle updated!") end it "shows the previous version of the gem" do - build_git "rails", "3.0", :path => lib_path("rails") + build_git "rails", "2.3.2", path: lib_path("rails") install_gemfile <<-G + source "https://gem.repo1" gem "rails", :git => "#{lib_path("rails")}" G - lockfile <<-G - GIT - remote: #{lib_path("rails")} - specs: - rails (2.3.2) - - PLATFORMS - #{generic_local_platform} + update_git "rails", "3.0", path: lib_path("rails"), gemspec: true - DEPENDENCIES - rails! - G - - bundle "update", :all => bundle_update_requires_all? - expect(out).to include("Using rails 3.0 (was 2.3.2) from #{lib_path("rails")} (at master@#{revision_for(lib_path("rails"))[0..6]})") + bundle "update", all: true + expect(out).to include("Using rails 3.0 (was 2.3.2) from #{lib_path("rails")} (at main@#{revision_for(lib_path("rails"))[0..6]})") end end describe "with --source flag" do before :each do build_repo2 - @git = build_git "foo", :path => lib_path("foo") do |s| + @git = build_git "foo", path: lib_path("foo") do |s| s.executables = "foobar" end install_gemfile <<-G - source "file://#{gem_repo2}" + source "https://gem.repo2" git "#{lib_path("foo")}" do gem 'foo' end - gem 'rack' + gem 'myrack' G end it "updates the source" do - update_git "foo", :path => @git.path + update_git "foo", path: @git.path bundle "update --source foo" - in_app_root do - run <<-RUBY - require 'foo' - puts "WIN" if defined?(FOO_PREV_REF) - RUBY + run <<-RUBY + require 'foo' + puts "WIN" if defined?(FOO_PREV_REF) + RUBY - expect(out).to eq("WIN") - end + expect(out).to eq("WIN") end it "unlocks gems that were originally pulled in by the source" do - update_git "foo", "2.0", :path => @git.path + update_git "foo", "2.0", path: @git.path bundle "update --source foo" expect(the_bundle).to include_gems "foo 2.0" @@ -278,40 +276,45 @@ RSpec.describe "bundle update" do it "leaves all other gems frozen" do update_repo2 - update_git "foo", :path => @git.path + update_git "foo", path: @git.path bundle "update --source foo" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "myrack 1.0" end end context "when the gem and the repository have different names" do before :each do build_repo2 - @git = build_git "foo", :path => lib_path("bar") + @git = build_git "foo", path: lib_path("bar") install_gemfile <<-G - source "file://#{gem_repo2}" + source "https://gem.repo2" git "#{lib_path("bar")}" do gem 'foo' end - gem 'rack' + gem 'myrack' G end - it "the --source flag updates version of gems that were originally pulled in by the source", :bundler => "< 2" do + it "the --source flag updates version of gems that were originally pulled in by the source" do spec_lines = lib_path("bar/foo.gemspec").read.split("\n") spec_lines[5] = "s.version = '2.0'" - update_git "foo", "2.0", :path => @git.path do |s| + update_git "foo", "2.0", path: @git.path do |s| s.write "foo.gemspec", spec_lines.join("\n") end - ref = @git.ref_for "master" + ref = @git.ref_for "main" bundle "update --source bar" - lockfile_should_be <<-G + checksums = checksums_section_when_enabled do |c| + c.no_checksum "foo", "2.0" + c.checksum gem_repo2, "myrack", "1.0.0" + end + + expect(lockfile).to eq <<~G GIT remote: #{@git.path} revision: #{ref} @@ -319,55 +322,19 @@ RSpec.describe "bundle update" do foo (2.0) GEM - remote: file:#{gem_repo2}/ + remote: https://gem.repo2/ specs: - rack (1.0.0) - - PLATFORMS - ruby - - DEPENDENCIES - foo! - rack - - BUNDLED WITH - #{Bundler::VERSION} - G - end - - it "the --source flag updates version of gems that were originally pulled in by the source", :bundler => "2" do - spec_lines = lib_path("bar/foo.gemspec").read.split("\n") - spec_lines[5] = "s.version = '2.0'" - - update_git "foo", "2.0", :path => @git.path do |s| - s.write "foo.gemspec", spec_lines.join("\n") - end - - ref = @git.ref_for "master" - - bundle "update --source bar" - - lockfile_should_be <<-G - GEM - remote: file:#{gem_repo2}/ - specs: - rack (1.0.0) - - GIT - remote: #{@git.path} - revision: #{ref} - specs: - foo (2.0) + myrack (1.0.0) PLATFORMS #{lockfile_platforms} DEPENDENCIES foo! - rack - + myrack + #{checksums} BUNDLED WITH - #{Bundler::VERSION} + #{Bundler::VERSION} G end end diff --git a/spec/bundler/update/path_spec.rb b/spec/bundler/update/path_spec.rb index 38c125e04b..8c76c94e1a 100644 --- a/spec/bundler/update/path_spec.rb +++ b/spec/bundler/update/path_spec.rb @@ -3,13 +3,14 @@ RSpec.describe "path sources" do describe "bundle update --source" do it "shows the previous version of the gem when updated from path source" do - build_lib "activesupport", "2.3.5", :path => lib_path("rails/activesupport") + build_lib "activesupport", "2.3.5", path: lib_path("rails/activesupport") install_gemfile <<-G + source "https://gem.repo1" gem "activesupport", :path => "#{lib_path("rails/activesupport")}" G - build_lib "activesupport", "3.0", :path => lib_path("rails/activesupport") + build_lib "activesupport", "3.0", path: lib_path("rails/activesupport") bundle "update --source activesupport" expect(out).to include("Using activesupport 3.0 (was 2.3.5) from source at `#{lib_path("rails/activesupport")}`") |
