diff --git a/spec/runtime/env_helpers_spec.rb b/spec/runtime/env_helpers_spec.rb index c4ebdd1fd289..38f501e7cde6 100644 --- a/spec/runtime/env_helpers_spec.rb +++ b/spec/runtime/env_helpers_spec.rb @@ -21,7 +21,7 @@ def run_bundler_script(env, script) create_file("source.rb", <<-RUBY) print Bundler.original_env["PATH"] RUBY - path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo" + path = default_system_path + "#{File::PATH_SEPARATOR}/foo" with_path_as(path) do bundle_exec_ruby(bundled_app("source.rb").to_s) expect(stdboth).to eq(path) @@ -49,7 +49,7 @@ def run_bundler_script(env, script) end exec(Gem.ruby, __FILE__, (count - 1).to_s) RUBY - path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby) + path = default_system_path + File::PATH_SEPARATOR + File.dirname(Gem.ruby) with_path_as(path) do build_bundler_context bundle_exec_ruby("#{bundled_app("exe.rb")} 2") diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 8798cca57bb5..7925663dd1d1 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -428,6 +428,12 @@ def with_gem_path_as(path) end end + # Windows has no `getconf`, and its current PATH holds the directories the + # Ruby under test finds its DLLs in, so keep it as is there. + def default_system_path + Gem.win_platform? ? ENV["PATH"] : `getconf PATH`.strip + end + def with_path_as(path) without_env_side_effects do ENV["PATH"] = path.to_s