From 7585bc31877d4f9725f8de51b4a2faf47acb6f34 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 11 Nov 2019 17:57:45 +0900 Subject: Merge Bundler 2.1.0.pre.3 Features: - Add caller information to some deprecation messages to make them easier to fix [#7361](https://github.com/bundler/bundler/pull/7361) - Reconcile `bundle cache` vs `bundle package` everywhere. Now in docs, CLI help and everywhere else `bundle cache` is the preferred version and `bundle package` remains as an alias [#7389](https://github.com/bundler/bundler/pull/7389) - Display some basic `bundler` documentation together with ruby's RDoc based documentation [#7394](https://github.com/bundler/bundler/pull/7394) Bugfixes: - Fix typos deprecation message and upgrading docs [#7374](https://github.com/bundler/bundler/pull/7374) - Deprecation warnings about `taint` usage on ruby 2.7 [#7385](https://github.com/bundler/bundler/pull/7385) - Fix `--help` flag not correctly delegating to `man` when used with command aliases [#7388](https://github.com/bundler/bundler/pull/7388) - `bundle add` should cache newly added gems if an application cache exists [#7393](https://github.com/bundler/bundler/pull/7393) - Stop using an insecure folder as a "fallback home" when user home is not defined [#7416](https://github.com/bundler/bundler/pull/7416) - Fix `bundler/inline` warning about `Bundler.root` redefinition [#7417](https://github.com/bundler/bundler/pull/7417) --- spec/bundler/bundler/bundler_spec.rb | 38 +- spec/bundler/bundler/cli_spec.rb | 50 +++ spec/bundler/bundler/friendly_errors_spec.rb | 2 +- spec/bundler/bundler/plugin_spec.rb | 2 + spec/bundler/bundler/ruby_version_spec.rb | 20 +- spec/bundler/bundler/settings_spec.rb | 2 +- spec/bundler/bundler/shared_helpers_spec.rb | 2 +- spec/bundler/bundler/source_spec.rb | 31 +- spec/bundler/bundler/ui/shell_spec.rb | 2 + spec/bundler/cache/cache_path_spec.rb | 6 +- spec/bundler/cache/git_spec.rb | 342 ++++++++------- spec/bundler/cache/path_spec.rb | 214 +++++----- spec/bundler/commands/add_spec.rb | 9 + spec/bundler/commands/cache_spec.rb | 351 +++++++++++++++ spec/bundler/commands/exec_spec.rb | 6 +- spec/bundler/commands/newgem_spec.rb | 474 +++++++-------------- spec/bundler/commands/package_spec.rb | 351 --------------- spec/bundler/install/deploy_spec.rb | 2 +- spec/bundler/install/gemfile/git_spec.rb | 8 +- spec/bundler/install/gemfile/groups_spec.rb | 2 +- spec/bundler/install/gemfile/path_spec.rb | 6 +- spec/bundler/install/gemfile/sources_spec.rb | 2 +- spec/bundler/lock/lockfile_spec.rb | 2 +- spec/bundler/other/major_deprecation_spec.rb | 19 +- spec/bundler/other/platform_spec.rb | 12 +- spec/bundler/plugins/source/example_spec.rb | 2 +- spec/bundler/realworld/dependency_api_spec.rb | 4 +- spec/bundler/realworld/double_check_spec.rb | 6 +- spec/bundler/realworld/edgecases_spec.rb | 20 +- .../realworld/gemfile_source_header_spec.rb | 4 +- spec/bundler/realworld/mirror_probe_spec.rb | 4 +- spec/bundler/runtime/gem_tasks_spec.rb | 4 +- spec/bundler/runtime/inline_spec.rb | 8 +- spec/bundler/runtime/load_spec.rb | 2 +- spec/bundler/runtime/platform_spec.rb | 2 +- spec/bundler/runtime/require_spec.rb | 2 +- spec/bundler/runtime/setup_spec.rb | 62 +-- spec/bundler/runtime/with_unbundled_env_spec.rb | 36 +- spec/bundler/spec_helper.rb | 46 +- spec/bundler/support/artifice/compact_index.rb | 2 +- .../support/artifice/compact_index_api_missing.rb | 2 +- .../artifice/compact_index_basic_authentication.rb | 2 +- .../artifice/compact_index_checksum_mismatch.rb | 2 +- .../artifice/compact_index_concurrent_download.rb | 2 +- .../artifice/compact_index_creds_diff_host.rb | 2 +- .../support/artifice/compact_index_extra.rb | 2 +- .../support/artifice/compact_index_extra_api.rb | 2 +- .../artifice/compact_index_extra_api_missing.rb | 2 +- .../artifice/compact_index_extra_missing.rb | 2 +- .../support/artifice/compact_index_forbidden.rb | 2 +- .../artifice/compact_index_host_redirect.rb | 2 +- .../support/artifice/compact_index_no_gem.rb | 2 +- .../artifice/compact_index_partial_update.rb | 2 +- .../compact_index_range_not_satisfiable.rb | 2 +- .../support/artifice/compact_index_rate_limited.rb | 2 +- .../support/artifice/compact_index_redirects.rb | 2 +- .../compact_index_strict_basic_authentication.rb | 2 +- .../artifice/compact_index_wrong_dependencies.rb | 2 +- .../artifice/compact_index_wrong_gem_checksum.rb | 2 +- .../endopint_marshal_fail_basic_authentication.rb | 2 +- spec/bundler/support/artifice/endpoint.rb | 6 +- spec/bundler/support/artifice/endpoint_500.rb | 2 +- .../support/artifice/endpoint_api_forbidden.rb | 2 +- .../support/artifice/endpoint_api_missing.rb | 2 +- .../artifice/endpoint_basic_authentication.rb | 2 +- .../support/artifice/endpoint_creds_diff_host.rb | 2 +- spec/bundler/support/artifice/endpoint_extra.rb | 2 +- .../bundler/support/artifice/endpoint_extra_api.rb | 2 +- .../support/artifice/endpoint_extra_missing.rb | 2 +- spec/bundler/support/artifice/endpoint_fallback.rb | 2 +- .../support/artifice/endpoint_host_redirect.rb | 2 +- .../support/artifice/endpoint_marshal_fail.rb | 2 +- .../support/artifice/endpoint_mirror_source.rb | 2 +- spec/bundler/support/artifice/endpoint_redirect.rb | 2 +- .../endpoint_strict_basic_authentication.rb | 2 +- spec/bundler/support/artifice/endpoint_timeout.rb | 2 +- spec/bundler/support/artifice/vcr.rb | 3 +- spec/bundler/support/artifice/windows.rb | 2 +- spec/bundler/support/command_execution.rb | 5 - spec/bundler/support/filters.rb | 45 ++ spec/bundler/support/helpers.rb | 32 +- spec/bundler/support/matchers.rb | 5 +- spec/bundler/support/path.rb | 4 +- spec/bundler/support/requirement_checker.rb | 19 - spec/bundler/support/rubygems.rb | 7 + spec/bundler/support/rubygems_ext.rb | 41 +- spec/bundler/support/rubygems_version_manager.rb | 127 ++++++ spec/bundler/support/the_bundle.rb | 4 +- 88 files changed, 1291 insertions(+), 1238 deletions(-) create mode 100644 spec/bundler/commands/cache_spec.rb delete mode 100644 spec/bundler/commands/package_spec.rb create mode 100644 spec/bundler/support/filters.rb delete mode 100644 spec/bundler/support/requirement_checker.rb create mode 100644 spec/bundler/support/rubygems.rb create mode 100644 spec/bundler/support/rubygems_version_manager.rb (limited to 'spec') diff --git a/spec/bundler/bundler/bundler_spec.rb b/spec/bundler/bundler/bundler_spec.rb index 74cf7ae05d..247838600b 100644 --- a/spec/bundler/bundler/bundler_spec.rb +++ b/spec/bundler/bundler/bundler_spec.rb @@ -232,16 +232,13 @@ EOF path = "/home/oggy" allow(Bundler.rubygems).to receive(:user_home).and_return(path) allow(File).to receive(:directory?).with(path).and_return false - allow(Etc).to receive(:getlogin).and_return("USER") - allow(Dir).to receive(:tmpdir).and_return("/TMP") - allow(FileTest).to receive(:exist?).with("/TMP/bundler/home").and_return(true) - expect(FileUtils).to receive(:mkpath).with("/TMP/bundler/home/USER") + allow(Bundler).to receive(:tmp).and_return(Pathname.new("/tmp/trulyrandom")) message = < "3" do bundle! "" diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb index 858831c448..47e7a5d3cd 100644 --- a/spec/bundler/bundler/friendly_errors_spec.rb +++ b/spec/bundler/bundler/friendly_errors_spec.rb @@ -94,7 +94,7 @@ RSpec.describe Bundler, "friendly errors" do end it "writes to Bundler.ui.trace" do - expect(Bundler.ui).to receive(:trace).with(orig_error, nil, true) + expect(Bundler.ui).to receive(:trace).with(orig_error) Bundler::FriendlyErrors.log_error(error) end end diff --git a/spec/bundler/bundler/plugin_spec.rb b/spec/bundler/bundler/plugin_spec.rb index eaa0b80905..e0e2e9afdf 100644 --- a/spec/bundler/bundler/plugin_spec.rb +++ b/spec/bundler/bundler/plugin_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../support/streams" + RSpec.describe Bundler::Plugin do Plugin = Bundler::Plugin diff --git a/spec/bundler/bundler/ruby_version_spec.rb b/spec/bundler/bundler/ruby_version_spec.rb index 868d81088d..8c6c071d7f 100644 --- a/spec/bundler/bundler/ruby_version_spec.rb +++ b/spec/bundler/bundler/ruby_version_spec.rb @@ -400,12 +400,20 @@ RSpec.describe "Bundler::RubyVersion and its subclasses" do let(:bundler_system_ruby_version) { subject } around do |example| - begin - old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version") - Bundler::RubyVersion.instance_variable_set("@ruby_version", nil) - example.run - ensure - Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version) + if Bundler::RubyVersion.instance_variable_defined?("@ruby_version") + begin + old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version") + Bundler::RubyVersion.remove_instance_variable("@ruby_version") + example.run + ensure + Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version) + end + else + begin + example.run + ensure + Bundler::RubyVersion.remove_instance_variable("@ruby_version") + end end end diff --git a/spec/bundler/bundler/settings_spec.rb b/spec/bundler/bundler/settings_spec.rb index 7e1dadded7..2a285fdcf3 100644 --- a/spec/bundler/bundler/settings_spec.rb +++ b/spec/bundler/bundler/settings_spec.rb @@ -67,7 +67,7 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow context "when $TMPDIR is not writable" do it "does not raise" do expect(Bundler.rubygems).to receive(:user_home).twice.and_return(nil) - expect(FileUtils).to receive(:mkpath).twice.with(File.join(Dir.tmpdir, "bundler", "home")).and_raise(Errno::EROFS, "Read-only file system @ dir_s_mkdir - /tmp/bundler") + expect(Bundler).to receive(:tmp).twice.and_raise(Errno::EROFS, "Read-only file system @ dir_s_mkdir - /tmp/bundler") expect(subject.send(:global_config_file)).to be_nil end diff --git a/spec/bundler/bundler/shared_helpers_spec.rb b/spec/bundler/bundler/shared_helpers_spec.rb index 0340cb7bae..4530a9a5cd 100644 --- a/spec/bundler/bundler/shared_helpers_spec.rb +++ b/spec/bundler/bundler/shared_helpers_spec.rb @@ -236,7 +236,7 @@ RSpec.describe Bundler::SharedHelpers do shared_examples_for "ENV['RUBYOPT'] gets set correctly" do it "ensures -rbundler/setup is at the beginning of ENV['RUBYOPT']" do subject.set_bundle_environment - expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{lib}/bundler/setup") + expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{lib_dir}/bundler/setup") end end diff --git a/spec/bundler/bundler/source_spec.rb b/spec/bundler/bundler/source_spec.rb index 5b11503d23..0c35c27fdf 100644 --- a/spec/bundler/bundler/source_spec.rb +++ b/spec/bundler/bundler/source_spec.rb @@ -59,7 +59,6 @@ RSpec.describe Bundler::Source do context "with color", :no_color_tty do before do allow($stdout).to receive(:tty?).and_return(true) - Bundler.ui = Bundler::UI::Shell.new end it "should return a string with the spec name and version and locked spec version" do @@ -68,7 +67,11 @@ RSpec.describe Bundler::Source do end context "without color" do - before { Bundler.ui = Bundler::UI::Shell.new("no-color" => true) } + around do |example| + with_ui(Bundler::UI::Shell.new("no-color" => true)) do + example.run + end + end it "should return a string with the spec name and version and locked spec version" do expect(subject.version_message(spec)).to eq("nokogiri >= 1.6 (was < 1.5)") @@ -83,7 +86,6 @@ RSpec.describe Bundler::Source do context "with color", :no_color_tty do before do allow($stdout).to receive(:tty?).and_return(true) - Bundler.ui = Bundler::UI::Shell.new end it "should return a string with the locked spec version in yellow" do @@ -92,7 +94,11 @@ RSpec.describe Bundler::Source do end context "without color" do - before { Bundler.ui = Bundler::UI::Shell.new("no-color" => true) } + around do |example| + with_ui(Bundler::UI::Shell.new("no-color" => true)) do + example.run + end + end it "should return a string with the locked spec version in yellow" do expect(subject.version_message(spec)).to eq("nokogiri 1.6.1 (was 1.7.0)") @@ -107,7 +113,6 @@ RSpec.describe Bundler::Source do context "with color", :no_color_tty do before do allow($stdout).to receive(:tty?).and_return(true) - Bundler.ui = Bundler::UI::Shell.new end it "should return a string with the locked spec version in green" do @@ -116,7 +121,11 @@ RSpec.describe Bundler::Source do end context "without color" do - before { Bundler.ui = Bundler::UI::Shell.new("no-color" => true) } + around do |example| + with_ui(Bundler::UI::Shell.new("no-color" => true)) do + example.run + end + end it "should return a string with the locked spec version in yellow" do expect(subject.version_message(spec)).to eq("nokogiri 1.7.1 (was 1.7.0)") @@ -178,4 +187,14 @@ RSpec.describe Bundler::Source do end end end + +private + + def with_ui(ui) + old_ui = Bundler.ui + Bundler.ui = ui + yield + ensure + Bundler.ui = old_ui + end end diff --git a/spec/bundler/bundler/ui/shell_spec.rb b/spec/bundler/bundler/ui/shell_spec.rb index 632477096e..536014c6aa 100644 --- a/spec/bundler/bundler/ui/shell_spec.rb +++ b/spec/bundler/bundler/ui/shell_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../../support/streams" + RSpec.describe Bundler::UI::Shell do subject { described_class.new } diff --git a/spec/bundler/cache/cache_path_spec.rb b/spec/bundler/cache/cache_path_spec.rb index 1a61494130..12385427b1 100644 --- a/spec/bundler/cache/cache_path_spec.rb +++ b/spec/bundler/cache/cache_path_spec.rb @@ -10,7 +10,7 @@ RSpec.describe "bundle package" do context "with --cache-path" do it "caches gems at given path" do - bundle :package, "cache-path" => "vendor/cache-foo" + bundle :cache, "cache-path" => "vendor/cache-foo" expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist end end @@ -18,14 +18,14 @@ RSpec.describe "bundle package" do context "with config cache_path" do it "caches gems at given path" do bundle "config set cache_path vendor/cache-foo" - bundle :package + bundle :cache expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist end end context "with absolute --cache-path" do it "caches gems at given path" do - bundle :package, "cache-path" => "/tmp/cache-foo" + bundle :cache, "cache-path" => "/tmp/cache-foo" expect(bundled_app("/tmp/cache-foo/rack-1.0.0.gem")).to exist end end diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb index 1cb278e912..75525d405b 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -12,230 +12,228 @@ RSpec.describe "git base name" do end end -%w[cache package].each do |cmd| - RSpec.describe "bundle #{cmd} with git" do - it "copies repository to vendor cache and uses it" do - git = build_git "foo" - ref = git.ref_for("master", 11) - - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist - expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file - - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end - - it "copies repository to vendor cache and uses it even when installed with bundle --path" do - git = build_git "foo" - ref = git.ref_for("master", 11) +RSpec.describe "bundle cache with git" do + it "copies repository to vendor cache and uses it" do + git = build_git "foo" + ref = git.ref_for("master", 11) + + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist + expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file + + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "copies repository to vendor cache and uses it even when installed with bundle --path" do + git = build_git "foo" + ref = git.ref_for("master", 11) - bundle "install --path vendor/bundle" - bundle "config set cache_all true" - bundle cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist + bundle "install --path vendor/bundle" + bundle "config set cache_all true" + bundle :cache - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist - it "runs twice without exploding" do - build_git "foo" + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - install_gemfile! <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "runs twice without exploding" do + build_git "foo" - bundle "config set cache_all true" - bundle! cmd - bundle! cmd + install_gemfile! <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - expect(out).to include "Updating files in vendor/cache" - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end + bundle "config set cache_all true" + bundle! :cache + bundle! :cache - it "tracks updates" do - git = build_git "foo" - old_ref = git.ref_for("master", 11) + expect(out).to include "Updating files in vendor/cache" + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "tracks updates" do + git = build_git "foo" + old_ref = git.ref_for("master", 11) - bundle "config set cache_all true" - bundle cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - update_git "foo" do |s| - s.write "lib/foo.rb", "puts :CACHE" - end + bundle "config set cache_all true" + bundle :cache - ref = git.ref_for("master", 11) - expect(ref).not_to eq(old_ref) + update_git "foo" do |s| + s.write "lib/foo.rb", "puts :CACHE" + end - bundle! "update", :all => true - bundle "config set cache_all true" - bundle! cmd + ref = git.ref_for("master", 11) + expect(ref).not_to eq(old_ref) - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist + bundle! "update", :all => true + bundle "config set cache_all true" + bundle! :cache - FileUtils.rm_rf lib_path("foo-1.0") - run! "require 'foo'" - expect(out).to eq("CACHE") - end + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist - it "tracks updates when specifying the gem" do - git = build_git "foo" - old_ref = git.ref_for("master", 11) + FileUtils.rm_rf lib_path("foo-1.0") + run! "require 'foo'" + expect(out).to eq("CACHE") + end - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "tracks updates when specifying the gem" do + git = build_git "foo" + old_ref = git.ref_for("master", 11) - bundle "config set cache_all true" - bundle! cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - update_git "foo" do |s| - s.write "lib/foo.rb", "puts :CACHE" - end + bundle "config set cache_all true" + bundle! :cache - ref = git.ref_for("master", 11) - expect(ref).not_to eq(old_ref) + update_git "foo" do |s| + s.write "lib/foo.rb", "puts :CACHE" + end - bundle "update foo" + ref = git.ref_for("master", 11) + expect(ref).not_to eq(old_ref) - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist + bundle "update foo" - FileUtils.rm_rf lib_path("foo-1.0") - run "require 'foo'" - expect(out).to eq("CACHE") - end + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist - it "uses the local repository to generate the cache" do - git = build_git "foo" - ref = git.ref_for("master", 11) + FileUtils.rm_rf lib_path("foo-1.0") + run "require 'foo'" + expect(out).to eq("CACHE") + end - gemfile <<-G - gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :master - G + it "uses the local repository to generate the cache" do + git = build_git "foo" + ref = git.ref_for("master", 11) - bundle %(config set local.foo #{lib_path("foo-1.0")}) - bundle "install" - bundle "config set cache_all true" - bundle cmd + gemfile <<-G + gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :master + G - expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist + bundle %(config set local.foo #{lib_path("foo-1.0")}) + bundle "install" + bundle "config set cache_all true" + bundle :cache - # Updating the local still uses the local. - update_git "foo" do |s| - s.write "lib/foo.rb", "puts :LOCAL" - end + expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist - run "require 'foo'" - expect(out).to eq("LOCAL") + # Updating the local still uses the local. + update_git "foo" do |s| + s.write "lib/foo.rb", "puts :LOCAL" end - it "copies repository to vendor cache, including submodules" do - build_git "submodule", "1.0" + run "require 'foo'" + expect(out).to eq("LOCAL") + end - git = build_git "has_submodule", "1.0" do |s| - s.add_dependency "submodule" - end + it "copies repository to vendor cache, including submodules" do + build_git "submodule", "1.0" - 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 = build_git "has_submodule", "1.0" do |s| + s.add_dependency "submodule" + end - install_gemfile <<-G - git "#{lib_path("has_submodule-1.0")}", :submodules => true do - gem "has_submodule" - end - G + 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 + + install_gemfile <<-G + git "#{lib_path("has_submodule-1.0")}", :submodules => true do + gem "has_submodule" + end + G - ref = git.ref_for("master", 11) - bundle "config set cache_all true" - bundle cmd + ref = git.ref_for("master", 11) + bundle "config set cache_all true" + bundle :cache - expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist - expect(the_bundle).to include_gems "has_submodule 1.0" - end + expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist + expect(the_bundle).to include_gems "has_submodule 1.0" + end - it "displays warning message when detecting git repo in Gemfile", :bundler => "< 3" do - build_git "foo" + it "displays warning message when detecting git repo in Gemfile", :bundler => "< 3" do + build_git "foo" - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - bundle cmd + bundle :cache - expect(err).to include("Your Gemfile contains path and git dependencies.") - end + expect(err).to include("Your Gemfile contains path and git dependencies.") + end - it "does not display warning message if cache_all is set in bundle config" do - build_git "foo" + it "does not display warning message if cache_all is set in bundle config" do + build_git "foo" - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - bundle cmd + bundle "config set cache_all true" + bundle :cache + bundle :cache - expect(err).not_to include("Your Gemfile contains path and git dependencies.") - end + expect(err).not_to include("Your Gemfile contains path and git dependencies.") + end - it "caches pre-evaluated gemspecs" do - git = build_git "foo" + it "caches pre-evaluated gemspecs" do + git = build_git "foo" - # Insert a gemspec method that shells out - spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n") - spec_lines.insert(-2, "s.description = `echo bob`") - update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") } + # Insert a gemspec method that shells out + spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n") + spec_lines.insert(-2, "s.description = `echo bob`") + update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") } - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - bundle "config set cache_all true" - bundle cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + bundle "config set cache_all true" + bundle :cache - ref = git.ref_for("master", 11) - gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read - expect(gemspec).to_not match("`echo bob`") - end + ref = git.ref_for("master", 11) + gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read + expect(gemspec).to_not match("`echo bob`") + end - it "can install after #{cmd} with git not installed" do - build_git "foo" + it "can install after bundle cache with git not installed" do + build_git "foo" - gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - bundle! "config set cache_all true" - bundle! cmd, "all-platforms" => true, :install => false, :path => "./vendor/cache" + gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + bundle! "config set cache_all true" + bundle! :cache, "all-platforms" => true, :install => false, :path => "./vendor/cache" - simulate_new_machine - with_path_as "" do - bundle! "config set deployment true" - bundle! :install, :local => true - expect(the_bundle).to include_gem "foo 1.0" - end + simulate_new_machine + with_path_as "" do + bundle! "config set deployment true" + bundle! :install, :local => true + expect(the_bundle).to include_gem "foo 1.0" end end end diff --git a/spec/bundler/cache/path_spec.rb b/spec/bundler/cache/path_spec.rb index 3bbd7b1805..79e8b4a82b 100644 --- a/spec/bundler/cache/path_spec.rb +++ b/spec/bundler/cache/path_spec.rb @@ -1,146 +1,144 @@ # frozen_string_literal: true -%w[cache package].each do |cmd| - RSpec.describe "bundle #{cmd} with path" do - it "is no-op when the path is within the bundle" do - build_lib "foo", :path => bundled_app("lib/foo") - - install_gemfile <<-G - gem "foo", :path => '#{bundled_app("lib/foo")}' - G - - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/foo-1.0")).not_to exist - expect(the_bundle).to include_gems "foo 1.0" - end +RSpec.describe "bundle cache with path" do + it "is no-op when the path is within the bundle" do + build_lib "foo", :path => bundled_app("lib/foo") + + install_gemfile <<-G + gem "foo", :path => '#{bundled_app("lib/foo")}' + G + + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0")).not_to exist + expect(the_bundle).to include_gems "foo 1.0" + end - it "copies when the path is outside the bundle " do - build_lib "foo" + it "copies when the path is outside the bundle " do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/foo-1.0")).to exist - expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0")).to exist + expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - it "copies when the path is outside the bundle and the paths intersect" do - libname = File.basename(Dir.pwd) + "_gem" - libpath = File.join(File.dirname(Dir.pwd), libname) + it "copies when the path is outside the bundle and the paths intersect" do + libname = File.basename(Dir.pwd) + "_gem" + libpath = File.join(File.dirname(Dir.pwd), libname) - build_lib libname, :path => libpath + build_lib libname, :path => libpath - install_gemfile <<-G - gem "#{libname}", :path => '#{libpath}' - G + install_gemfile <<-G + gem "#{libname}", :path => '#{libpath}' + G - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/#{libname}")).to exist - expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/#{libname}")).to exist + expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file - FileUtils.rm_rf libpath - expect(the_bundle).to include_gems "#{libname} 1.0" - end + FileUtils.rm_rf libpath + expect(the_bundle).to include_gems "#{libname} 1.0" + end - it "updates the path on each cache" do - build_lib "foo" + it "updates the path on each cache" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd + bundle "config set cache_all true" + bundle :cache - build_lib "foo" do |s| - s.write "lib/foo.rb", "puts :CACHE" - end + build_lib "foo" do |s| + s.write "lib/foo.rb", "puts :CACHE" + end - bundle cmd + bundle :cache - expect(bundled_app("vendor/cache/foo-1.0")).to exist - FileUtils.rm_rf lib_path("foo-1.0") + expect(bundled_app("vendor/cache/foo-1.0")).to exist + FileUtils.rm_rf lib_path("foo-1.0") - run "require 'foo'" - expect(out).to eq("CACHE") - end + run "require 'foo'" + expect(out).to eq("CACHE") + end - it "removes stale entries cache" do - build_lib "foo" + it "removes stale entries cache" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd + bundle "config set cache_all true" + bundle :cache - install_gemfile <<-G - gem "bar", :path => '#{lib_path("bar-1.0")}' - G + install_gemfile <<-G + gem "bar", :path => '#{lib_path("bar-1.0")}' + G - bundle cmd - expect(bundled_app("vendor/cache/bar-1.0")).not_to exist - end + bundle :cache + expect(bundled_app("vendor/cache/bar-1.0")).not_to exist + end - it "raises a warning without --all", :bundler => "< 3" do - build_lib "foo" + it "raises a warning without --all", :bundler => "< 3" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle cmd - expect(err).to match(/please pass the \-\-all flag/) - expect(bundled_app("vendor/cache/foo-1.0")).not_to exist - end + bundle :cache + expect(err).to match(/please pass the \-\-all flag/) + expect(bundled_app("vendor/cache/foo-1.0")).not_to exist + end - it "stores the given flag" do - build_lib "foo" + it "stores the given flag" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - build_lib "bar" + bundle "config set cache_all true" + bundle :cache + build_lib "bar" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - gem "bar", :path => '#{lib_path("bar-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + gem "bar", :path => '#{lib_path("bar-1.0")}' + G - bundle cmd - expect(bundled_app("vendor/cache/bar-1.0")).to exist - end + bundle :cache + expect(bundled_app("vendor/cache/bar-1.0")).to exist + end - it "can rewind chosen configuration" do - build_lib "foo" + it "can rewind chosen configuration" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - build_lib "baz" + bundle "config set cache_all true" + bundle :cache + build_lib "baz" - gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - gem "baz", :path => '#{lib_path("baz-1.0")}' - G + gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + gem "baz", :path => '#{lib_path("baz-1.0")}' + G - bundle "#{cmd} --no-all" - expect(bundled_app("vendor/cache/baz-1.0")).not_to exist - end + bundle "cache --no-all" + expect(bundled_app("vendor/cache/baz-1.0")).not_to exist end end diff --git a/spec/bundler/commands/add_spec.rb b/spec/bundler/commands/add_spec.rb index fdfca5d8f2..35fd43d3d2 100644 --- a/spec/bundler/commands/add_spec.rb +++ b/spec/bundler/commands/add_spec.rb @@ -239,4 +239,13 @@ RSpec.describe "bundle add" do expect(err).not_to include("You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end end + + describe "when a gem is added and cache exists" do + it "caches all new dependencies added for the specified gem" do + bundle! :cache + + bundle "add 'rack' --version=1.0.0" + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + end + end end diff --git a/spec/bundler/commands/cache_spec.rb b/spec/bundler/commands/cache_spec.rb new file mode 100644 index 0000000000..07ec186c2f --- /dev/null +++ b/spec/bundler/commands/cache_spec.rb @@ -0,0 +1,351 @@ +# frozen_string_literal: true + +RSpec.describe "bundle cache" do + context "with --gemfile" do + it "finds the gemfile" do + gemfile bundled_app("NotGemfile"), <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + G + + bundle "cache --gemfile=NotGemfile" + + ENV["BUNDLE_GEMFILE"] = "NotGemfile" + expect(the_bundle).to include_gems "rack 1.0.0" + end + end + + context "with --all" do + context "without a gemspec" do + it "caches all dependencies except bundler itself" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gem 'bundler' + D + + bundle "config set cache_all true" + bundle :cache + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end + + context "with a gemspec" do + context "that has the same name as the gem" do + before do + File.open(bundled_app("mygem.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "nokogiri", "=1.4.2" + end + G + end + end + + it "caches all dependencies except bundler and the gemspec specified gem" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gemspec + D + + bundle "config set cache_all true" + bundle! :cache + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist + expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end + + context "that has a different name as the gem" do + before do + File.open(bundled_app("mygem_diffname.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "nokogiri", "=1.4.2" + end + G + end + end + + it "caches all dependencies except bundler and the gemspec specified gem" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gemspec + D + + bundle "config set cache_all true" + bundle! :cache + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist + expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end + end + + context "with multiple gemspecs" do + before do + File.open(bundled_app("mygem.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "nokogiri", "=1.4.2" + end + G + end + File.open(bundled_app("mygem_client.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem_test" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "weakling", "=0.0.3" + end + G + end + end + + it "caches all dependencies except bundler and the gemspec specified gems" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gemspec :name => 'mygem' + gemspec :name => 'mygem_test' + D + + bundle "config set cache_all true" + bundle! :cache + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist + expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist + expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/mygem_test-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end + end + + context "with --path", :bundler => "< 3" do + it "sets root directory for gems" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + D + + bundle! :cache, forgotten_command_line_options(:path => bundled_app("test")) + + expect(the_bundle).to include_gems "rack 1.0.0" + expect(bundled_app("test/vendor/cache/")).to exist + end + end + + context "with --no-install" do + it "puts the gems in vendor/cache but does not install them" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + D + + bundle! "cache --no-install" + + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + end + + it "does not prevent installing gems with bundle install" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + D + + bundle! "cache --no-install" + bundle! "install" + + expect(the_bundle).to include_gems "rack 1.0.0" + end + + it "does not prevent installing gems with bundle update" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem "rack", "1.0.0" + D + + bundle! "cache --no-install" + bundle! "update --all" + + expect(the_bundle).to include_gems "rack 1.0.0" + end + end + + context "with --all-platforms" do + it "puts the gems in vendor/cache even for other rubies" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack', :platforms => :ruby_19 + D + + bundle "cache --all-platforms" + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + end + + it "does not attempt to install gems in without groups" do + build_repo4 do + build_gem "uninstallable", "2.0" do |s| + s.add_development_dependency "rake" + s.extensions << "Rakefile" + s.write "Rakefile", "task(:default) { raise 'CANNOT INSTALL' }" + end + end + + install_gemfile! <<-G, forgotten_command_line_options(:without => "wo") + source "file:#{gem_repo1}" + gem "rack" + group :wo do + gem "weakling" + gem "uninstallable", :source => "file:#{gem_repo4}" + end + G + + bundle! :cache, "all-platforms" => true + expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist + expect(bundled_app("vendor/cache/uninstallable-2.0.gem")).to exist + expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gems "weakling", "uninstallable" + + bundle! :install, forgotten_command_line_options(:without => "wo") + expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gems "weakling", "uninstallable" + end + end + + context "with --frozen" do + before do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + bundle "install" + end + + subject { bundle :cache, forgotten_command_line_options(:frozen => true) } + + it "tries to install with frozen" do + bundle! "config set deployment true" + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + gem "rack-obama" + G + subject + expect(exitstatus).to eq(16) if exitstatus + expect(err).to include("deployment mode") + expect(err).to include("You have added to the Gemfile") + expect(err).to include("* rack-obama") + bundle "env" + expect(out).to include("frozen").or include("deployment") + end + end +end + +RSpec.describe "bundle install with gem sources" do + describe "when cached and locked" do + it "does not hit the remote at all" do + build_repo2 + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "rack" + G + + bundle :cache + simulate_new_machine + FileUtils.rm_rf gem_repo2 + + bundle "install --local" + expect(the_bundle).to include_gems "rack 1.0.0" + end + + it "does not hit the remote at all" do + build_repo2 + install_gemfile! <<-G + source "#{file_uri_for(gem_repo2)}" + gem "rack" + G + + bundle! :cache + simulate_new_machine + FileUtils.rm_rf gem_repo2 + + bundle! :install, forgotten_command_line_options(:deployment => true, :path => "vendor/bundle") + expect(the_bundle).to include_gems "rack 1.0.0" + end + + it "does not reinstall already-installed gems" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + bundle :cache + + build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s| + s.write "lib/rack.rb", "raise 'omg'" + end + + bundle :install + expect(err).to be_empty + expect(the_bundle).to include_gems "rack 1.0" + end + + it "ignores cached gems for the wrong platform" do + simulate_platform "java" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "platform_specific" + G + bundle :cache + end + + simulate_new_machine + + simulate_platform "ruby" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "platform_specific" + G + run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" + expect(out).to eq("1.0.0 RUBY") + end + end + + it "does not update the cache if --no-cache is passed" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + bundled_app("vendor/cache").mkpath + expect(bundled_app("vendor/cache").children).to be_empty + + bundle "install --no-cache" + expect(bundled_app("vendor/cache").children).to be_empty + end + end +end diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index cf76d3fb93..7ae504d360 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -89,7 +89,7 @@ RSpec.describe "bundle exec" do else require 'tempfile' io = Tempfile.new("io-test-fd") - args = %W[#{Gem.ruby} -I#{lib} #{bindir.join("bundle")} exec --keep-file-descriptors #{Gem.ruby} #{command.path} \#{io.to_i}] + args = %W[#{Gem.ruby} -I#{lib_dir} #{bindir.join("bundle")} exec --keep-file-descriptors #{Gem.ruby} #{command.path} \#{io.to_i}] args << { io.to_i => io } exec(*args) end @@ -279,7 +279,7 @@ RSpec.describe "bundle exec" do G rubyopt = ENV["RUBYOPT"] - rubyopt = "-r#{lib}/bundler/setup #{rubyopt}" + rubyopt = "-r#{lib_dir}/bundler/setup #{rubyopt}" bundle "exec 'echo $RUBYOPT'" expect(out).to have_rubyopts(rubyopt) @@ -294,7 +294,7 @@ RSpec.describe "bundle exec" do G rubylib = ENV["RUBYLIB"] - rubylib = rubylib.to_s.split(File::PATH_SEPARATOR).unshift lib.to_s + rubylib = rubylib.to_s.split(File::PATH_SEPARATOR).unshift lib_dir.to_s rubylib = rubylib.uniq.join(File::PATH_SEPARATOR) bundle "exec 'echo $RUBYLIB'" diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index 32c1868cd2..708b41f623 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -1,22 +1,20 @@ # frozen_string_literal: true RSpec.describe "bundle gem" do - def execute_bundle_gem(gem_name, flag = "") - bundle! "gem #{gem_name} #{flag}" - # reset gemspec cache for each test because of commit 3d4163a - Bundler.clear_gemspec_cache - end - - def gem_skeleton_assertions(gem_name) + def gem_skeleton_assertions expect(bundled_app("#{gem_name}/#{gem_name}.gemspec")).to exist expect(bundled_app("#{gem_name}/README.md")).to exist expect(bundled_app("#{gem_name}/Gemfile")).to exist expect(bundled_app("#{gem_name}/Rakefile")).to exist - expect(bundled_app("#{gem_name}/lib/test/gem.rb")).to exist - expect(bundled_app("#{gem_name}/lib/test/gem/version.rb")).to exist + expect(bundled_app("#{gem_name}/lib/#{require_path}.rb")).to exist + expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb")).to exist end - let(:generated_gemspec) { Bundler::GemHelper.new(bundled_app(gem_name).to_s).gemspec } + let(:generated_gemspec) { Bundler.load_gemspec_uncached(bundled_app(gem_name).join("#{gem_name}.gemspec")) } + + let(:gem_name) { "mygem" } + + let(:require_path) { "mygem" } before do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" @@ -28,7 +26,7 @@ RSpec.describe "bundle gem" do user = bundleuser EOF @git_config_location = ENV["GIT_CONFIG"] - path = "#{File.expand_path(tmp, File.dirname(__FILE__))}/test_git_config.txt" + path = "#{tmp}/test_git_config.txt" File.open(path, "w") {|f| f.write(git_config_content) } ENV["GIT_CONFIG"] = path end @@ -61,15 +59,14 @@ RSpec.describe "bundle gem" do end describe "git repo initialization" do - let(:gem_name) { "test-gem" } - shared_examples_for "a gem with an initial git repo" do before do - execute_bundle_gem(gem_name, flags) + bundle! "gem #{gem_name} #{flags}" end + it "generates a gem skeleton with a .git folder" do - gem_skeleton_assertions(gem_name) - expect(bundled_app("test-gem/.git")).to exist + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/.git")).to exist end end @@ -87,111 +84,104 @@ RSpec.describe "bundle gem" do context "when passing --no-git" do before do - execute_bundle_gem(gem_name, "--no-git") + bundle! "gem #{gem_name} --no-git" end it "generates a gem skeleton without a .git folder" do - gem_skeleton_assertions(gem_name) - expect(bundled_app("test-gem/.git")).not_to exist + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/.git")).not_to exist end end end shared_examples_for "--mit flag" do before do - execute_bundle_gem(gem_name, "--mit") + bundle! "gem #{gem_name} --mit" end it "generates a gem skeleton with MIT license" do - gem_skeleton_assertions(gem_name) - expect(bundled_app("test-gem/LICENSE.txt")).to exist - skel = Bundler::GemHelper.new(bundled_app(gem_name).to_s) - expect(skel.gemspec.license).to eq("MIT") + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/LICENSE.txt")).to exist + expect(generated_gemspec.license).to eq("MIT") end end shared_examples_for "--no-mit flag" do before do - execute_bundle_gem(gem_name, "--no-mit") + bundle! "gem #{gem_name} --no-mit" end it "generates a gem skeleton without MIT license" do - gem_skeleton_assertions(gem_name) - expect(bundled_app("test-gem/LICENSE.txt")).to_not exist + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/LICENSE.txt")).to_not exist end end shared_examples_for "--coc flag" do before do - execute_bundle_gem(gem_name, "--coc") + bundle! "gem #{gem_name} --coc" end it "generates a gem skeleton with MIT license" do - gem_skeleton_assertions(gem_name) - expect(bundled_app("test-gem/CODE_OF_CONDUCT.md")).to exist + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/CODE_OF_CONDUCT.md")).to exist end describe "README additions" do it "generates the README with a section for the Code of Conduct" do - expect(bundled_app("test-gem/README.md").read).to include("## Code of Conduct") - expect(bundled_app("test-gem/README.md").read).to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md") + expect(bundled_app("#{gem_name}/README.md").read).to include("## Code of Conduct") + expect(bundled_app("#{gem_name}/README.md").read).to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md") end end end shared_examples_for "--no-coc flag" do before do - execute_bundle_gem(gem_name, "--no-coc") + bundle! "gem #{gem_name} --no-coc" end it "generates a gem skeleton without Code of Conduct" do - gem_skeleton_assertions(gem_name) - expect(bundled_app("test-gem/CODE_OF_CONDUCT.md")).to_not exist + gem_skeleton_assertions + expect(bundled_app("#{gem_name}/CODE_OF_CONDUCT.md")).to_not exist end describe "README additions" do it "generates the README without a section for the Code of Conduct" do - expect(bundled_app("test-gem/README.md").read).not_to include("## Code of Conduct") - expect(bundled_app("test-gem/README.md").read).not_to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md") + expect(bundled_app("#{gem_name}/README.md").read).not_to include("## Code of Conduct") + expect(bundled_app("#{gem_name}/README.md").read).not_to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md") end end end context "README.md" do - let(:gem_name) { "test_gem" } - context "git config github.user present" do before do - execute_bundle_gem(gem_name) + bundle! "gem #{gem_name}" end it "contribute URL set to git username" do - expect(bundled_app("test_gem/README.md").read).not_to include("[USERNAME]") - expect(bundled_app("test_gem/README.md").read).to include("github.com/bundleuser") + expect(bundled_app("#{gem_name}/README.md").read).not_to include("[USERNAME]") + expect(bundled_app("#{gem_name}/README.md").read).to include("github.com/bundleuser") end end context "git config github.user is absent" do before do sys_exec("git config --unset github.user") - in_app_root bundle "gem #{gem_name}" end it "contribute URL set to [USERNAME]" do - expect(bundled_app("test_gem/README.md").read).to include("[USERNAME]") - expect(bundled_app("test_gem/README.md").read).not_to include("github.com/bundleuser") + expect(bundled_app("#{gem_name}/README.md").read).to include("[USERNAME]") + expect(bundled_app("#{gem_name}/README.md").read).not_to include("github.com/bundleuser") end end end it "creates a new git repository" do - in_app_root - bundle "gem test_gem" - expect(bundled_app("test_gem/.git")).to exist + bundle "gem #{gem_name}" + expect(bundled_app("#{gem_name}/.git")).to exist end context "when git is not available" do - let(:gem_name) { "test_gem" } - # This spec cannot have `git` available in the test env before do - load_paths = [lib, spec] + load_paths = [lib_dir, spec_dir] load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}" sys_exec "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", "PATH" => "" @@ -211,7 +201,6 @@ RSpec.describe "bundle gem" do end it "generates a valid gemspec" do - in_app_root bundle! "gem newgem --bin" prepare_gemspec(bundled_app("newgem", "newgem.gemspec")) @@ -226,10 +215,6 @@ RSpec.describe "bundle gem" do end context "gem naming with relative paths" do - before do - in_app_root - end - it "resolves ." do create_temporary_dir("tmp") @@ -260,43 +245,41 @@ RSpec.describe "bundle gem" do end end - context "gem naming with underscore" do - let(:gem_name) { "test_gem" } - - before do - execute_bundle_gem(gem_name) - end - + shared_examples_for "generating a gem" do it "generates a gem skeleton" do - expect(bundled_app("test_gem/test_gem.gemspec")).to exist - expect(bundled_app("test_gem/Gemfile")).to exist - expect(bundled_app("test_gem/Rakefile")).to exist - expect(bundled_app("test_gem/lib/test_gem.rb")).to exist - expect(bundled_app("test_gem/lib/test_gem/version.rb")).to exist - expect(bundled_app("test_gem/.gitignore")).to exist + bundle! "gem #{gem_name}" + + expect(bundled_app("#{gem_name}/#{gem_name}.gemspec")).to exist + expect(bundled_app("#{gem_name}/Gemfile")).to exist + expect(bundled_app("#{gem_name}/Rakefile")).to exist + expect(bundled_app("#{gem_name}/lib/#{require_path}.rb")).to exist + expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb")).to exist + expect(bundled_app("#{gem_name}/.gitignore")).to exist - expect(bundled_app("test_gem/bin/setup")).to exist - expect(bundled_app("test_gem/bin/console")).to exist - expect(bundled_app("test_gem/bin/setup")).to be_executable - expect(bundled_app("test_gem/bin/console")).to be_executable + expect(bundled_app("#{gem_name}/bin/setup")).to exist + expect(bundled_app("#{gem_name}/bin/console")).to exist + expect(bundled_app("#{gem_name}/bin/setup")).to be_executable + expect(bundled_app("#{gem_name}/bin/console")).to be_executable end it "starts with version 0.1.0" do - expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/VERSION = "0.1.0"/) - end + bundle! "gem #{gem_name}" - it "does not nest constants" do - expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/module TestGem/) - expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/module TestGem/) + expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/VERSION = "0.1.0"/) end - it_should_behave_like "git config is present" + context "git config user.{name,email} is set" do + before do + bundle! "gem #{gem_name}" + end + + it_should_behave_like "git config is present" + end context "git config user.{name,email} is not set" do before do `git config --unset user.name` `git config --unset user.email` - in_app_root bundle "gem #{gem_name}" end @@ -304,25 +287,35 @@ RSpec.describe "bundle gem" do end it "sets gemspec metadata['allowed_push_host']" do + bundle! "gem #{gem_name}" + expect(generated_gemspec.metadata["allowed_push_host"]). to match(/mygemserver\.com/) end it "sets a minimum ruby version" do + bundle! "gem #{gem_name}" + bundler_gemspec = Bundler::GemHelper.new(gemspec_dir).gemspec expect(bundler_gemspec.required_ruby_version).to eq(generated_gemspec.required_ruby_version) end it "requires the version file" do - expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(%r{require "test_gem/version"}) + bundle! "gem #{gem_name}" + + expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(%r{require "#{require_path}/version"}) end it "creates a base error class" do - expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/class Error < StandardError; end$/) + bundle! "gem #{gem_name}" + + expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/class Error < StandardError; end$/) end it "runs rake without problems" do + bundle! "gem #{gem_name}" + system_gems ["rake-12.3.2"] rakefile = strip_whitespace <<-RAKEFILE @@ -330,7 +323,7 @@ RSpec.describe "bundle gem" do puts 'SUCCESS' end RAKEFILE - File.open(bundled_app("test_gem/Rakefile"), "w") do |file| + File.open(bundled_app("#{gem_name}/Rakefile"), "w") do |file| file.puts rakefile end @@ -342,117 +335,110 @@ RSpec.describe "bundle gem" do context "--exe parameter set" do before do - in_app_root bundle "gem #{gem_name} --exe" end it "builds exe skeleton" do - expect(bundled_app("test_gem/exe/test_gem")).to exist + expect(bundled_app("#{gem_name}/exe/#{gem_name}")).to exist end - it "requires 'test-gem'" do - expect(bundled_app("test_gem/exe/test_gem").read).to match(/require "test_gem"/) + it "requires the main file" do + expect(bundled_app("#{gem_name}/exe/#{gem_name}").read).to match(/require "#{require_path}"/) end end context "--bin parameter set" do before do - in_app_root bundle "gem #{gem_name} --bin" end it "builds exe skeleton" do - expect(bundled_app("test_gem/exe/test_gem")).to exist + expect(bundled_app("#{gem_name}/exe/#{gem_name}")).to exist end - it "requires 'test-gem'" do - expect(bundled_app("test_gem/exe/test_gem").read).to match(/require "test_gem"/) + it "requires the main file" do + expect(bundled_app("#{gem_name}/exe/#{gem_name}").read).to match(/require "#{require_path}"/) end end context "no --test parameter" do before do - in_app_root bundle "gem #{gem_name}" end it "doesn't create any spec/test file" do - expect(bundled_app("test_gem/.rspec")).to_not exist - expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to_not exist - expect(bundled_app("test_gem/spec/spec_helper.rb")).to_not exist - expect(bundled_app("test_gem/test/test_test_gem.rb")).to_not exist - expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist + expect(bundled_app("#{gem_name}/.rspec")).to_not exist + expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to_not exist + expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to_not exist + expect(bundled_app("#{gem_name}/test/#{require_path}.rb")).to_not exist + expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist end end context "--test parameter set to rspec" do before do - in_app_root bundle "gem #{gem_name} --test=rspec" end it "builds spec skeleton" do - expect(bundled_app("test_gem/.rspec")).to exist - expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist - expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist + expect(bundled_app("#{gem_name}/.rspec")).to exist + expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to exist + expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist end it "depends on a specific version of rspec in generated Gemfile" do - Dir.chdir(bundled_app("test_gem")) do + Dir.chdir(bundled_app(gem_name)) do builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("test_gem/Gemfile")) + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) builder.dependencies rspec_dep = builder.dependencies.find {|d| d.name == "rspec" } expect(rspec_dep).to be_specific end end - it "requires 'test-gem'" do - expect(bundled_app("test_gem/spec/spec_helper.rb").read).to include(%(require "test_gem")) + it "requires the main file" do + expect(bundled_app("#{gem_name}/spec/spec_helper.rb").read).to include(%(require "#{require_path}")) end it "creates a default test which fails" do - expect(bundled_app("test_gem/spec/test_gem_spec.rb").read).to include("expect(false).to eq(true)") + expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb").read).to include("expect(false).to eq(true)") end end context "gem.test setting set to rspec" do before do - in_app_root bundle "config set gem.test rspec" bundle "gem #{gem_name}" end it "builds spec skeleton" do - expect(bundled_app("test_gem/.rspec")).to exist - expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist - expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist + expect(bundled_app("#{gem_name}/.rspec")).to exist + expect(bundled_app("#{gem_name}/spec/#{require_path}_spec.rb")).to exist + expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist end end context "gem.test setting set to rspec and --test is set to minitest" do before do - in_app_root bundle "config set gem.test rspec" bundle "gem #{gem_name} --test=minitest" end it "builds spec skeleton" do - expect(bundled_app("test_gem/test/test_gem_test.rb")).to exist - expect(bundled_app("test_gem/test/test_helper.rb")).to exist + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist + expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist end end context "--test parameter set to minitest" do before do - in_app_root bundle "gem #{gem_name} --test=minitest" end it "depends on a specific version of minitest" do - Dir.chdir(bundled_app("test_gem")) do + Dir.chdir(bundled_app(gem_name)) do builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("test_gem/Gemfile")) + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) builder.dependencies minitest_dep = builder.dependencies.find {|d| d.name == "minitest" } expect(minitest_dep).to be_specific @@ -460,26 +446,25 @@ RSpec.describe "bundle gem" do end it "builds spec skeleton" do - expect(bundled_app("test_gem/test/test_gem_test.rb")).to exist - expect(bundled_app("test_gem/test/test_helper.rb")).to exist + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb")).to exist + expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist end - it "requires 'test-gem'" do - expect(bundled_app("test_gem/test/test_helper.rb").read).to include(%(require "test_gem")) + it "requires the main file" do + expect(bundled_app("#{gem_name}/test/test_helper.rb").read).to include(%(require "#{require_path}")) end it "requires 'minitest_helper'" do - expect(bundled_app("test_gem/test/test_gem_test.rb").read).to include(%(require "test_helper")) + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include(%(require "test_helper")) end it "creates a default test which fails" do - expect(bundled_app("test_gem/test/test_gem_test.rb").read).to include("assert false") + expect(bundled_app("#{gem_name}/test/#{require_path}_test.rb").read).to include("assert false") end end context "gem.test setting set to minitest" do before do - in_app_root bundle "config set gem.test minitest" bundle "gem #{gem_name}" end @@ -498,29 +483,27 @@ RSpec.describe "bundle gem" do task :default => :test RAKEFILE - expect(bundled_app("test_gem/Rakefile").read).to eq(rakefile) + expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile) end end context "--test with no arguments" do before do - in_app_root bundle "gem #{gem_name} --test" end it "defaults to rspec" do - expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist - expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist + expect(bundled_app("#{gem_name}/spec/spec_helper.rb")).to exist + expect(bundled_app("#{gem_name}/test/minitest_helper.rb")).to_not exist end it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do - expect(bundled_app("test_gem/.travis.yml").read).to match(/- #{RUBY_VERSION}/) + expect(bundled_app("#{gem_name}/.travis.yml").read).to match(/- #{RUBY_VERSION}/) end end context "--edit option" do it "opens the generated gemspec in the user's text editor" do - in_app_root output = bundle "gem #{gem_name} --edit=echo" gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec") expect(output).to include("echo \"#{gemspec_path}\"") @@ -531,6 +514,8 @@ RSpec.describe "bundle gem" do context "testing --mit and --coc options against bundle config settings" do let(:gem_name) { "test-gem" } + let(:require_path) { "test/gem" } + context "with mit option in bundle config settings set to true" do before do global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" @@ -558,196 +543,35 @@ RSpec.describe "bundle gem" do end end - context "gem naming with dashed" do - let(:gem_name) { "test-gem" } - - before do - execute_bundle_gem(gem_name) - end - - it "generates a gem skeleton" do - expect(bundled_app("test-gem/test-gem.gemspec")).to exist - expect(bundled_app("test-gem/Gemfile")).to exist - expect(bundled_app("test-gem/Rakefile")).to exist - expect(bundled_app("test-gem/lib/test/gem.rb")).to exist - expect(bundled_app("test-gem/lib/test/gem/version.rb")).to exist - end - - it "starts with version 0.1.0" do - expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/VERSION = "0.1.0"/) - end - - it "nests constants so they work" do - expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/module Test\n module Gem/) - expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/module Test\n module Gem/) - end - - it_should_behave_like "git config is present" - - context "git config user.{name,email} is not set" do - before do - `git config --unset user.name` - `git config --unset user.email` - in_app_root - bundle "gem #{gem_name}" - end - - it_should_behave_like "git config is absent" - end - - it "requires the version file" do - expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(%r{require "test/gem/version"}) - end - - it "runs rake without problems" do - system_gems ["rake-12.3.2"] - - rakefile = strip_whitespace <<-RAKEFILE - task :default do - puts 'SUCCESS' - end - RAKEFILE - File.open(bundled_app("test-gem/Rakefile"), "w") do |file| - file.puts rakefile - end - - Dir.chdir(bundled_app(gem_name)) do - sys_exec(rake) - expect(out).to include("SUCCESS") - end - end - - context "--bin parameter set" do - before do - in_app_root - bundle "gem #{gem_name} --bin" - end - - it "builds bin skeleton" do - expect(bundled_app("test-gem/exe/test-gem")).to exist - end - - it "requires 'test/gem'" do - expect(bundled_app("test-gem/exe/test-gem").read).to match(%r{require "test/gem"}) - end - end - - context "no --test parameter" do - before do - in_app_root - bundle "gem #{gem_name}" - end - - it "doesn't create any spec/test file" do - expect(bundled_app("test-gem/.rspec")).to_not exist - expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to_not exist - expect(bundled_app("test-gem/spec/spec_helper.rb")).to_not exist - expect(bundled_app("test-gem/test/test_test/gem.rb")).to_not exist - expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist - end - end - - context "--test parameter set to rspec" do - before do - in_app_root - bundle "gem #{gem_name} --test=rspec" - end - - it "builds spec skeleton" do - expect(bundled_app("test-gem/.rspec")).to exist - expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to exist - expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist - end - - it "requires 'test/gem'" do - expect(bundled_app("test-gem/spec/spec_helper.rb").read).to include(%(require "test/gem")) - end - - it "creates a default test which fails" do - expect(bundled_app("test-gem/spec/test/gem_spec.rb").read).to include("expect(false).to eq(true)") - end - - it "creates a default rake task to run the specs" do - rakefile = strip_whitespace <<-RAKEFILE - require "bundler/gem_tasks" - require "rspec/core/rake_task" + context "gem naming with underscore" do + let(:gem_name) { "test_gem" } - RSpec::Core::RakeTask.new(:spec) + let(:require_path) { "test_gem" } - task :default => :spec - RAKEFILE + let(:flags) { nil } - expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile) - end + before do + bundle! ["gem", gem_name, flags].compact.join(" ") end - context "--test parameter set to minitest" do - before do - in_app_root - bundle "gem #{gem_name} --test=minitest" - end - - it "builds spec skeleton" do - expect(bundled_app("test-gem/test/test/gem_test.rb")).to exist - expect(bundled_app("test-gem/test/test_helper.rb")).to exist - end - - it "requires 'test/gem'" do - expect(bundled_app("test-gem/test/test_helper.rb").read).to match(%r{require "test/gem"}) - end - - it "requires 'test_helper'" do - expect(bundled_app("test-gem/test/test/gem_test.rb").read).to match(/require "test_helper"/) - end - - it "creates a default test which fails" do - expect(bundled_app("test-gem/test/test/gem_test.rb").read).to match(/assert false/) - end - - it "creates a default rake task to run the test suite" do - rakefile = strip_whitespace <<-RAKEFILE - require "bundler/gem_tasks" - require "rake/testtask" - - Rake::TestTask.new(:test) do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/*_test.rb"] - end - - task :default => :test - RAKEFILE - - expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile) - end + it "does not nest constants" do + expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module TestGem/) + expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/module TestGem/) end - context "--test with no arguments" do - before do - in_app_root - bundle "gem #{gem_name} --test" - end - - it "defaults to rspec" do - expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist - expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist - end - end + include_examples "generating a gem" context "--ext parameter set" do - before do - in_app_root - bundle "gem test_gem --ext" - end + let(:flags) { "--ext" } it "builds ext skeleton" do - expect(bundled_app("test_gem/ext/test_gem/extconf.rb")).to exist - expect(bundled_app("test_gem/ext/test_gem/test_gem.h")).to exist - expect(bundled_app("test_gem/ext/test_gem/test_gem.c")).to exist + expect(bundled_app("#{gem_name}/ext/#{gem_name}/extconf.rb")).to exist + expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.h")).to exist + expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c")).to exist end it "includes rake-compiler" do - expect(bundled_app("test_gem/Gemfile").read).to include('gem "rake-compiler"') + expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"') end it "depends on compile task for build" do @@ -757,21 +581,38 @@ RSpec.describe "bundle gem" do task :build => :compile - Rake::ExtensionTask.new("test_gem") do |ext| - ext.lib_dir = "lib/test_gem" + Rake::ExtensionTask.new("#{gem_name}") do |ext| + ext.lib_dir = "lib/#{gem_name}" end task :default => [:clobber, :compile, :spec] RAKEFILE - expect(bundled_app("test_gem/Rakefile").read).to eq(rakefile) + expect(bundled_app("#{gem_name}/Rakefile").read).to eq(rakefile) end end end + context "gem naming with dashed" do + let(:gem_name) { "test-gem" } + + let(:require_path) { "test/gem" } + + before do + bundle! "gem #{gem_name}" + end + + it "nests constants so they work" do + expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module Test\n module Gem/) + expect(bundled_app("#{gem_name}/lib/#{require_path}.rb").read).to match(/module Test\n module Gem/) + end + + include_examples "generating a gem" + end + describe "uncommon gem names" do it "can deal with two dashes" do - execute_bundle_gem("a--a") + bundle! "gem a--a" expect(bundled_app("a--a/a--a.gemspec")).to exist end @@ -804,9 +645,6 @@ Usage: "bundle gem NAME [OPTIONS]" before do bundle "gem #{subject}" end - after do - Bundler.clear_gemspec_cache - end context "with an existing const name" do subject { "gem" } @@ -830,10 +668,6 @@ Usage: "bundle gem NAME [OPTIONS]" end context "on first run" do - before do - in_app_root - end - it "asks about test framework" do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false" @@ -880,9 +714,7 @@ Usage: "bundle gem NAME [OPTIONS]" context "on conflicts with a previously created file" do it "should fail gracefully" do - in_app_root do - FileUtils.touch("conflict-foobar") - end + FileUtils.touch("conflict-foobar") bundle "gem conflict-foobar" expect(err).to include("Errno::ENOTDIR") expect(exitstatus).to eql(32) if exitstatus @@ -891,9 +723,7 @@ Usage: "bundle gem NAME [OPTIONS]" context "on conflicts with a previously created directory" do it "should succeed" do - in_app_root do - FileUtils.mkdir_p("conflict-foobar/Gemfile") - end + FileUtils.mkdir_p("conflict-foobar/Gemfile") bundle! "gem conflict-foobar" expect(out).to include("file_clash conflict-foobar/Gemfile"). and include "Initializing git repo in #{bundled_app("conflict-foobar")}" diff --git a/spec/bundler/commands/package_spec.rb b/spec/bundler/commands/package_spec.rb deleted file mode 100644 index da22c002eb..0000000000 --- a/spec/bundler/commands/package_spec.rb +++ /dev/null @@ -1,351 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "bundle package" do - context "with --gemfile" do - it "finds the gemfile" do - gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - G - - bundle "package --gemfile=NotGemfile" - - ENV["BUNDLE_GEMFILE"] = "NotGemfile" - expect(the_bundle).to include_gems "rack 1.0.0" - end - end - - context "with --all" do - context "without a gemspec" do - it "caches all dependencies except bundler itself" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gem 'bundler' - D - - bundle "config set cache_all true" - bundle :package - - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - end - end - - context "with a gemspec" do - context "that has the same name as the gem" do - before do - File.open(bundled_app("mygem.gemspec"), "w") do |f| - f.write <<-G - Gem::Specification.new do |s| - s.name = "mygem" - s.version = "0.1.1" - s.summary = "" - s.authors = ["gem author"] - s.add_development_dependency "nokogiri", "=1.4.2" - end - G - end - end - - it "caches all dependencies except bundler and the gemspec specified gem" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gemspec - D - - bundle "config set cache_all true" - bundle! :package - - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist - expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - end - end - - context "that has a different name as the gem" do - before do - File.open(bundled_app("mygem_diffname.gemspec"), "w") do |f| - f.write <<-G - Gem::Specification.new do |s| - s.name = "mygem" - s.version = "0.1.1" - s.summary = "" - s.authors = ["gem author"] - s.add_development_dependency "nokogiri", "=1.4.2" - end - G - end - end - - it "caches all dependencies except bundler and the gemspec specified gem" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gemspec - D - - bundle "config set cache_all true" - bundle! :package - - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist - expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - end - end - end - - context "with multiple gemspecs" do - before do - File.open(bundled_app("mygem.gemspec"), "w") do |f| - f.write <<-G - Gem::Specification.new do |s| - s.name = "mygem" - s.version = "0.1.1" - s.summary = "" - s.authors = ["gem author"] - s.add_development_dependency "nokogiri", "=1.4.2" - end - G - end - File.open(bundled_app("mygem_client.gemspec"), "w") do |f| - f.write <<-G - Gem::Specification.new do |s| - s.name = "mygem_test" - s.version = "0.1.1" - s.summary = "" - s.authors = ["gem author"] - s.add_development_dependency "weakling", "=0.0.3" - end - G - end - end - - it "caches all dependencies except bundler and the gemspec specified gems" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gemspec :name => 'mygem' - gemspec :name => 'mygem_test' - D - - bundle "config set cache_all true" - bundle! :package - - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist - expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist - expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/mygem_test-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - end - end - end - - context "with --path", :bundler => "< 3" do - it "sets root directory for gems" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - D - - bundle! :package, forgotten_command_line_options(:path => bundled_app("test")) - - expect(the_bundle).to include_gems "rack 1.0.0" - expect(bundled_app("test/vendor/cache/")).to exist - end - end - - context "with --no-install" do - it "puts the gems in vendor/cache but does not install them" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - D - - bundle! "package --no-install" - - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - end - - it "does not prevent installing gems with bundle install" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - D - - bundle! "package --no-install" - bundle! "install" - - expect(the_bundle).to include_gems "rack 1.0.0" - end - - it "does not prevent installing gems with bundle update" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" - D - - bundle! "package --no-install" - bundle! "update --all" - - expect(the_bundle).to include_gems "rack 1.0.0" - end - end - - context "with --all-platforms" do - it "puts the gems in vendor/cache even for other rubies" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack', :platforms => :ruby_19 - D - - bundle "package --all-platforms" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - end - - it "does not attempt to install gems in without groups" do - build_repo4 do - build_gem "uninstallable", "2.0" do |s| - s.add_development_dependency "rake" - s.extensions << "Rakefile" - s.write "Rakefile", "task(:default) { raise 'CANNOT INSTALL' }" - end - end - - install_gemfile! <<-G, forgotten_command_line_options(:without => "wo") - source "file:#{gem_repo1}" - gem "rack" - group :wo do - gem "weakling" - gem "uninstallable", :source => "file:#{gem_repo4}" - end - G - - bundle! :package, "all-platforms" => true - expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist - expect(bundled_app("vendor/cache/uninstallable-2.0.gem")).to exist - expect(the_bundle).to include_gem "rack 1.0" - expect(the_bundle).not_to include_gems "weakling", "uninstallable" - - bundle! :install, forgotten_command_line_options(:without => "wo") - expect(the_bundle).to include_gem "rack 1.0" - expect(the_bundle).not_to include_gems "weakling", "uninstallable" - end - end - - context "with --frozen" do - before do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - bundle "install" - end - - subject { bundle :package, forgotten_command_line_options(:frozen => true) } - - it "tries to install with frozen" do - bundle! "config set deployment true" - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" - G - subject - expect(exitstatus).to eq(16) if exitstatus - expect(err).to include("deployment mode") - expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") - bundle "env" - expect(out).to include("frozen").or include("deployment") - end - end -end - -RSpec.describe "bundle install with gem sources" do - describe "when cached and locked" do - it "does not hit the remote at all" do - build_repo2 - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" - G - - bundle :pack - simulate_new_machine - FileUtils.rm_rf gem_repo2 - - bundle "install --local" - expect(the_bundle).to include_gems "rack 1.0.0" - end - - it "does not hit the remote at all" do - build_repo2 - install_gemfile! <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" - G - - bundle! :pack - simulate_new_machine - FileUtils.rm_rf gem_repo2 - - bundle! :install, forgotten_command_line_options(:deployment => true, :path => "vendor/bundle") - expect(the_bundle).to include_gems "rack 1.0.0" - end - - it "does not reinstall already-installed gems" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - bundle :pack - - build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s| - s.write "lib/rack.rb", "raise 'omg'" - end - - bundle :install - expect(err).to be_empty - expect(the_bundle).to include_gems "rack 1.0" - end - - it "ignores cached gems for the wrong platform" do - simulate_platform "java" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "platform_specific" - G - bundle :pack - end - - simulate_new_machine - - simulate_platform "ruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "platform_specific" - G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 RUBY") - end - end - - it "does not update the cache if --no-cache is passed" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - bundled_app("vendor/cache").mkpath - expect(bundled_app("vendor/cache").children).to be_empty - - bundle "install --no-cache" - expect(bundled_app("vendor/cache").children).to be_empty - end - end -end diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index 79a344eaa1..d607f8bb46 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -390,7 +390,7 @@ You have deleted from the Gemfile: expect(the_bundle).to include_gems "foo 1.0" bundle "config set cache_all true" - bundle! :package + bundle! :cache expect(bundled_app("vendor/cache/foo")).to be_directory bundle! "install --local" diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 7eb05a995c..08789820d8 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -1056,7 +1056,7 @@ RSpec.describe "bundle install with git sources" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require 'rubygems' + require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}" end @@ -1076,7 +1076,7 @@ RSpec.describe "bundle install with git sources" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require 'rubygems' + require '#{spec_dir}/support/rubygems' Gem.post_install_hooks << lambda do |inst| STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}" end @@ -1096,7 +1096,7 @@ RSpec.describe "bundle install with git sources" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require 'rubygems' + require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| false end @@ -1391,7 +1391,7 @@ In Gemfile: end G bundle "config set cache_all true" - bundle :package + bundle :cache simulate_new_machine bundle! "install", :env => { "PATH" => "" } diff --git a/spec/bundler/install/gemfile/groups_spec.rb b/spec/bundler/install/gemfile/groups_spec.rb index 93798ef62e..63be1a4e43 100644 --- a/spec/bundler/install/gemfile/groups_spec.rb +++ b/spec/bundler/install/gemfile/groups_spec.rb @@ -333,7 +333,7 @@ RSpec.describe "bundle install with groups" do G ruby <<-R - require "#{lib}/bundler" + require "#{lib_dir}/bundler" Bundler.setup :default Bundler.require :default puts RACK diff --git a/spec/bundler/install/gemfile/path_spec.rb b/spec/bundler/install/gemfile/path_spec.rb index 3f2e5bdfc3..5261e18bbe 100644 --- a/spec/bundler/install/gemfile/path_spec.rb +++ b/spec/bundler/install/gemfile/path_spec.rb @@ -672,7 +672,7 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require 'rubygems' + require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}" end @@ -692,7 +692,7 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require 'rubygems' + require '#{spec_dir}/support/rubygems' Gem.post_install_hooks << lambda do |inst| STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}" end @@ -712,7 +712,7 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require 'rubygems' + require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| false end diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index b2861e1c00..61943ef2e5 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -102,7 +102,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "can cache and deploy" do - bundle! :package + bundle! :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/rack-obama-1.0.gem")).to exist diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index df30bc0400..e291fb7917 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -621,7 +621,7 @@ RSpec.describe "the lockfile format" do G bundle "config set cache_all true" - bundle! :package + bundle! :cache bundle! :install, :local => true lockfile_should_be <<-G diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index 74f28b94f9..57b68fdb97 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -20,7 +20,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_env", :bundler => "2" do expect(deprecations).to include \ "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env` " \ + "(called at -e:1)" end pending "is removed and shows a helpful error message about it", :bundler => "3" @@ -35,7 +36,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_env", :bundler => "2" do expect(deprecations).to include( "`Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` " \ + "(called at -e:1)" ) end @@ -51,7 +53,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_system", :bundler => "2" do expect(deprecations).to include( "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \ - "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`" + "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system` " \ + "(called at -e:1)" ) end @@ -67,7 +70,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_exec", :bundler => "2" do expect(deprecations).to include( "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \ - "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`" + "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec` " \ + "(called at -e:1)" ) end @@ -81,7 +85,7 @@ RSpec.describe "major deprecations" do end it "is deprecated in favor of .load", :bundler => "2" do - expect(deprecations).to include "Bundler.environment has been removed in favor of Bundler.load" + expect(deprecations).to include "Bundler.environment has been removed in favor of Bundler.load (called at -e:1)" end pending "is removed and shows a helpful error message about it", :bundler => "3" @@ -108,7 +112,7 @@ RSpec.describe "major deprecations" do it "should print a deprecation warning", :bundler => "2" do expect(deprecations).to include( "The `--path` flag is deprecated because it relies on being " \ - "remembered across bundler invokations, which bundler will no " \ + "remembered across bundler invocations, which bundler will no " \ "longer do in future versions. Instead please use `bundle config set " \ "path 'vendor/bundle'`, and stop using this flag" ) @@ -310,7 +314,7 @@ RSpec.describe "major deprecations" do it "should print a deprecation warning", :bundler => "2" do expect(deprecations).to include( "The `#{flag_name}` flag is deprecated because it relies on " \ - "being remembered across bundler invokations, which bundler " \ + "being remembered across bundler invocations, which bundler " \ "will no longer do in future versions. Instead please use " \ "`bundle config set #{name} '#{value}'`, and stop using this flag" ) @@ -356,7 +360,6 @@ RSpec.describe "major deprecations" do require 'bundler' require 'bundler/vendored_thor' - Bundler.ui = Bundler::UI::Shell.new Bundler.setup Bundler.setup RUBY diff --git a/spec/bundler/other/platform_spec.rb b/spec/bundler/other/platform_spec.rb index b61a3f1b03..4feec14d76 100644 --- a/spec/bundler/other/platform_spec.rb +++ b/spec/bundler/other/platform_spec.rb @@ -781,7 +781,7 @@ G #{ruby_version_correct} G - bundle :pack + bundle :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end @@ -794,7 +794,7 @@ G #{ruby_version_correct_engineless} G - bundle :pack + bundle :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end end @@ -806,7 +806,7 @@ G #{ruby_version_incorrect} G - bundle :pack + bundle :cache should_be_ruby_version_incorrect end @@ -817,7 +817,7 @@ G #{engine_incorrect} G - bundle :pack + bundle :cache should_be_engine_incorrect end @@ -829,7 +829,7 @@ G #{engine_version_incorrect} G - bundle :pack + bundle :cache should_be_engine_version_incorrect end end @@ -842,7 +842,7 @@ G #{patchlevel_incorrect} G - bundle :pack + bundle :cache should_be_patchlevel_incorrect end end diff --git a/spec/bundler/plugins/source/example_spec.rb b/spec/bundler/plugins/source/example_spec.rb index 1ef7c2134d..64002d8f46 100644 --- a/spec/bundler/plugins/source/example_spec.rb +++ b/spec/bundler/plugins/source/example_spec.rb @@ -169,7 +169,7 @@ RSpec.describe "real source plugins" do it "bundler package copies repository to vendor cache" do bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") bundle "config set cache_all true" - bundle! :package + bundle! :cache expect(bundled_app("vendor/cache/a-path-gem-1.0-#{uri_hash}")).to exist diff --git a/spec/bundler/realworld/dependency_api_spec.rb b/spec/bundler/realworld/dependency_api_spec.rb index e7d11419cd..dea8329a4d 100644 --- a/spec/bundler/realworld/dependency_api_spec.rb +++ b/spec/bundler/realworld/dependency_api_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../support/silent_logger" + RSpec.describe "gemcutter's dependency API", :realworld => true do context "when Gemcutter API takes too long to respond" do before do @@ -8,7 +10,7 @@ RSpec.describe "gemcutter's dependency API", :realworld => true do port = find_unused_port @server_uri = "http://127.0.0.1:#{port}" - require File.expand_path("../../support/artifice/endpoint_timeout", __FILE__) + require_relative "../support/artifice/endpoint_timeout" @t = Thread.new do server = Rack::Server.start(:app => EndpointTimeout, diff --git a/spec/bundler/realworld/double_check_spec.rb b/spec/bundler/realworld/double_check_spec.rb index 323e0d5735..90cf298b33 100644 --- a/spec/bundler/realworld/double_check_spec.rb +++ b/spec/bundler/realworld/double_check_spec.rb @@ -25,9 +25,9 @@ RSpec.describe "double checking sources", :realworld => true, :sometimes => true RUBY cmd = <<-RUBY - require "#{lib}/bundler" - require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} - require "#{lib}/bundler/inline" + require "#{lib_dir}/bundler" + require "#{spec_dir}/support/artifice/vcr" + require "#{lib_dir}/bundler/inline" gemfile(true) do source "https://rubygems.org" gem "rails", path: "." diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb index 6468ee7f1e..53d9f9a026 100644 --- a/spec/bundler/realworld/edgecases_spec.rb +++ b/spec/bundler/realworld/edgecases_spec.rb @@ -3,19 +3,21 @@ RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do def rubygems_version(name, requirement) ruby! <<-RUBY - require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump} - require "bundler" - require "bundler/source/rubygems/remote" - require "bundler/fetcher" - source = Bundler::Source::Rubygems::Remote.new(URI("https://rubygems.org")) - fetcher = Bundler::Fetcher.new(source) - index = fetcher.specs([#{name.dump}], nil) - rubygem = index.search(Gem::Dependency.new(#{name.dump}, #{requirement.dump})).last + require "#{spec_dir}/support/artifice/vcr" + require "#{lib_dir}/bundler" + require "#{lib_dir}/bundler/source/rubygems/remote" + require "#{lib_dir}/bundler/fetcher" + rubygem = Bundler.ui.silence do + source = Bundler::Source::Rubygems::Remote.new(URI("https://rubygems.org")) + fetcher = Bundler::Fetcher.new(source) + index = fetcher.specs([#{name.dump}], nil) + index.search(Gem::Dependency.new(#{name.dump}, #{requirement.dump})).last + end if rubygem.nil? raise "Could not find #{name} (#{requirement}) on rubygems.org!\n" \ "Found specs:\n\#{index.send(:specs).inspect}" end - "#{name} (\#{rubygem.version})" + puts "#{name} (\#{rubygem.version})" RUBY end diff --git a/spec/bundler/realworld/gemfile_source_header_spec.rb b/spec/bundler/realworld/gemfile_source_header_spec.rb index 382485b8fc..3f507b056a 100644 --- a/spec/bundler/realworld/gemfile_source_header_spec.rb +++ b/spec/bundler/realworld/gemfile_source_header_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../support/silent_logger" + RSpec.describe "fetching dependencies with a mirrored source", :realworld => true do let(:mirror) { "https://server.example.org" } let(:original) { "http://127.0.0.1:#{@port}" } @@ -35,7 +37,7 @@ private @port = find_unused_port @server_uri = "http://127.0.0.1:#{@port}" - require File.expand_path("../../support/artifice/endpoint_mirror_source", __FILE__) + require_relative "../support/artifice/endpoint_mirror_source" @t = Thread.new do Rack::Server.start(:app => EndpointMirrorSource, diff --git a/spec/bundler/realworld/mirror_probe_spec.rb b/spec/bundler/realworld/mirror_probe_spec.rb index 13d1afe124..735fb2b3dd 100644 --- a/spec/bundler/realworld/mirror_probe_spec.rb +++ b/spec/bundler/realworld/mirror_probe_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../support/silent_logger" + RSpec.describe "fetching dependencies with a not available mirror", :realworld => true do let(:mirror) { @mirror_uri } let(:original) { @server_uri } @@ -121,7 +123,7 @@ Could not fetch specs from #{mirror}/ @server_port = find_unused_port @server_uri = "http://#{host}:#{@server_port}" - require File.expand_path("../../support/artifice/endpoint", __FILE__) + require_relative "../support/artifice/endpoint" @server_thread = Thread.new do Rack::Server.start(:app => Endpoint, diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index af645c8ef1..4760b6a749 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -11,7 +11,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do end bundled_app("Rakefile").open("w") do |f| f.write <<-RAKEFILE - $:.unshift("#{lib}") + $:.unshift("#{lib_dir}") require "bundler/gem_tasks" RAKEFILE end @@ -19,7 +19,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do it "includes the relevant tasks" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do - sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib}" + sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}" end expect(err).to eq("") diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 92243a77b6..e5569fec94 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -2,8 +2,8 @@ RSpec.describe "bundler/inline#gemfile" do def script(code, options = {}) - requires = ["#{lib}/bundler/inline"] - requires.unshift File.expand_path("../../support/artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice) + requires = ["#{lib_dir}/bundler/inline"] + requires.unshift "#{spec_dir}/support/artifice/" + options.delete(:artifice) if options.key?(:artifice) requires = requires.map {|r| "require '#{r}'" }.join("\n") @out = ruby("#{requires}\n\n" + code, options) end @@ -97,7 +97,7 @@ RSpec.describe "bundler/inline#gemfile" do it "lets me use my own ui object" do script <<-RUBY, :artifice => "endpoint" - require '#{lib}/bundler' + require '#{lib_dir}/bundler' class MyBundlerUI < Bundler::UI::Silent def confirm(msg, newline = nil) puts "CONFIRMED!" @@ -141,7 +141,7 @@ RSpec.describe "bundler/inline#gemfile" do it "does not mutate the option argument" do script <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' options = { :ui => Bundler::UI::Shell.new } gemfile(false, options) do path "#{lib_path}" do diff --git a/spec/bundler/runtime/load_spec.rb b/spec/bundler/runtime/load_spec.rb index acefc1a583..7de67e247c 100644 --- a/spec/bundler/runtime/load_spec.rb +++ b/spec/bundler/runtime/load_spec.rb @@ -80,7 +80,7 @@ RSpec.describe "Bundler.load" do G ruby! <<-RUBY - require "#{lib}/bundler" + require "#{lib_dir}/bundler" Bundler.setup :default Bundler.require :default puts RACK diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb index c504685ea3..f7e93eacf1 100644 --- a/spec/bundler/runtime/platform_spec.rb +++ b/spec/bundler/runtime/platform_spec.rb @@ -23,7 +23,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do ruby <<-R begin require 'bundler' - Bundler.setup + Bundler.ui.silence { Bundler.setup } rescue Bundler::GemNotFound => e puts "WIN" end diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index 42d0c2db77..490b8c7631 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -193,7 +193,7 @@ RSpec.describe "Bundler.require" do G cmd = <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.require RUBY ruby(cmd) diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index b9d710a9d9..72ad06a43a 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -12,7 +12,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup require 'rack' @@ -34,7 +34,7 @@ RSpec.describe "Bundler.setup" do it "doesn't make all groups available" do ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup(:default) begin @@ -49,7 +49,7 @@ RSpec.describe "Bundler.setup" do it "accepts string for group name" do ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup(:default, 'test') require 'rack' @@ -61,7 +61,7 @@ RSpec.describe "Bundler.setup" do it "leaves all groups available if they were already" do ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup Bundler.setup(:default) @@ -74,7 +74,7 @@ RSpec.describe "Bundler.setup" do it "leaves :default available if setup is called twice" do ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup(:default) Bundler.setup(:default, :test) @@ -91,7 +91,7 @@ RSpec.describe "Bundler.setup" do it "handles multiple non-additive invocations" do ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup(:default, :test) Bundler.setup(:default) require 'rack' @@ -109,7 +109,7 @@ RSpec.describe "Bundler.setup" do def clean_load_path(lp) without_bundler_load_path = ruby!("puts $LOAD_PATH").split("\n") lp -= without_bundler_load_path - lp.map! {|p| p.sub(/^#{Regexp.union system_gem_path.to_s, default_bundle_path.to_s, lib.to_s}/i, "") } + lp.map! {|p| p.sub(/^#{Regexp.union system_gem_path.to_s, default_bundle_path.to_s, lib_dir.to_s}/i, "") } end it "puts loaded gems after -I and RUBYLIB", :ruby_repo do @@ -122,7 +122,7 @@ RSpec.describe "Bundler.setup" do ENV["RUBYLIB"] = "rubylib_dir" ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -144,7 +144,7 @@ RSpec.describe "Bundler.setup" do G ruby! <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup puts $LOAD_PATH RUBY @@ -172,7 +172,7 @@ RSpec.describe "Bundler.setup" do G ruby! <<-RUBY - require '#{lib}/bundler/setup' + require '#{lib_dir}/bundler/setup' puts $LOAD_PATH RUBY @@ -193,7 +193,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-R - require '#{lib}/bundler' + require '#{lib_dir}/bundler' begin Bundler.setup @@ -213,7 +213,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-R - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup R @@ -236,7 +236,7 @@ RSpec.describe "Bundler.setup" do G ruby <<-R - require '#{lib}/bundler' + require '#{lib_dir}/bundler' Bundler.setup R @@ -289,7 +289,7 @@ RSpec.describe "Bundler.setup" do ENV["BUNDLE_GEMFILE"] = "Gemfile" ruby <<-R - require '#{lib}/bundler' + require '#{lib_dir}/bundler' begin Bundler.setup @@ -444,7 +444,7 @@ RSpec.describe "Bundler.setup" do break_git! ruby <<-R - require '#{lib}/bundler' + require '#{lib_dir}/bundler' begin Bundler.setup @@ -465,7 +465,7 @@ RSpec.describe "Bundler.setup" do break_git! ruby <<-R - require "#{lib}/bundler" + require "#{lib_dir}/bundler" begin Bundler.setup @@ -774,7 +774,7 @@ end s.class.send(:define_method, :build_extensions) { nil } end - require '#{lib}/bundler' + require '#{lib_dir}/bundler' gem '#{gem_name}' puts $LOAD_PATH.count {|path| path =~ /#{gem_name}/} >= 2 @@ -1028,7 +1028,7 @@ end bundle "install" ruby <<-RUBY - require '#{lib}/bundler' + require '#{lib_dir}/bundler' def Bundler.require(path) raise "LOSE" end @@ -1043,7 +1043,7 @@ end describe "when Bundler is bundled" do it "doesn't blow up" do install_gemfile <<-G - gem "bundler", :path => "#{File.expand_path("..", lib)}" + gem "bundler", :path => "#{root}" G bundle %(exec ruby -e "require 'bundler'; Bundler.setup") @@ -1083,7 +1083,7 @@ end context "is not present" do it "does not change the lock" do lockfile lock_with(nil) - ruby "require '#{lib}/bundler/setup'" + ruby "require '#{lib_dir}/bundler/setup'" lockfile_should_be lock_with(nil) end end @@ -1091,7 +1091,7 @@ end context "is newer" do it "does not change the lock or warn" do lockfile lock_with(Bundler::VERSION.succ) - ruby "require '#{lib}/bundler/setup'" + ruby "require '#{lib_dir}/bundler/setup'" expect(out).to eq("") expect(err).to eq("") lockfile_should_be lock_with(Bundler::VERSION.succ) @@ -1101,7 +1101,7 @@ end context "is older" do it "does not change the lock" do lockfile lock_with("1.10.1") - ruby "require '#{lib}/bundler/setup'" + ruby "require '#{lib_dir}/bundler/setup'" lockfile_should_be lock_with("1.10.1") end end @@ -1148,14 +1148,14 @@ end context "is not present" do it "does not change the lock" do - expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile } end end context "is newer" do let(:ruby_version) { "5.5.5" } it "does not change the lock or warn" do - expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile } expect(out).to eq("") expect(err).to eq("") end @@ -1164,7 +1164,7 @@ end context "is older" do let(:ruby_version) { "1.0.0" } it "does not change the lock" do - expect { ruby! "require '#{lib}/bundler/setup'" }.not_to change { lockfile } + expect { ruby! "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile } end end end @@ -1173,7 +1173,7 @@ end it "does not load Psych" do gemfile "" ruby <<-RUBY - require '#{lib}/bundler/setup' + require '#{lib_dir}/bundler/setup' puts defined?(Psych::VERSION) ? Psych::VERSION : "undefined" require 'psych' puts Psych::VERSION @@ -1186,7 +1186,7 @@ end it "does not load openssl" do install_gemfile! "" ruby! <<-RUBY - require "#{lib}/bundler/setup" + require "#{lib_dir}/bundler/setup" puts defined?(OpenSSL) || "undefined" require "openssl" puts defined?(OpenSSL) || "undefined" @@ -1240,7 +1240,7 @@ end it "activates no gems with -rbundler/setup" do install_gemfile! "" - ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -r#{lib}/bundler/setup" } + ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -r#{lib_dir}/bundler/setup" } expect(out).to eq("{}") end @@ -1315,7 +1315,7 @@ end G ruby! <<-RUBY - require "#{lib}/bundler/setup" + require "#{lib_dir}/bundler/setup" Object.new.gem "rack" puts Gem.loaded_specs["rack"].full_name RUBY @@ -1330,7 +1330,7 @@ end G ruby <<-RUBY - require "#{lib}/bundler/setup" + require "#{lib_dir}/bundler/setup" Object.new.gem "rack" puts "FAIL" RUBY @@ -1346,7 +1346,7 @@ end G ruby <<-RUBY - require "#{lib}/bundler/setup" + require "#{lib_dir}/bundler/setup" Object.new.require "rack" puts "FAIL" RUBY diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb index a5140ae463..4aaf9d499c 100644 --- a/spec/bundler/runtime/with_unbundled_env_spec.rb +++ b/spec/bundler/runtime/with_unbundled_env_spec.rb @@ -81,8 +81,8 @@ RSpec.describe "Bundler.with_env helpers" do it "should restore RUBYLIB", :ruby_repo do code = "print #{modified_env}['RUBYLIB']" - ENV["RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo" - ENV["BUNDLER_ORIG_RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo-original" + ENV["RUBYLIB"] = lib_dir.to_s + File::PATH_SEPARATOR + "/foo" + ENV["BUNDLER_ORIG_RUBYLIB"] = lib_dir.to_s + File::PATH_SEPARATOR + "/foo-original" bundle_exec_ruby! code.dump expect(last_command.stdboth).to include("/foo-original") end @@ -127,13 +127,17 @@ RSpec.describe "Bundler.with_env helpers" do describe "Bundler.with_clean_env", :bundler => 2 do it "should set ENV to unbundled_env in the block" do expected = Bundler.unbundled_env - actual = Bundler.with_clean_env { ENV.to_hash } + + actual = Bundler.ui.silence do + Bundler.with_clean_env { ENV.to_hash } + end + expect(actual).to eq(expected) end it "should restore the environment after execution" do - Bundler.with_clean_env do - ENV["FOO"] = "hello" + Bundler.ui.silence do + Bundler.with_clean_env { ENV["FOO"] = "hello" } end expect(ENV).not_to have_key("FOO") @@ -166,8 +170,7 @@ RSpec.describe "Bundler.with_env helpers" do end it "runs system inside with_original_env" do - lib = File.expand_path("../../lib", __dir__) - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") expect($?.exitstatus).to eq(42) end end @@ -175,15 +178,14 @@ RSpec.describe "Bundler.with_env helpers" do describe "Bundler.clean_system", :bundler => 2 do let(:code) do <<~RUBY - Bundler.clean_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42)) + Bundler.ui.silence { Bundler.clean_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42)) } exit $?.exitstatus RUBY end it "runs system inside with_clean_env" do - lib = File.expand_path("../../lib", __dir__) - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") expect($?.exitstatus).to eq(42) end end @@ -198,8 +200,7 @@ RSpec.describe "Bundler.with_env helpers" do end it "runs system inside with_unbundled_env" do - lib = File.expand_path("../../lib", __dir__) - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") expect($?.exitstatus).to eq(42) end end @@ -220,8 +221,7 @@ RSpec.describe "Bundler.with_env helpers" do it "runs exec inside with_original_env" do skip "Fork not implemented" if Gem.win_platform? - lib = File.expand_path("../../lib", __dir__) - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") expect($?.exitstatus).to eq(0) end end @@ -230,7 +230,7 @@ RSpec.describe "Bundler.with_env helpers" do let(:code) do <<~RUBY Process.fork do - exit Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar")) + exit Bundler.ui.silence { Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar")) } end _, status = Process.wait2 @@ -242,8 +242,7 @@ RSpec.describe "Bundler.with_env helpers" do it "runs exec inside with_clean_env" do skip "Fork not implemented" if Gem.win_platform? - lib = File.expand_path("../../lib", __dir__) - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") expect($?.exitstatus).to eq(1) end end @@ -264,8 +263,7 @@ RSpec.describe "Bundler.with_env helpers" do it "runs exec inside with_clean_env" do skip "Fork not implemented" if Gem.win_platform? - lib = File.expand_path("../../lib", __dir__) - system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'") + system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'") expect($?.exitstatus).to eq(1) end end diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 58d498e070..ba21d22fbd 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true -$:.unshift File.expand_path("..", __FILE__) -$:.unshift File.expand_path("../../lib", __FILE__) +require_relative "support/path" + +$:.unshift Spec::Path.spec_dir.to_s +$:.unshift Spec::Path.lib_dir.to_s require "bundler/psyched_yaml" require "bundler/vendored_fileutils" @@ -15,10 +17,16 @@ end require "bundler" require "rspec" -Dir["#{File.expand_path("../support", __FILE__)}/*.rb"].each do |file| - file = file.gsub(%r{\A#{Regexp.escape File.expand_path("..", __FILE__)}/}, "") - require file unless file.end_with?("hax.rb") -end +require_relative "support/builders" +require_relative "support/filters" +require_relative "support/helpers" +require_relative "support/indexes" +require_relative "support/matchers" +require_relative "support/parallel" +require_relative "support/permissions" +require_relative "support/platforms" +require_relative "support/sometimes" +require_relative "support/sudo" $debug = false @@ -34,7 +42,6 @@ RSpec.configure do |config| config.include Spec::Indexes config.include Spec::Matchers config.include Spec::Path - config.include Spec::Rubygems config.include Spec::Platforms config.include Spec::Sudo config.include Spec::Permissions @@ -52,28 +59,6 @@ RSpec.configure do |config| config.bisect_runner = :shell - if ENV["BUNDLER_SUDO_TESTS"] && Spec::Sudo.present? - config.filter_run :sudo => true - else - config.filter_run_excluding :sudo => true - end - - if ENV["BUNDLER_REALWORLD_TESTS"] - config.filter_run :realworld => true - else - config.filter_run_excluding :realworld => true - end - - git_version = Bundler::Source::Git::GitProxy.new(nil, nil, nil).version - - config.filter_run_excluding :rubygems => RequirementChecker.against(Gem::VERSION) - config.filter_run_excluding :git => RequirementChecker.against(git_version) - config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) - config.filter_run_excluding :ruby_repo => !ENV["GEM_COMMAND"].nil? - config.filter_run_excluding :no_color_tty => Gem.win_platform? || !ENV["GITHUB_ACTION"].nil? - - config.filter_run_when_matching :focus unless ENV["CI"] - original_wd = Dir.pwd original_env = ENV.to_hash @@ -95,6 +80,7 @@ RSpec.configure do |config| end config.before :suite do + require_relative "support/rubygems_ext" Spec::Rubygems.setup ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" ENV["BUNDLE_SPEC_RUN"] = "true" @@ -122,7 +108,7 @@ RSpec.configure do |config| in_app_root @command_executions = [] - example.run + Bundler.ui.silence { example.run } all_output = @command_executions.map(&:to_s_verbose).join("\n\n") if example.exception && !all_output.empty? diff --git a/spec/bundler/support/artifice/compact_index.rb b/spec/bundler/support/artifice/compact_index.rb index 4f01690ae4..89362c4dbc 100644 --- a/spec/bundler/support/artifice/compact_index.rb +++ b/spec/bundler/support/artifice/compact_index.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" $LOAD_PATH.unshift Dir[base_system_gems.join("gems/compact_index*/lib")].first.to_s require "compact_index" diff --git a/spec/bundler/support/artifice/compact_index_api_missing.rb b/spec/bundler/support/artifice/compact_index_api_missing.rb index 94e6b73000..fdd342bc08 100644 --- a/spec/bundler/support/artifice/compact_index_api_missing.rb +++ b/spec/bundler/support/artifice/compact_index_api_missing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_basic_authentication.rb b/spec/bundler/support/artifice/compact_index_basic_authentication.rb index 97aa6cbd84..775f1a3977 100644 --- a/spec/bundler/support/artifice/compact_index_basic_authentication.rb +++ b/spec/bundler/support/artifice/compact_index_basic_authentication.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_checksum_mismatch.rb b/spec/bundler/support/artifice/compact_index_checksum_mismatch.rb index 62feb9f164..1abe64236c 100644 --- a/spec/bundler/support/artifice/compact_index_checksum_mismatch.rb +++ b/spec/bundler/support/artifice/compact_index_checksum_mismatch.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_concurrent_download.rb b/spec/bundler/support/artifice/compact_index_concurrent_download.rb index 972ecb88b7..7f989a3f37 100644 --- a/spec/bundler/support/artifice/compact_index_concurrent_download.rb +++ b/spec/bundler/support/artifice/compact_index_concurrent_download.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_creds_diff_host.rb b/spec/bundler/support/artifice/compact_index_creds_diff_host.rb index 0d349bcc1e..6c3442e14b 100644 --- a/spec/bundler/support/artifice/compact_index_creds_diff_host.rb +++ b/spec/bundler/support/artifice/compact_index_creds_diff_host.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_extra.rb b/spec/bundler/support/artifice/compact_index_extra.rb index 84d1859235..3a09afd06f 100644 --- a/spec/bundler/support/artifice/compact_index_extra.rb +++ b/spec/bundler/support/artifice/compact_index_extra.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_extra_api.rb b/spec/bundler/support/artifice/compact_index_extra_api.rb index 903aa900fb..3c716763c0 100644 --- a/spec/bundler/support/artifice/compact_index_extra_api.rb +++ b/spec/bundler/support/artifice/compact_index_extra_api.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_extra_api_missing.rb b/spec/bundler/support/artifice/compact_index_extra_api_missing.rb index e72040f604..6bd24ddbb4 100644 --- a/spec/bundler/support/artifice/compact_index_extra_api_missing.rb +++ b/spec/bundler/support/artifice/compact_index_extra_api_missing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index_extra_api", __FILE__) +require_relative "compact_index_extra_api" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_extra_missing.rb b/spec/bundler/support/artifice/compact_index_extra_missing.rb index 67a9d23691..4758b785ac 100644 --- a/spec/bundler/support/artifice/compact_index_extra_missing.rb +++ b/spec/bundler/support/artifice/compact_index_extra_missing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index_extra", __FILE__) +require_relative "compact_index_extra" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_forbidden.rb b/spec/bundler/support/artifice/compact_index_forbidden.rb index 0a4dfdb2e8..3eebe0fbd8 100644 --- a/spec/bundler/support/artifice/compact_index_forbidden.rb +++ b/spec/bundler/support/artifice/compact_index_forbidden.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_host_redirect.rb b/spec/bundler/support/artifice/compact_index_host_redirect.rb index ab371117de..304c897d68 100644 --- a/spec/bundler/support/artifice/compact_index_host_redirect.rb +++ b/spec/bundler/support/artifice/compact_index_host_redirect.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_no_gem.rb b/spec/bundler/support/artifice/compact_index_no_gem.rb index 01c5be1b3d..0a4be08a46 100644 --- a/spec/bundler/support/artifice/compact_index_no_gem.rb +++ b/spec/bundler/support/artifice/compact_index_no_gem.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_partial_update.rb b/spec/bundler/support/artifice/compact_index_partial_update.rb index eaedff5105..6e7c05d423 100644 --- a/spec/bundler/support/artifice/compact_index_partial_update.rb +++ b/spec/bundler/support/artifice/compact_index_partial_update.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb b/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb index 487be4771a..788f9d6f99 100644 --- a/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb +++ b/spec/bundler/support/artifice/compact_index_range_not_satisfiable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_rate_limited.rb b/spec/bundler/support/artifice/compact_index_rate_limited.rb index d8f4fc941c..ba17476045 100644 --- a/spec/bundler/support/artifice/compact_index_rate_limited.rb +++ b/spec/bundler/support/artifice/compact_index_rate_limited.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_redirects.rb b/spec/bundler/support/artifice/compact_index_redirects.rb index e83451b5b6..99adc797bf 100644 --- a/spec/bundler/support/artifice/compact_index_redirects.rb +++ b/spec/bundler/support/artifice/compact_index_redirects.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb b/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb index abbf3258e7..7d427b5382 100644 --- a/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb +++ b/spec/bundler/support/artifice/compact_index_strict_basic_authentication.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_wrong_dependencies.rb b/spec/bundler/support/artifice/compact_index_wrong_dependencies.rb index 7e1d3686e2..036fac70b3 100644 --- a/spec/bundler/support/artifice/compact_index_wrong_dependencies.rb +++ b/spec/bundler/support/artifice/compact_index_wrong_dependencies.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb b/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb index db4d8e3974..8add32b88f 100644 --- a/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb +++ b/spec/bundler/support/artifice/compact_index_wrong_gem_checksum.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../compact_index", __FILE__) +require_relative "compact_index" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endopint_marshal_fail_basic_authentication.rb b/spec/bundler/support/artifice/endopint_marshal_fail_basic_authentication.rb index 12a6fa153f..c341c3993f 100644 --- a/spec/bundler/support/artifice/endopint_marshal_fail_basic_authentication.rb +++ b/spec/bundler/support/artifice/endopint_marshal_fail_basic_authentication.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint_marshal_fail", __FILE__) +require_relative "endpoint_marshal_fail" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint.rb b/spec/bundler/support/artifice/endpoint.rb index 966681f8d8..bf26c56503 100644 --- a/spec/bundler/support/artifice/endpoint.rb +++ b/spec/bundler/support/artifice/endpoint.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require File.expand_path("../../path.rb", __FILE__) -require Spec::Path.root.join("lib/bundler/deprecate") +require_relative "../path" +require Spec::Path.lib_dir.join("bundler/deprecate") include Spec::Path $LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra}-*/lib")].map(&:to_s)) @@ -44,7 +44,7 @@ class Endpoint < Sinatra::Base def dependencies_for(gem_names, gem_repo = GEM_REPO) return [] if gem_names.nil? || gem_names.empty? - require "#{Spec::Path.lib}/bundler" + require "#{Spec::Path.lib_dir}/bundler" Bundler::Deprecate.skip_during do all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| Marshal.load(File.open(gem_repo.join(filename)).read) diff --git a/spec/bundler/support/artifice/endpoint_500.rb b/spec/bundler/support/artifice/endpoint_500.rb index ad51d58e67..f98e7e3bc2 100644 --- a/spec/bundler/support/artifice/endpoint_500.rb +++ b/spec/bundler/support/artifice/endpoint_500.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../../path.rb", __FILE__) +require_relative "../path" include Spec::Path $LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra}-*/lib")].map(&:to_s)) diff --git a/spec/bundler/support/artifice/endpoint_api_forbidden.rb b/spec/bundler/support/artifice/endpoint_api_forbidden.rb index bb89747adc..edc2463424 100644 --- a/spec/bundler/support/artifice/endpoint_api_forbidden.rb +++ b/spec/bundler/support/artifice/endpoint_api_forbidden.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_api_missing.rb b/spec/bundler/support/artifice/endpoint_api_missing.rb index 2ada0dc553..8dafde7362 100644 --- a/spec/bundler/support/artifice/endpoint_api_missing.rb +++ b/spec/bundler/support/artifice/endpoint_api_missing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_basic_authentication.rb b/spec/bundler/support/artifice/endpoint_basic_authentication.rb index 223671bc29..ff3d1493d6 100644 --- a/spec/bundler/support/artifice/endpoint_basic_authentication.rb +++ b/spec/bundler/support/artifice/endpoint_basic_authentication.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_creds_diff_host.rb b/spec/bundler/support/artifice/endpoint_creds_diff_host.rb index 925954b12d..f20ef74ac6 100644 --- a/spec/bundler/support/artifice/endpoint_creds_diff_host.rb +++ b/spec/bundler/support/artifice/endpoint_creds_diff_host.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_extra.rb b/spec/bundler/support/artifice/endpoint_extra.rb index 422f65401b..31f6822161 100644 --- a/spec/bundler/support/artifice/endpoint_extra.rb +++ b/spec/bundler/support/artifice/endpoint_extra.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_extra_api.rb b/spec/bundler/support/artifice/endpoint_extra_api.rb index 62e2c2bb93..213b8e5895 100644 --- a/spec/bundler/support/artifice/endpoint_extra_api.rb +++ b/spec/bundler/support/artifice/endpoint_extra_api.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_extra_missing.rb b/spec/bundler/support/artifice/endpoint_extra_missing.rb index 038a12610a..ee129025ff 100644 --- a/spec/bundler/support/artifice/endpoint_extra_missing.rb +++ b/spec/bundler/support/artifice/endpoint_extra_missing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint_extra", __FILE__) +require_relative "endpoint_extra" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_fallback.rb b/spec/bundler/support/artifice/endpoint_fallback.rb index 554c08f0a2..08edf232e3 100644 --- a/spec/bundler/support/artifice/endpoint_fallback.rb +++ b/spec/bundler/support/artifice/endpoint_fallback.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_host_redirect.rb b/spec/bundler/support/artifice/endpoint_host_redirect.rb index cda5664be2..338cbcad00 100644 --- a/spec/bundler/support/artifice/endpoint_host_redirect.rb +++ b/spec/bundler/support/artifice/endpoint_host_redirect.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_marshal_fail.rb b/spec/bundler/support/artifice/endpoint_marshal_fail.rb index 2a5dcdc2fd..22c13e3e17 100644 --- a/spec/bundler/support/artifice/endpoint_marshal_fail.rb +++ b/spec/bundler/support/artifice/endpoint_marshal_fail.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint_fallback", __FILE__) +require_relative "endpoint_fallback" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_mirror_source.rb b/spec/bundler/support/artifice/endpoint_mirror_source.rb index 64452f198d..318866e420 100644 --- a/spec/bundler/support/artifice/endpoint_mirror_source.rb +++ b/spec/bundler/support/artifice/endpoint_mirror_source.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" class EndpointMirrorSource < Endpoint get "/gems/:id" do diff --git a/spec/bundler/support/artifice/endpoint_redirect.rb b/spec/bundler/support/artifice/endpoint_redirect.rb index ebf01458ba..ee97fccf64 100644 --- a/spec/bundler/support/artifice/endpoint_redirect.rb +++ b/spec/bundler/support/artifice/endpoint_redirect.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb b/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb index 905a519f3f..4d4da08770 100644 --- a/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb +++ b/spec/bundler/support/artifice/endpoint_strict_basic_authentication.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint", __FILE__) +require_relative "endpoint" Artifice.deactivate diff --git a/spec/bundler/support/artifice/endpoint_timeout.rb b/spec/bundler/support/artifice/endpoint_timeout.rb index 3f60471c90..c118da1893 100644 --- a/spec/bundler/support/artifice/endpoint_timeout.rb +++ b/spec/bundler/support/artifice/endpoint_timeout.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../endpoint_fallback", __FILE__) +require_relative "endpoint_fallback" Artifice.deactivate diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index 1e3809ff62..a46f8e9391 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true require "net/http" +require_relative "../path" -CASSETTE_PATH = File.expand_path("../vcr_cassettes", __FILE__) +CASSETTE_PATH = "#{Spec::Path.spec_dir}/support/artifice/vcr_cassettes" CASSETTE_NAME = ENV.fetch("BUNDLER_SPEC_VCR_CASSETTE_NAME") { "realworld" } class BundlerVCRHTTP < Net::HTTP diff --git a/spec/bundler/support/artifice/windows.rb b/spec/bundler/support/artifice/windows.rb index 0630798df0..ce7455b86c 100644 --- a/spec/bundler/support/artifice/windows.rb +++ b/spec/bundler/support/artifice/windows.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path("../../path.rb", __FILE__) +require_relative "../path" include Spec::Path $LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra}-*/lib")].map(&:to_s)) diff --git a/spec/bundler/support/command_execution.rb b/spec/bundler/support/command_execution.rb index cec531d6c3..b3c289979f 100644 --- a/spec/bundler/support/command_execution.rb +++ b/spec/bundler/support/command_execution.rb @@ -1,12 +1,7 @@ # frozen_string_literal: true -require "support/helpers" -require "support/path" - module Spec CommandExecution = Struct.new(:command, :working_directory, :exitstatus, :stdout, :stderr) do - include RSpec::Matchers::Composable - def to_s c = Shellwords.shellsplit(command.strip).map {|s| s.include?("\n") ? " \\\n < true + else + config.filter_run_excluding :sudo => true + end + + if ENV["BUNDLER_REALWORLD_TESTS"] + config.filter_run :realworld => true + else + config.filter_run_excluding :realworld => true + end + + git_version = Bundler::Source::Git::GitProxy.new(nil, nil, nil).version + + config.filter_run_excluding :rubygems => RequirementChecker.against(Gem::VERSION) + config.filter_run_excluding :git => RequirementChecker.against(git_version) + config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) + config.filter_run_excluding :ruby_repo => !ENV["GEM_COMMAND"].nil? + config.filter_run_excluding :no_color_tty => Gem.win_platform? || !ENV["GITHUB_ACTION"].nil? + + config.filter_run_when_matching :focus unless ENV["CI"] +end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 0c05789946..8bf76bba89 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -2,6 +2,9 @@ require "open3" +require_relative "command_execution" +require_relative "the_bundle" + module Spec module Helpers def reset! @@ -16,8 +19,6 @@ module Spec FileUtils.mkdir_p(home) FileUtils.mkdir_p(tmpdir) Bundler.reset! - Bundler.ui = nil - Bundler.ui # force it to initialize end def self.bang(method) @@ -77,7 +78,7 @@ module Spec def run(cmd, *args) opts = args.last.is_a?(Hash) ? args.pop : {} groups = args.map(&:inspect).join(", ") - setup = "require '#{lib}/bundler' ; Bundler.setup(#{groups})\n" + setup = "require '#{lib_dir}/bundler' ; Bundler.ui.silence { Bundler.setup(#{groups}) }\n" ruby(setup + cmd, opts) end bang :run @@ -95,10 +96,6 @@ module Spec run(cmd, *args) end - def spec - spec_dir.to_s - end - def bundle(cmd, options = {}) with_sudo = options.delete(:sudo) sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo @@ -113,6 +110,7 @@ module Spec env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler requires = options.delete(:requires) || [] + requires << "support/rubygems" requires << "support/hax" artifice = options.delete(:artifice) do @@ -123,14 +121,14 @@ module Spec end end if artifice - requires << File.expand_path("../artifice/#{artifice}", __FILE__) + requires << "support/artifice/#{artifice}" end requires_str = requires.map {|r| "-r#{r}" }.join(" ") load_path = [] - load_path << lib unless system_bundler - load_path << spec + load_path << lib_dir unless system_bundler + load_path << spec_dir load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}" args = options.map do |k, v| @@ -146,7 +144,7 @@ module Spec end end.join - cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" + cmd = "#{sudo} #{Gem.ruby} --disable-gems #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? } end bang :bundle @@ -174,10 +172,10 @@ module Spec end def ruby(ruby, options = {}) - env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join + env = options.delete(:env) || {} ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" } - lib_option = options[:no_lib] ? "" : " -I#{lib}" - sys_exec(%(#{env}#{Gem.ruby}#{lib_option} -e "#{ruby}")) + lib_option = options[:no_lib] ? "" : " -I#{lib_dir}" + sys_exec(%(#{Gem.ruby}#{lib_option} -e "#{ruby}"), env) end bang :ruby @@ -193,7 +191,7 @@ module Spec def gembin(cmd) old = ENV["RUBYOPT"] - ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib}" + ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}" cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/") sys_exec(cmd.to_s) ensure @@ -513,10 +511,6 @@ module Spec Dir.chdir(path) { `git rev-parse HEAD`.strip } end - def capture_output - capture(:stdout) - end - def with_read_only(pattern) chmod = lambda do |dirmode, filemode| lambda do |f| diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index b0493801e8..69d3be4a3d 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require "forwardable" -require "support/the_bundle" +require_relative "the_bundle" + module Spec module Matchers extend RSpec::Matchers @@ -170,7 +171,7 @@ module Spec end R rescue StandardError => e - next "checking for #{name} failed:\n#{e}" + next "checking for #{name} failed:\n#{e}\n#{e.backtrace.join("\n")}" end next if out == "WIN" next "expected #{name} to not be installed, but it was" if version.nil? diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index db28454792..b957e24abe 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -22,7 +22,7 @@ module Spec end def gem_bin - @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -S gem --backtrace" + @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} --disable-gems -r#{spec_dir}/support/rubygems -S gem --backtrace" end def spec_dir @@ -131,7 +131,7 @@ module Spec tmp("libs", *args) end - def lib + def lib_dir root.join("lib") end diff --git a/spec/bundler/support/requirement_checker.rb b/spec/bundler/support/requirement_checker.rb deleted file mode 100644 index e6bd0eb50d..0000000000 --- a/spec/bundler/support/requirement_checker.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -class RequirementChecker < Proc - def self.against(present) - provided = Gem::Version.new(present) - - new do |required| - !Gem::Requirement.new(required).satisfied_by?(provided) - end.tap do |checker| - checker.provided = provided - end - end - - attr_accessor :provided - - def inspect - "\"!= #{provided}\"" - end -end diff --git a/spec/bundler/support/rubygems.rb b/spec/bundler/support/rubygems.rb new file mode 100644 index 0000000000..e60f9a928e --- /dev/null +++ b/spec/bundler/support/rubygems.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require_relative "rubygems_version_manager" + +RubygemsVersionManager.new(ENV["RGV"]).switch + +require "rubygems" diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index faa474a917..1093362d81 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "rubygems/user_interaction" require_relative "path" require "fileutils" @@ -29,7 +28,9 @@ module Spec "ruby-graphviz" => ">= 0.a", }.freeze - def self.dev_setup + extend self + + def dev_setup deps = DEV_DEPS # JRuby can't build ronn, so we skip that @@ -38,22 +39,17 @@ module Spec install_gems(deps) end - def self.gem_load(gem_name, bin_container) - gem_activate(gem_name) - load Gem.bin_path(gem_name, bin_container) + def gem_load(gem_name, bin_container) + require_relative "rubygems" + gem_load_and_activate(gem_name, bin_container) end - def self.gem_activate(gem_name) - gem_requirement = DEV_DEPS[gem_name] - gem gem_name, gem_requirement - end - - def self.gem_require(gem_name) + def gem_require(gem_name) gem_activate(gem_name) require gem_name end - def self.setup + def setup Gem.clear_paths ENV["BUNDLE_PATH"] = nil @@ -71,20 +67,37 @@ module Spec manifest_path.open("w") {|f| f << manifest.join } end + FileUtils.mkdir_p(Path.home) + FileUtils.mkdir_p(Path.tmpdir) + ENV["HOME"] = Path.home.to_s ENV["TMPDIR"] = Path.tmpdir.to_s + require "rubygems/user_interaction" Gem::DefaultUserInteraction.ui = Gem::SilentUI.new end - def self.install_gems(gems) + private + + def gem_load_and_activate(gem_name, bin_container) + gem_activate(gem_name) + load Gem.bin_path(gem_name, bin_container) + rescue Gem::LoadError => e + abort "We couln't activate #{gem_name} (#{e.requirement}). Run `gem install #{gem_name}:'#{e.requirement}'`" + end + + def gem_activate(gem_name) + gem_requirement = DEV_DEPS[gem_name] + gem gem_name, gem_requirement + end + + def install_gems(gems) reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? } no_reqs.map!(&:first) reqs.map! {|name, req| "'#{name}:#{req}'" } deps = reqs.concat(no_reqs).join(" ") gem = Path.gem_bin cmd = "#{gem} install #{deps} --no-document --conservative" - puts cmd system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") end end diff --git a/spec/bundler/support/rubygems_version_manager.rb b/spec/bundler/support/rubygems_version_manager.rb new file mode 100644 index 0000000000..31f7cc4b08 --- /dev/null +++ b/spec/bundler/support/rubygems_version_manager.rb @@ -0,0 +1,127 @@ +# frozen_string_literal: true + +require "pathname" +require_relative "helpers" +require_relative "path" + +class RubygemsVersionManager + include Spec::Helpers + include Spec::Path + + def initialize(env_version) + @env_version = env_version + end + + def switch + return if use_system? + + unrequire_rubygems_if_needed + + switch_local_copy_if_needed + + prepare_environment + end + +private + + def use_system? + @env_version.nil? + end + + def unrequire_rubygems_if_needed + return unless rubygems_unrequire_needed? + + require "rbconfig" + + ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"]) + ruby << RbConfig::CONFIG["EXEEXT"] + + cmd = [ruby, $0, *ARGV].compact + cmd[1, 0] = "--disable-gems" + + exec(ENV, *cmd) + end + + def switch_local_copy_if_needed + return unless local_copy_switch_needed? + + Dir.chdir(local_copy_path) do + sys_exec!("git remote update") + sys_exec!("git checkout #{target_tag_version} --quiet") + end + end + + def prepare_environment + $:.unshift File.expand_path("lib", local_copy_path) + end + + def rubygems_unrequire_needed? + defined?(Gem) && Gem::VERSION != target_gem_version + end + + def local_copy_switch_needed? + !env_version_is_path? && target_gem_version != local_copy_version + end + + def target_gem_version + @target_gem_version ||= resolve_target_gem_version + end + + def target_tag_version + @target_tag_version ||= resolve_target_tag_version + end + + def local_copy_version + gemspec_contents = File.read(local_copy_path.join("lib/rubygems.rb")) + version_regexp = /VERSION = ["'](.*)["']/ + + version_regexp.match(gemspec_contents)[1] + end + + def local_copy_path + @local_copy_path ||= resolve_local_copy_path + end + + def resolve_local_copy_path + return expanded_env_version if env_version_is_path? + + rubygems_path = root.join("tmp/rubygems") + + unless rubygems_path.directory? + rubygems_path.parent.mkpath + sys_exec!("git clone https://github.com/rubygems/rubygems.git #{rubygems_path}") + end + + rubygems_path + end + + def env_version_is_path? + expanded_env_version.directory? + end + + def expanded_env_version + @expanded_env_version ||= Pathname.new(@env_version).expand_path(root) + end + + def resolve_target_tag_version + return "v#{@env_version}" if @env_version.match(/^\d/) + + return "master" if @env_version == master_gem_version + + @env_version + end + + def resolve_target_gem_version + return local_copy_version if env_version_is_path? + + return @env_version[1..-1] if @env_version.match(/^v/) + + return master_gem_version if @env_version == "master" + + @env_version + end + + def master_gem_version + "3.1.0.pre1" + end +end diff --git a/spec/bundler/support/the_bundle.rb b/spec/bundler/support/the_bundle.rb index c994eaae78..f252a4515b 100644 --- a/spec/bundler/support/the_bundle.rb +++ b/spec/bundler/support/the_bundle.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -require "support/helpers" -require "support/path" +require_relative "path" module Spec class TheBundle - include Spec::Helpers include Spec::Path attr_accessor :bundle_dir -- cgit v1.2.3