class Appraisal::Command

Executes commands with a clean environment

Constants

BUNDLER_ENV_VARS

Public Class Methods

from_args(gemfile) click to toggle source
# File lib/appraisal/command.rb, line 6
def self.from_args(gemfile)
  command = ([$0] + ARGV.slice(1, ARGV.size)).join(' ')
  new(command, gemfile)
end
new(command, gemfile = nil) click to toggle source
# File lib/appraisal/command.rb, line 11
def initialize(command, gemfile = nil)
  @original_env = {}
  @gemfile = gemfile
  if command =~ /^bundle/
    @command = command
  else
    @command = "bundle exec #{command}"
  end
end

Public Instance Methods

exec() click to toggle source
# File lib/appraisal/command.rb, line 30
def exec
  announce
  with_clean_env { Kernel.exec(@command) }
end
run() click to toggle source
# File lib/appraisal/command.rb, line 21
def run
  announce
  with_clean_env do
    unless Kernel.system(@command)
      exit(1)
    end
  end
end

Private Instance Methods

announce() click to toggle source
# File lib/appraisal/command.rb, line 45
def announce
  if @gemfile
    puts ">> BUNDLE_GEMFILE=#{@gemfile} #{@command}"
  else
    puts ">> #{@command}"
  end
end
restore_env() click to toggle source
# File lib/appraisal/command.rb, line 60
def restore_env
  @original_env.each { |key, value| ENV[key] = value }
end
unset_bundler_env_vars() click to toggle source
# File lib/appraisal/command.rb, line 53
def unset_bundler_env_vars
  BUNDLER_ENV_VARS.each do |key|
    @original_env[key] = ENV[key]
    ENV[key] = nil
  end
end
with_clean_env() { || ... } click to toggle source
# File lib/appraisal/command.rb, line 37
def with_clean_env
  unset_bundler_env_vars
  ENV['BUNDLE_GEMFILE'] = @gemfile
  yield
ensure
  restore_env
end