Skip to content

Commit 77be14b

Browse files
committed
🐛 Handling of ENV, and BUNDLE_PATH specifically
Fixes #21 Thanks to @richard-kramer for the report!
1 parent 27dd47a commit 77be14b

File tree

8 files changed

+35
-418
lines changed

8 files changed

+35
-418
lines changed

docs/Appraisal/Git.html

Lines changed: 0 additions & 399 deletions
Large diffs are not rendered by default.

lib/appraisal/command.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ def initialize(command, options = {})
1515
end
1616

1717
def run
18+
# Capture BUNDLE_PATH from the current environment before with_original_env scrubs it
19+
bundle_path = ENV["BUNDLE_PATH"]
1820
run_env = test_environment.merge(env)
1921

2022
if @skip_bundle_exec
2123
execute(run_env)
2224
else
2325
Bundler.with_original_env do
26+
# Restore BUNDLE_PATH if it was set
27+
ENV["BUNDLE_PATH"] = bundle_path if bundle_path
2428
ensure_bundler_is_available
2529
execute(run_env)
2630
end

spec/acceptance/bundle_with_custom_path_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe "Bundle with custom path" do
4-
let(:gem_name) { "rack" }
4+
let(:gem_name) { "include_with_respect" }
55
let(:path) { "vendor/bundle" }
66

77
shared_examples "gemfile dependencies are satisfied" do

spec/acceptance/cli/named_appraisal_install_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
before do
6868
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
6969
appraise 'rails-7' do
70-
gem 'rack', '~> 2.2.0'
70+
gem 'status_tag', '~> 0.2'
7171
end
7272
APPRAISAL
7373
end

spec/acceptance/cli/named_appraisal_update_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
before do
5757
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
5858
appraise 'rails-7' do
59-
gem 'rake', '~> 13.0'
59+
gem 'status_tag', '~> 0.2'
6060
end
6161
APPRAISAL
6262

spec/acceptance/cli/ore_install_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
RSpec.describe "CLI with ore", ".install --gem-manager=ore", :ore do
66
it "installs the dependencies using ore" do
77
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
8-
appraise 'rack_1' do
9-
gem 'rack', '~> 2.2.0'
8+
appraise 'via_ore' do
9+
gem 'status_tag', '~> 0.2'
1010
end
1111
APPRAISAL
1212

1313
output = run "appraisal install --gem-manager=ore"
1414

1515
expect(output).to include("ore lock")
1616
expect(output).to include("ore install")
17-
expect(file("gemfiles/rack_1.gemfile.lock")).to be_exists
17+
expect(file("gemfiles/via_ore.gemfile.lock")).to be_exists
1818
end
1919

2020
context "with jobs option" do
2121
it "passes -workers flag to ore" do
2222
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
23-
appraise 'rack_workers' do
24-
gem 'rack', '~> 2.2.0'
23+
appraise 'ore_workers' do
24+
gem 'status_tag', '~> 0.2'
2525
end
2626
APPRAISAL
2727

@@ -35,8 +35,8 @@
3535
context "with path option" do
3636
it "passes -vendor flag to ore" do
3737
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
38-
appraise 'rack_vendor' do
39-
gem 'rack', '~> 2.2.0'
38+
appraise 'ore_vendor' do
39+
gem 'status_tag', '~> 0.2'
4040
end
4141
APPRAISAL
4242

@@ -51,8 +51,8 @@
5151
context "with without option" do
5252
it "passes -without flag to ore with comma-separated groups" do
5353
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
54-
appraise 'rack_without' do
55-
gem 'rack', '~> 2.2.0'
54+
appraise 'ore_without' do
55+
gem 'status_tag', '~> 0.2'
5656
end
5757
APPRAISAL
5858

spec/acceptance/cli/ore_update_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
before do
77
build_appraisal_file <<-APPRAISAL.strip_heredoc.rstrip
88
appraise 'rack_update' do
9-
gem 'rack', '~> 2.2.0'
9+
gem 'status_tag', '~> 0.2'
1010
end
1111
APPRAISAL
1212

spec/appraisal/command_spec.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,26 @@
6969
end
7070
end
7171

72-
context "when skip_bundle_exec is true" do
73-
let(:command) { described_class.new(command_string, :gemfile => gemfile, :skip_bundle_exec => true) }
74-
75-
it "does not wrap execution in Bundler.with_original_env and does not ensure bundler" do
76-
expect(Bundler).not_to receive(:with_original_env)
77-
expect(command).not_to receive(:ensure_bundler_is_available)
72+
context "with BUNDLE_PATH set in environment" do
73+
it "preserves BUNDLE_PATH within Bundler.with_original_env" do
74+
ENV["BUNDLE_PATH"] = "/custom/path"
75+
76+
# We need to mock Bundler.with_original_env to actually yield
77+
# but also simulate it scrubbing the environment as it would in reality
78+
allow(Bundler).to receive(:with_original_env) do |&block|
79+
old_bundle_path = ENV.delete("BUNDLE_PATH")
80+
block.call
81+
ENV["BUNDLE_PATH"] = old_bundle_path
82+
end
83+
84+
expect(Kernel).to receive(:system) do
85+
expect(ENV["BUNDLE_PATH"]).to eq("/custom/path")
86+
true
87+
end
7888

7989
command.run
90+
91+
ENV.delete("BUNDLE_PATH")
8092
end
8193
end
8294
end

0 commit comments

Comments
 (0)