Skip to content

Commit 9858303

Browse files
authored
Merge pull request #749 from cucumber/issue-699-disable-bundler-using-bundler-tooling-0-14-stable
Disable bundler using bundler tooling (0-14-stable)
2 parents a596709 + a43f930 commit 9858303

File tree

5 files changed

+64
-11
lines changed

5 files changed

+64
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,51 @@
11
Feature: Disable Bundler environment
22
Use the @disable-bundler tag to escape from your project's Gemfile.
33

4-
Background:
5-
Given I use the fixture "cli-app"
6-
4+
@disable-bundler
75
Scenario: Clear the Bundler environment
8-
6+
Given I use the fixture "cli-app"
97
Given a file named "features/run.feature" with:
108
"""
119
Feature: My Feature
1210
@disable-bundler
1311
Scenario: Check environment
1412
When I run `env`
1513
Then the output should not match /^BUNDLE_GEMFILE=/
14+
15+
@disable-bundler
16+
Scenario: Run bundle in a fresh bundler environment
17+
Given a file named "Gemfile" with:
18+
\"\"\"
19+
source 'https://rubygems.org'
20+
\"\"\"
21+
When I run `bundle`
22+
Then the output should not contain "aruba"
23+
24+
@disable-bundler
25+
Scenario: Run programs that are not in the outer bundle
26+
Given a file named "Gemfile" with:
27+
\"\"\"
28+
source 'https://rubygems.org'
29+
30+
gem 'rubocop'
31+
\"\"\"
32+
When I run `bundle`
33+
When I run `bundle exec rubocop --help`
34+
Then the output should contain "Usage: rubocop"
1635
"""
17-
When I run `cucumber`
36+
When I run `bundle`
37+
When I run `bundle exec cucumber`
1838
Then the features should all pass
39+
40+
@disable-bundler
41+
Scenario: Direct test
42+
Given I use the fixture "cli-app"
43+
Given a file named "Gemfile" with:
44+
"""
45+
source 'https://rubygems.org'
46+
47+
gem 'parallel_tests'
48+
"""
49+
When I successfully run `bundle`
50+
When I successfully run `bundle exec parallel_rspec --help`
51+
Then the output should contain "Run all tests in parallel"

fixtures/cli-app/Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Use dependencies from gemspec
4+
gemspec

fixtures/cli-app/cli-app.gemspec

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
2121
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2222
spec.require_paths = ['lib']
2323

24-
spec.add_development_dependency 'bundler', '~> 1.9'
25-
spec.add_development_dependency 'rake', '~> 10.0'
24+
spec.add_development_dependency 'bundler'
25+
spec.add_development_dependency 'rake'
26+
spec.add_development_dependency 'aruba'
2627
end

fixtures/empty-app/cli-app.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
2121
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2222
spec.require_paths = ['lib']
2323

24-
spec.add_development_dependency 'bundler', '~> 1.9'
25-
spec.add_development_dependency 'rake', '~> 10.0'
24+
spec.add_development_dependency 'bundler'
25+
spec.add_development_dependency 'rake'
2626
end

lib/aruba/api/bundler.rb

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@ module Bundler
77

88
# Unset variables used by bundler
99
def unset_bundler_env_vars
10-
%w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key|
11-
delete_environment_variable(key)
10+
empty_env = with_environment { with_unbundled_env { ENV.to_h } }
11+
aruba_env = aruba.environment.to_h
12+
(aruba_env.keys - empty_env.keys).each do |key|
13+
delete_environment_variable key
14+
end
15+
empty_env.each do |k, v|
16+
set_environment_variable k, v
17+
end
18+
end
19+
20+
private
21+
22+
def with_unbundled_env
23+
if ::Bundler.respond_to?(:with_unbundled_env)
24+
::Bundler.with_unbundled_env { yield }
25+
else
26+
::Bundler.with_clean_env { yield }
1227
end
1328
end
1429
end

0 commit comments

Comments
 (0)