Class: Coatepec::Spec::ProcessStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/coatepec/spec/process_strategy.rb

Overview

Shared child-process lifecycle for running an isolated RSpec run: spawns (via a subclass's #start), reaps with a timeout budget (TERM then KILL on overrun), and hands the captured output/JSON to Result. Subclasses (ForkStrategy, SpawnStrategy) only implement how the child is started.

Direct Known Subclasses

ForkStrategy, SpawnStrategy

Instance Method Summary collapse

Constructor Details

#initialize(project_root, project: nil, rails_runtime: nil) ⇒ ProcessStrategy

Returns a new instance of ProcessStrategy.



12
13
14
15
16
# File 'lib/coatepec/spec/process_strategy.rb', line 12

def initialize(project_root, project: nil, rails_runtime: nil)
  @project_root = project_root
  @project = project
  @rails_runtime = rails_runtime
end

Instance Method Details

#run(args, timeout_seconds) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/coatepec/spec/process_strategy.rb', line 18

def run(args, timeout_seconds)
  out_r, out_w = IO.pipe
  err_r, err_w = IO.pipe
  json_path = Tempfile.create(["coatepec-rspec", ".json"], &:path)

  pid = start_or_release(args, out_w, err_w, json_path, [out_r, err_r])
  [out_w, err_w].each(&:close)

  reap(pid, out_r, err_r, timeout_seconds, json_path)
end