Class: RailsProof::TestRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_proof/test_runner.rb

Defined Under Namespace

Classes: Error, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, test_file_path:) ⇒ TestRunner

Returns a new instance of TestRunner.



21
22
23
24
# File 'lib/rails_proof/test_runner.rb', line 21

def initialize(root:, test_file_path:)
  @root = Pathname.new(root).expand_path
  @test_file_path = Pathname.new(test_file_path)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



19
20
21
# File 'lib/rails_proof/test_runner.rb', line 19

def root
  @root
end

#test_file_pathObject (readonly)

Returns the value of attribute test_file_path.



19
20
21
# File 'lib/rails_proof/test_runner.rb', line 19

def test_file_path
  @test_file_path
end

Instance Method Details

#commandObject



44
45
46
# File 'lib/rails_proof/test_runner.rb', line 44

def command
  @command ||= resolve_runner.fetch(:command)
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rails_proof/test_runner.rb', line 26

def run
  stdout, stderr, status = Open3.capture3(
    { "RAILS_ENV" => "test" },
    *command,
    chdir: working_directory.to_s
  )

  output = [stdout, stderr].reject(&:empty?).join

  raise_unavailable_test_api!(output)

  Result.new(
    passed: status.success?,
    output: output,
    command: command
  )
end

#working_directoryObject



48
49
50
# File 'lib/rails_proof/test_runner.rb', line 48

def working_directory
  @working_directory ||= resolve_runner.fetch(:working_directory)
end