Class: Wukong::SpecHelpers::IntegrationTestRunner
- Inherits:
-
Object
- Object
- Wukong::SpecHelpers::IntegrationTestRunner
- Defined in:
- lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb
Overview
A runner for running commands in a subprocess.
Instance Attribute Summary collapse
-
#cmd ⇒ Object
The command to execute.
-
#cwd ⇒ Object
The directory in which to execute the command.
-
#exit_code ⇒ Object
The exit code of the spawned process.
-
#pid ⇒ Object
The ID of the spawned subprocess (while it was running).
-
#stderr ⇒ Object
The STDERR of the spawned process.
-
#stdout ⇒ Object
The STDOUT of the spawned process.
Instance Method Summary collapse
- #cmd_summary ⇒ Object
- #env ⇒ Object
- #env_summary ⇒ Object
- #in(dir) ⇒ Object
-
#initialize(args, options) ⇒ IntegrationTestRunner
constructor
Initialize a new IntegrationTestRunner to run a given command.
- #on(*events) ⇒ Object (also: #<)
- #ran? ⇒ Boolean
-
#run! ⇒ true, false
Run the command and capture its outputs and exit code.
- #using(env) ⇒ Object
Constructor Details
#initialize(args, options) ⇒ IntegrationTestRunner
Initialize a new IntegrationTestRunner to run a given command.
48 49 50 51 52 53 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 48 def initialize args, @args = args @env = [:env] @cwd = [:cwd] @inputs = [] end |
Instance Attribute Details
#cmd ⇒ Object
The command to execute
10 11 12 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 10 def cmd @cmd end |
#cwd ⇒ Object
The directory in which to execute the command.
13 14 15 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 13 def cwd @cwd end |
#exit_code ⇒ Object
The exit code of the spawned process.
25 26 27 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 25 def exit_code @exit_code end |
#pid ⇒ Object
The ID of the spawned subprocess (while it was running).
16 17 18 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 16 def pid @pid end |
#stderr ⇒ Object
The STDERR of the spawned process.
22 23 24 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 22 def stderr @stderr end |
#stdout ⇒ Object
The STDOUT of the spawned process.
19 20 21 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 19 def stdout @stdout end |
Instance Method Details
#cmd_summary ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 83 def cmd_summary [ cmd, "with env #{env_summary}", "in dir #{cwd}" ].join("\n") end |
#env ⇒ Object
75 76 77 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 75 def env ENV.to_hash.merge(@env || {}) end |
#env_summary ⇒ Object
91 92 93 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 91 def env_summary { "PATH" => env["PATH"], "RUBYLIB" => env["RUBYLIB"] }.inspect end |
#in(dir) ⇒ Object
65 66 67 68 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 65 def in dir @cwd = dir self end |
#on(*events) ⇒ Object Also known as: <
59 60 61 62 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 59 def on *events @inputs.concat(events) self end |
#ran? ⇒ Boolean
79 80 81 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 79 def ran? @ran end |
#run! ⇒ true, false
Run the command and capture its outputs and exit code.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 30 def run! return false if ran? FileUtils.cd(cwd) do Open3.popen3(env, cmd) do |i, o, e, wait_thr| self.pid = wait_thr.pid @inputs.each { |input| i.puts(input) } i.close self.stdout = o.read self.stderr = e.read self.exit_code = wait_thr.value.to_i end end @ran = true end |
#using(env) ⇒ Object
70 71 72 73 |
# File 'lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb', line 70 def using env @env = env self end |