Sha256: 7584ea73034f23029f7f52f5e19769f4d21cd0aadd6f313a9dba9d10cb329586

Contents?: true

Size: 835 Bytes

Versions: 4

Compression:

Stored size: 835 Bytes

Contents

# frozen_string_literal: true

require "open3"

module AIRefactor
  module Tests
    class RSpecRunner
      def initialize(file_path, command_template: "bundle exec rspec __FILE__")
        @file_path = file_path
        @command_template = command_template
      end

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

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ai_refactor-0.3.1 lib/ai_refactor/refactors/tests/rspec_runner.rb
ai_refactor-0.3.0 lib/ai_refactor/refactors/tests/rspec_runner.rb
ai_refactor-0.2.0 lib/ai_refactor/refactors/tests/rspec_runner.rb
ai_refactor-0.1.0 lib/ai_refactor/refactors/tests/rspec_runner.rb