diff options
author | Bundlerbot <bot@bundler.io> | 2019-11-05 09:33:44 +0000 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-11-07 16:41:43 +0100 |
commit | e133e7a8d59c951b86da095fb7b3d5952f854c2d (patch) | |
tree | c3d82ad4c8d0cf48b60fdf11e2bbdd2e392eb89b | |
parent | 212900f5b12074597208b906a8b564f81f0c47e5 (diff) | |
download | bundler-e133e7a8d59c951b86da095fb7b3d5952f854c2d.tar.gz |
Merge #7402
7402: Spec normalizations r=deivid-rodriguez a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that I saw some room for improvement in our specs and I couldn't help myself :)
### What is your fix for the problem, implemented in this PR?
Essentially, the idea of this PR is to avoid using `__FILE__` or other folder-structure specific constructs to look for files, and instead use our helpers ìn `spec/support/path.rb`. The idea is that the helpers in this file are aware that `bundler` specs can be run from ruby-core or the upstream repo, and the folder structure is different for both.
Also, the PR normalizes some naming, some duplicated helpers, and the way we require files from specs.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
(cherry picked from commit 2e7a37b4517767190e227ed93814567f4b12413d)
58 files changed, 118 insertions, 126 deletions
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index 0340cb7bae..4530a9a5cd 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/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/commands/exec_spec.rb b/spec/commands/exec_spec.rb index cf76d3fb93..7ae504d360 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/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/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 18a30ca9db..708b41f623 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -26,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 @@ -181,7 +181,7 @@ RSpec.describe "bundle gem" do context "when git is not available" do # 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" => "" diff --git a/spec/install/gemfile/groups_spec.rb b/spec/install/gemfile/groups_spec.rb index 93798ef62e..63be1a4e43 100644 --- a/spec/install/gemfile/groups_spec.rb +++ b/spec/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/realworld/dependency_api_spec.rb b/spec/realworld/dependency_api_spec.rb index c04003073e..dea8329a4d 100644 --- a/spec/realworld/dependency_api_spec.rb +++ b/spec/realworld/dependency_api_spec.rb @@ -10,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/realworld/double_check_spec.rb b/spec/realworld/double_check_spec.rb index 323e0d5735..90cf298b33 100644 --- a/spec/realworld/double_check_spec.rb +++ b/spec/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/realworld/edgecases_spec.rb b/spec/realworld/edgecases_spec.rb index c7ec814df5..53d9f9a026 100644 --- a/spec/realworld/edgecases_spec.rb +++ b/spec/realworld/edgecases_spec.rb @@ -3,10 +3,10 @@ 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" + 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) diff --git a/spec/realworld/gemfile_source_header_spec.rb b/spec/realworld/gemfile_source_header_spec.rb index 8658c836c3..3f507b056a 100644 --- a/spec/realworld/gemfile_source_header_spec.rb +++ b/spec/realworld/gemfile_source_header_spec.rb @@ -37,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/realworld/mirror_probe_spec.rb b/spec/realworld/mirror_probe_spec.rb index a0db3cd9ec..735fb2b3dd 100644 --- a/spec/realworld/mirror_probe_spec.rb +++ b/spec/realworld/mirror_probe_spec.rb @@ -123,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/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb index af645c8ef1..4760b6a749 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/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/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb index 92243a77b6..e5569fec94 100644 --- a/spec/runtime/inline_spec.rb +++ b/spec/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/runtime/load_spec.rb b/spec/runtime/load_spec.rb index acefc1a583..7de67e247c 100644 --- a/spec/runtime/load_spec.rb +++ b/spec/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/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 42d0c2db77..490b8c7631 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/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/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index b9d710a9d9..72ad06a43a 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/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/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb index 254f493042..4aaf9d499c 100644 --- a/spec/runtime/with_unbundled_env_spec.rb +++ b/spec/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 @@ -170,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 @@ -186,8 +185,7 @@ RSpec.describe "Bundler.with_env helpers" do 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 @@ -202,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 @@ -224,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 @@ -246,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 @@ -268,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/spec_helper.rb b/spec/spec_helper.rb index 98bc21e537..ba21d22fbd 100644 --- a/spec/spec_helper.rb +++ b/spec/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" @@ -20,7 +22,6 @@ require_relative "support/filters" require_relative "support/helpers" require_relative "support/indexes" require_relative "support/matchers" -require_relative "support/path" require_relative "support/parallel" require_relative "support/permissions" require_relative "support/platforms" diff --git a/spec/support/artifice/compact_index.rb b/spec/support/artifice/compact_index.rb index 4f01690ae4..89362c4dbc 100644 --- a/spec/support/artifice/compact_index.rb +++ b/spec/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/support/artifice/compact_index_api_missing.rb b/spec/support/artifice/compact_index_api_missing.rb index 94e6b73000..fdd342bc08 100644 --- a/spec/support/artifice/compact_index_api_missing.rb +++ b/spec/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/support/artifice/compact_index_basic_authentication.rb b/spec/support/artifice/compact_index_basic_authentication.rb index 97aa6cbd84..775f1a3977 100644 --- a/spec/support/artifice/compact_index_basic_authentication.rb +++ b/spec/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/support/artifice/compact_index_checksum_mismatch.rb b/spec/support/artifice/compact_index_checksum_mismatch.rb index 62feb9f164..1abe64236c 100644 --- a/spec/support/artifice/compact_index_checksum_mismatch.rb +++ b/spec/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/support/artifice/compact_index_concurrent_download.rb b/spec/support/artifice/compact_index_concurrent_download.rb index 972ecb88b7..7f989a3f37 100644 --- a/spec/support/artifice/compact_index_concurrent_download.rb +++ b/spec/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/support/artifice/compact_index_creds_diff_host.rb b/spec/support/artifice/compact_index_creds_diff_host.rb index 0d349bcc1e..6c3442e14b 100644 --- a/spec/support/artifice/compact_index_creds_diff_host.rb +++ b/spec/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/support/artifice/compact_index_extra.rb b/spec/support/artifice/compact_index_extra.rb index 84d1859235..3a09afd06f 100644 --- a/spec/support/artifice/compact_index_extra.rb +++ b/spec/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/support/artifice/compact_index_extra_api.rb b/spec/support/artifice/compact_index_extra_api.rb index 903aa900fb..3c716763c0 100644 --- a/spec/support/artifice/compact_index_extra_api.rb +++ b/spec/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/support/artifice/compact_index_extra_api_missing.rb b/spec/support/artifice/compact_index_extra_api_missing.rb index e72040f604..6bd24ddbb4 100644 --- a/spec/support/artifice/compact_index_extra_api_missing.rb +++ b/spec/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/support/artifice/compact_index_extra_missing.rb b/spec/support/artifice/compact_index_extra_missing.rb index 67a9d23691..4758b785ac 100644 --- a/spec/support/artifice/compact_index_extra_missing.rb +++ b/spec/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/support/artifice/compact_index_forbidden.rb b/spec/support/artifice/compact_index_forbidden.rb index 0a4dfdb2e8..3eebe0fbd8 100644 --- a/spec/support/artifice/compact_index_forbidden.rb +++ b/spec/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/support/artifice/compact_index_host_redirect.rb b/spec/support/artifice/compact_index_host_redirect.rb index ab371117de..304c897d68 100644 --- a/spec/support/artifice/compact_index_host_redirect.rb +++ b/spec/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/support/artifice/compact_index_no_gem.rb b/spec/support/artifice/compact_index_no_gem.rb index 01c5be1b3d..0a4be08a46 100644 --- a/spec/support/artifice/compact_index_no_gem.rb +++ b/spec/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/support/artifice/compact_index_partial_update.rb b/spec/support/artifice/compact_index_partial_update.rb index eaedff5105..6e7c05d423 100644 --- a/spec/support/artifice/compact_index_partial_update.rb +++ b/spec/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/support/artifice/compact_index_range_not_satisfiable.rb b/spec/support/artifice/compact_index_range_not_satisfiable.rb index 487be4771a..788f9d6f99 100644 --- a/spec/support/artifice/compact_index_range_not_satisfiable.rb +++ b/spec/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/support/artifice/compact_index_rate_limited.rb b/spec/support/artifice/compact_index_rate_limited.rb index d8f4fc941c..ba17476045 100644 --- a/spec/support/artifice/compact_index_rate_limited.rb +++ b/spec/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/support/artifice/compact_index_redirects.rb b/spec/support/artifice/compact_index_redirects.rb index e83451b5b6..99adc797bf 100644 --- a/spec/support/artifice/compact_index_redirects.rb +++ b/spec/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/support/artifice/compact_index_strict_basic_authentication.rb b/spec/support/artifice/compact_index_strict_basic_authentication.rb index abbf3258e7..7d427b5382 100644 --- a/spec/support/artifice/compact_index_strict_basic_authentication.rb +++ b/spec/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/support/artifice/compact_index_wrong_dependencies.rb b/spec/support/artifice/compact_index_wrong_dependencies.rb index 7e1d3686e2..036fac70b3 100644 --- a/spec/support/artifice/compact_index_wrong_dependencies.rb +++ b/spec/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/support/artifice/compact_index_wrong_gem_checksum.rb b/spec/support/artifice/compact_index_wrong_gem_checksum.rb index db4d8e3974..8add32b88f 100644 --- a/spec/support/artifice/compact_index_wrong_gem_checksum.rb +++ b/spec/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/support/artifice/endopint_marshal_fail_basic_authentication.rb b/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb index 12a6fa153f..c341c3993f 100644 --- a/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +++ b/spec/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/support/artifice/endpoint.rb b/spec/support/artifice/endpoint.rb index 966681f8d8..bf26c56503 100644 --- a/spec/support/artifice/endpoint.rb +++ b/spec/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/support/artifice/endpoint_500.rb b/spec/support/artifice/endpoint_500.rb index ad51d58e67..f98e7e3bc2 100644 --- a/spec/support/artifice/endpoint_500.rb +++ b/spec/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/support/artifice/endpoint_api_forbidden.rb b/spec/support/artifice/endpoint_api_forbidden.rb index bb89747adc..edc2463424 100644 --- a/spec/support/artifice/endpoint_api_forbidden.rb +++ b/spec/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/support/artifice/endpoint_api_missing.rb b/spec/support/artifice/endpoint_api_missing.rb index 2ada0dc553..8dafde7362 100644 --- a/spec/support/artifice/endpoint_api_missing.rb +++ b/spec/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/support/artifice/endpoint_basic_authentication.rb b/spec/support/artifice/endpoint_basic_authentication.rb index 223671bc29..ff3d1493d6 100644 --- a/spec/support/artifice/endpoint_basic_authentication.rb +++ b/spec/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/support/artifice/endpoint_creds_diff_host.rb b/spec/support/artifice/endpoint_creds_diff_host.rb index 925954b12d..f20ef74ac6 100644 --- a/spec/support/artifice/endpoint_creds_diff_host.rb +++ b/spec/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/support/artifice/endpoint_extra.rb b/spec/support/artifice/endpoint_extra.rb index 422f65401b..31f6822161 100644 --- a/spec/support/artifice/endpoint_extra.rb +++ b/spec/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/support/artifice/endpoint_extra_api.rb b/spec/support/artifice/endpoint_extra_api.rb index 62e2c2bb93..213b8e5895 100644 --- a/spec/support/artifice/endpoint_extra_api.rb +++ b/spec/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/support/artifice/endpoint_extra_missing.rb b/spec/support/artifice/endpoint_extra_missing.rb index 038a12610a..ee129025ff 100644 --- a/spec/support/artifice/endpoint_extra_missing.rb +++ b/spec/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/support/artifice/endpoint_fallback.rb b/spec/support/artifice/endpoint_fallback.rb index 554c08f0a2..08edf232e3 100644 --- a/spec/support/artifice/endpoint_fallback.rb +++ b/spec/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/support/artifice/endpoint_host_redirect.rb b/spec/support/artifice/endpoint_host_redirect.rb index cda5664be2..338cbcad00 100644 --- a/spec/support/artifice/endpoint_host_redirect.rb +++ b/spec/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/support/artifice/endpoint_marshal_fail.rb b/spec/support/artifice/endpoint_marshal_fail.rb index 2a5dcdc2fd..22c13e3e17 100644 --- a/spec/support/artifice/endpoint_marshal_fail.rb +++ b/spec/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/support/artifice/endpoint_mirror_source.rb b/spec/support/artifice/endpoint_mirror_source.rb index 64452f198d..318866e420 100644 --- a/spec/support/artifice/endpoint_mirror_source.rb +++ b/spec/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/support/artifice/endpoint_redirect.rb b/spec/support/artifice/endpoint_redirect.rb index ebf01458ba..ee97fccf64 100644 --- a/spec/support/artifice/endpoint_redirect.rb +++ b/spec/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/support/artifice/endpoint_strict_basic_authentication.rb b/spec/support/artifice/endpoint_strict_basic_authentication.rb index 905a519f3f..4d4da08770 100644 --- a/spec/support/artifice/endpoint_strict_basic_authentication.rb +++ b/spec/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/support/artifice/endpoint_timeout.rb b/spec/support/artifice/endpoint_timeout.rb index 3f60471c90..c118da1893 100644 --- a/spec/support/artifice/endpoint_timeout.rb +++ b/spec/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/support/artifice/vcr.rb b/spec/support/artifice/vcr.rb index 1e3809ff62..a46f8e9391 100644 --- a/spec/support/artifice/vcr.rb +++ b/spec/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/support/artifice/windows.rb b/spec/support/artifice/windows.rb index 0630798df0..ce7455b86c 100644 --- a/spec/support/artifice/windows.rb +++ b/spec/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/support/helpers.rb b/spec/support/helpers.rb index 76a1f77b72..1099602fc1 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -78,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.ui.silence { Bundler.setup(#{groups}) }\n" + setup = "require '#{lib_dir}/bundler' ; Bundler.ui.silence { Bundler.setup(#{groups}) }\n" ruby(setup + cmd, opts) end bang :run @@ -96,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 @@ -125,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| @@ -178,7 +174,7 @@ module Spec def ruby(ruby, options = {}) env = (options.delete(:env) || {}).map {|k, v| "#{k}='#{v}' " }.join ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" } - lib_option = options[:no_lib] ? "" : " -I#{lib}" + lib_option = options[:no_lib] ? "" : " -I#{lib_dir}" sys_exec(%(#{env}#{Gem.ruby}#{lib_option} -e "#{ruby}")) end bang :ruby @@ -195,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 diff --git a/spec/support/path.rb b/spec/support/path.rb index 79b55dd42a..b957e24abe 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -131,7 +131,7 @@ module Spec tmp("libs", *args) end - def lib + def lib_dir root.join("lib") end diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb index b89d704e65..31f7cc4b08 100644 --- a/spec/support/rubygems_version_manager.rb +++ b/spec/support/rubygems_version_manager.rb @@ -85,7 +85,7 @@ private def resolve_local_copy_path return expanded_env_version if env_version_is_path? - rubygems_path = Pathname.new("../../tmp/rubygems").expand_path(__dir__) + rubygems_path = root.join("tmp/rubygems") unless rubygems_path.directory? rubygems_path.parent.mkpath |