Class: Appraisal::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/appraisal/command.rb

Overview

Executes commands with a clean environment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, options = {}) ⇒ Command

Returns a new instance of Command.



8
9
10
11
12
# File 'lib/appraisal/command.rb', line 8

def initialize(command, options = {})
  @gemfile = options[:gemfile]
  @env = options.fetch(:env, {})
  @command = command_starting_with_bundle(command)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/appraisal/command.rb', line 6

def command
  @command
end

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/appraisal/command.rb', line 6

def env
  @env
end

#gemfileObject (readonly)

Returns the value of attribute gemfile.



6
7
8
# File 'lib/appraisal/command.rb', line 6

def gemfile
  @gemfile
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/appraisal/command.rb', line 14

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"
    run_env.each_pair do |key, value|
      ENV[key] = value
    end

    unless Kernel.system(command_as_string)
      exit(1)
    end
  end
end