Class: AIRefactor::TestRunners::RSpecRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ai_refactor/test_runners/rspec_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path, command_template: "bundle exec rspec __FILE__") ⇒ RSpecRunner

Returns a new instance of RSpecRunner.



8
9
10
11
# File 'lib/ai_refactor/test_runners/rspec_runner.rb', line 8

def initialize(file_path, command_template: "bundle exec rspec __FILE__")
  @file_path = file_path
  @command_template = command_template
end

Instance Method Details

#commandObject



13
14
15
# File 'lib/ai_refactor/test_runners/rspec_runner.rb', line 13

def command
  @command_template.gsub("__FILE__", @file_path)
end

#runObject



17
18
19
20
21
22
23
# File 'lib/ai_refactor/test_runners/rspec_runner.rb', line 17

def run
  stdout, stderr, status = Open3.capture3(command)
  _matched, example_count, failure_count = stdout.match(/(\d+) examples?, (\d+) failures?/).to_a
  pending_count = stdout.match(/(\d+) pending/)&.values_at(1) || "0"
  errored = stdout.match(/, (\d+) errors? occurred outside of examples/)&.values_at(1) || "0"
  TestRunResult.new(stdout, stderr, status, example_count, failure_count, pending_count, errored)
end