summaryrefslogtreecommitdiff
path: root/spec/bundler/runtime/with_unbundled_env_spec.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-08 14:19:04 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-13 07:54:37 +0900
commit0e60b59d5884edb8f9aea023efd9b24f1ff02049 (patch)
treee52935ce510440872ca5ce6b0e092cbc94f18bc9 /spec/bundler/runtime/with_unbundled_env_spec.rb
parent68224651a4d4dc3ce0cea666f5423dd8b6ba6cfc (diff)
Update the bundler version with master branch
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3086
Diffstat (limited to 'spec/bundler/runtime/with_unbundled_env_spec.rb')
-rw-r--r--spec/bundler/runtime/with_unbundled_env_spec.rb110
1 files changed, 64 insertions, 46 deletions
diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb
index 4aaf9d499c..80c5d92b76 100644
--- a/spec/bundler/runtime/with_unbundled_env_spec.rb
+++ b/spec/bundler/runtime/with_unbundled_env_spec.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
RSpec.describe "Bundler.with_env helpers" do
- def bundle_exec_ruby!(code, options = {})
+ def bundle_exec_ruby!(args, options = {})
build_bundler_context options
- bundle! "exec '#{Gem.ruby}' -e #{code}", options
+ bundle! "exec '#{Gem.ruby}' #{args}", options
end
def build_bundler_context(options = {})
@@ -12,39 +12,47 @@ RSpec.describe "Bundler.with_env helpers" do
bundle "install", options
end
+ def run_bundler_script(env, script)
+ system(env, "ruby", "-I#{lib_dir}", "-rbundler", script.to_s)
+ end
+
describe "Bundler.original_env" do
it "should return the PATH present before bundle was activated" do
- code = "print Bundler.original_env['PATH']"
+ create_file("source.rb", <<-RUBY)
+ print Bundler.original_env["PATH"]
+ RUBY
path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo"
with_path_as(path) do
- bundle_exec_ruby!(code.dump)
+ bundle_exec_ruby!(bundled_app("source.rb").to_s)
expect(last_command.stdboth).to eq(path)
end
end
it "should return the GEM_PATH present before bundle was activated" do
- code = "print Bundler.original_env['GEM_PATH']"
- gem_path = ENV["GEM_PATH"] + ":/foo"
+ create_file("source.rb", <<-RUBY)
+ print Bundler.original_env['GEM_PATH']
+ RUBY
+ gem_path = ENV["GEM_PATH"] + "#{File::PATH_SEPARATOR}/foo"
with_gem_path_as(gem_path) do
- bundle_exec_ruby!(code.dump)
+ bundle_exec_ruby!(bundled_app("source.rb").to_s)
expect(last_command.stdboth).to eq(gem_path)
end
end
it "works with nested bundle exec invocations" do
- create_file("exe.rb", <<-'RB')
+ create_file("exe.rb", <<-'RUBY')
count = ARGV.first.to_i
exit if count < 0
- STDERR.puts "#{count} #{ENV["PATH"].end_with?(":/foo")}"
+ STDERR.puts "#{count} #{ENV["PATH"].end_with?("#{File::PATH_SEPARATOR}/foo")}"
if count == 2
- ENV["PATH"] = "#{ENV["PATH"]}:/foo"
+ ENV["PATH"] = "#{ENV["PATH"]}#{File::PATH_SEPARATOR}/foo"
end
exec(Gem.ruby, __FILE__, (count - 1).to_s)
- RB
+ RUBY
path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby)
with_path_as(path) do
build_bundler_context
- bundle! "exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2"
+ bundle_exec_ruby!("#{bundled_app("exe.rb")} 2")
end
expect(err).to eq <<-EOS.strip
2 false
@@ -58,40 +66,50 @@ RSpec.describe "Bundler.with_env helpers" do
ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) })
original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")')
- code = 'puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")'
- bundle_exec_ruby! code.dump
+ create_file("source.rb", <<-RUBY)
+ puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")
+ RUBY
+ bundle_exec_ruby! bundled_app("source.rb")
expect(out).to eq original
end
end
shared_examples_for "an unbundling helper" do
it "should delete BUNDLE_PATH" do
- code = "print #{modified_env}.has_key?('BUNDLE_PATH')"
+ create_file("source.rb", <<-RUBY)
+ print #{modified_env}.has_key?('BUNDLE_PATH')
+ RUBY
ENV["BUNDLE_PATH"] = "./foo"
- bundle_exec_ruby! code.dump
+ bundle_exec_ruby! bundled_app("source.rb")
expect(last_command.stdboth).to include "false"
end
it "should remove '-rbundler/setup' from RUBYOPT" do
- code = "print #{modified_env}['RUBYOPT']"
+ create_file("source.rb", <<-RUBY)
+ print #{modified_env}['RUBYOPT']
+ RUBY
ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}"
- bundle_exec_ruby! code.dump, :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" }
+ bundle_exec_ruby! bundled_app("source.rb"), :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" }
expect(last_command.stdboth).not_to include("-rbundler/setup")
end
it "should restore RUBYLIB", :ruby_repo do
- code = "print #{modified_env}['RUBYLIB']"
+ create_file("source.rb", <<-RUBY)
+ print #{modified_env}['RUBYLIB']
+ RUBY
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
+ bundle_exec_ruby! bundled_app("source.rb")
expect(last_command.stdboth).to include("/foo-original")
end
it "should restore the original MANPATH" do
- code = "print #{modified_env}['MANPATH']"
+ create_file("source.rb", <<-RUBY)
+ print #{modified_env}['MANPATH']
+ RUBY
ENV["MANPATH"] = "/foo"
ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original"
- bundle_exec_ruby! code.dump
+ bundle_exec_ruby! bundled_app("source.rb")
expect(last_command.stdboth).to include("/foo-original")
end
end
@@ -111,7 +129,7 @@ RSpec.describe "Bundler.with_env helpers" do
describe "Bundler.with_original_env" do
it "should set ENV to original_env in the block" do
expected = Bundler.original_env
- actual = Bundler.with_original_env { ENV.to_hash }
+ actual = Bundler.with_original_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
expect(actual).to eq(expected)
end
@@ -129,7 +147,7 @@ RSpec.describe "Bundler.with_env helpers" do
expected = Bundler.unbundled_env
actual = Bundler.ui.silence do
- Bundler.with_clean_env { ENV.to_hash }
+ Bundler.with_clean_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
end
expect(actual).to eq(expected)
@@ -147,7 +165,7 @@ RSpec.describe "Bundler.with_env helpers" do
describe "Bundler.with_unbundled_env" do
it "should set ENV to unbundled_env in the block" do
expected = Bundler.unbundled_env
- actual = Bundler.with_unbundled_env { ENV.to_hash }
+ actual = Bundler.with_unbundled_env { Bundler::EnvironmentPreserver.env_to_hash(ENV) }
expect(actual).to eq(expected)
end
@@ -161,53 +179,53 @@ RSpec.describe "Bundler.with_env helpers" do
end
describe "Bundler.original_system" do
- let(:code) do
- <<~RUBY
- Bundler.original_system(%([ "\$BUNDLE_FOO" = "bar" ] && exit 42))
+ before do
+ create_file("source.rb", <<-'RUBY')
+ Bundler.original_system("ruby", "-e", "exit(42) if ENV['BUNDLE_FOO'] == 'bar'")
exit $?.exitstatus
RUBY
end
it "runs system inside with_original_env" do
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'")
+ run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(42)
end
end
describe "Bundler.clean_system", :bundler => 2 do
- let(:code) do
- <<~RUBY
- Bundler.ui.silence { Bundler.clean_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42)) }
+ before do
+ create_file("source.rb", <<-'RUBY')
+ Bundler.ui.silence { Bundler.clean_system("ruby", "-e", "exit(42) unless ENV['BUNDLE_FOO'] == 'bar'") }
exit $?.exitstatus
RUBY
end
it "runs system inside with_clean_env" do
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'")
+ run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(42)
end
end
describe "Bundler.unbundled_system" do
- let(:code) do
- <<~RUBY
- Bundler.unbundled_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42))
+ before do
+ create_file("source.rb", <<-'RUBY')
+ Bundler.unbundled_system("ruby", "-e", "exit(42) unless ENV['BUNDLE_FOO'] == 'bar'")
exit $?.exitstatus
RUBY
end
it "runs system inside with_unbundled_env" do
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'")
+ run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(42)
end
end
describe "Bundler.original_exec" do
- let(:code) do
- <<~RUBY
+ before do
+ create_file("source.rb", <<-'RUBY')
Process.fork do
exit Bundler.original_exec(%(test "\$BUNDLE_FOO" = "bar"))
end
@@ -221,14 +239,14 @@ RSpec.describe "Bundler.with_env helpers" do
it "runs exec inside with_original_env" do
skip "Fork not implemented" if Gem.win_platform?
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'")
+ run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(0)
end
end
describe "Bundler.clean_exec", :bundler => 2 do
- let(:code) do
- <<~RUBY
+ before do
+ create_file("source.rb", <<-'RUBY')
Process.fork do
exit Bundler.ui.silence { Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar")) }
end
@@ -242,14 +260,14 @@ RSpec.describe "Bundler.with_env helpers" do
it "runs exec inside with_clean_env" do
skip "Fork not implemented" if Gem.win_platform?
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'")
+ run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(1)
end
end
describe "Bundler.unbundled_exec" do
- let(:code) do
- <<~RUBY
+ before do
+ create_file("source.rb", <<-'RUBY')
Process.fork do
exit Bundler.unbundled_exec(%(test "\$BUNDLE_FOO" = "bar"))
end
@@ -263,7 +281,7 @@ RSpec.describe "Bundler.with_env helpers" do
it "runs exec inside with_clean_env" do
skip "Fork not implemented" if Gem.win_platform?
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib_dir} -rbundler -e '#{code}'")
+ run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(1)
end
end