Skip to content

Commit

Permalink
command: support running under test
Browse files Browse the repository at this point in the history
Introduce a new 'APPRAISAL_UNDER_TEST' environment variable that
`Command` uses to determine if Appraisal itself is under test, and if
so, tweaks the environment in the way the tests require. This allows the
tests to pass while using `Bundler.with_original_env`.

Fix #173.

Signed-off-by: Kyle Fazzari <[email protected]>
  • Loading branch information
kyrofa committed Jan 17, 2023
1 parent 7af659a commit 6680c58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/appraisal/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ def initialize(command, options = {})
end

def run
run_env = test_environment.merge(env)

Bundler.with_original_env do
ensure_bundler_is_available
announce

ENV["BUNDLE_GEMFILE"] = gemfile
ENV["APPRAISAL_INITIALIZED"] = "1"
env.each_pair do |key, value|
run_env.each_pair do |key, value|
ENV[key] = value
end

Expand Down Expand Up @@ -79,5 +81,14 @@ def command_as_string
command
end
end

def test_environment
return {} unless ENV["APPRAISAL_UNDER_TEST"] == "1"

{
"GEM_HOME" => ENV["GEM_HOME"],
"GEM_PATH" => "",
}
end
end
end
4 changes: 3 additions & 1 deletion spec/acceptance/bundle_without_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
output = run "appraisal install --without drinks"

expect(output).to include("Bundle complete")
expect(output).to include("Gems in the group drinks were not installed.")
expect(output).to(
match(/Gems in the group ['"]?drinks['"]? were not installed/)
)
expect(output).not_to include("orange_juice")
expect(output).not_to include("coffee")
expect(output).not_to include("soda")
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
TMP_GEM_ROOT = File.join(PROJECT_ROOT, "tmp", "gems")
ENV["APPRAISAL_UNDER_TEST"] = "1"

RSpec.configure do |config|
config.raise_errors_for_deprecations!
Expand Down

0 comments on commit 6680c58

Please sign in to comment.