Skip to content

Commit

Permalink
Unset variables using Bundler tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Dec 5, 2020
1 parent 5981a94 commit 8550c91
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
43 changes: 38 additions & 5 deletions features/03_testing_frameworks/cucumber/disable_bunder.feature
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
Feature: Disable Bundler environment
Use the @disable-bundler tag to escape from your project's Gemfile.

Background:
Given I use the fixture "cli-app"

@disable-bundler
Scenario: Clear the Bundler environment

Given I use the fixture "cli-app"
Given a file named "features/run.feature" with:
"""
Feature: My Feature
@disable-bundler
Scenario: Check environment
When I run `env`
Then the output should not match /^BUNDLE_GEMFILE=/
@disable-bundler
Scenario: Run bundle in a fresh bundler environment
Given a file named "Gemfile" with:
\"\"\"
source 'https://rubygems.org'
\"\"\"
When I run `bundle`
Then the output should not contain "aruba"
@disable-bundler
Scenario: Run programs that are not in the outer bundle
Given a file named "Gemfile" with:
\"\"\"
source 'https://rubygems.org'
gem 'rubocop'
\"\"\"
When I run `bundle`
When I run `bundle exec rubocop --help`
Then the output should contain "Usage: rubocop"
"""
When I run `cucumber`
When I run `bundle`
When I run `bundle exec cucumber`
Then the features should all pass

@disable-bundler
Scenario: Direct test
Given I use the fixture "cli-app"
Given a file named "Gemfile" with:
"""
source 'https://rubygems.org'
gem 'parallel_tests'
"""
When I successfully run `bundle`
When I successfully run `bundle exec parallel_rspec --help`
Then the output should contain "Run all tests in parallel"
1 change: 1 addition & 0 deletions fixtures/cli-app/cli-app.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.executables = ['bin/aruba-test-cli']
spec.require_paths = ['lib']

spec.add_development_dependency 'aruba'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
end
19 changes: 17 additions & 2 deletions lib/aruba/api/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ module Bundler

# Unset variables used by bundler
def unset_bundler_env_vars
%w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).each do |key|
delete_environment_variable(key)
empty_env = with_environment { with_unbundled_env { ENV.to_h } }
aruba_env = aruba.environment.to_h
(aruba_env.keys - empty_env.keys).each do |key|
delete_environment_variable key
end
empty_env.each do |k, v|
set_environment_variable k, v
end
end

private

def with_unbundled_env(&block)
if ::Bundler.respond_to?(:with_unbundled_env)
::Bundler.with_unbundled_env(&block)
else
::Bundler.with_clean_env(&block)
end
end
end
Expand Down

0 comments on commit 8550c91

Please sign in to comment.