Class: SixthSense::Adapters::Minitest

Inherits:
FrameworkAdapter show all
Defined in:
lib/sixth_sense/adapters/minitest.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

ASSERTION_PREFIXES =
%w[assert refute].freeze

Instance Method Summary collapse

Methods inherited from FrameworkAdapter

#assertion_patterns, #checked_coverage_test_command, #coverage_test_command, for_path, #mutation_test_command, register, registry

Instance Method Details

#handles?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
# File 'lib/sixth_sense/adapters/minitest.rb', line 15

def handles?(path)
  return false unless path.end_with?("_test.rb")
  return false unless File.file?(path)

  source = File.read(path)
  return false if source.match?(/\bTest::Unit::TestCase\b/)

  source.match?(/\b(Minitest::Test|assert_|refute_|assert\b|refute\b)/)
end

#map_to_sut(test_file) ⇒ Object



51
52
53
# File 'lib/sixth_sense/adapters/minitest.rb', line 51

def map_to_sut(test_file)
  map_to_sut_path(test_file.path)
end

#mutation_session(test_files:) ⇒ Object



47
48
49
# File 'lib/sixth_sense/adapters/minitest.rb', line 47

def mutation_session(test_files:)
  { framework: :minitest, test_files: test_files.map(&:path), runner: "ruby" }
end

#parse(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sixth_sense/adapters/minitest.rb', line 25

def parse(path)
  parsed = Prism.parse_file(path)
  unless parsed.success?
    messages = parsed.errors.map(&:message).join(", ")
    raise Error, "failed to parse #{path}: #{messages}"
  end

  Model::TestFile.new(
    path: path,
    framework: :minitest,
    test_cases: Parser.new(path, parsed.value).test_cases,
    sut_candidates: map_to_sut_path(path),
    metadata: {}
  )
end

#run_with_coverage(test_files:, isolation:) ⇒ Object



41
42
43
44
45
# File 'lib/sixth_sense/adapters/minitest.rb', line 41

def run_with_coverage(test_files:, isolation:)
  require_relative "../runners/coverage_runner"

  Runners::CoverageRunner.new.run(test_files: test_files, isolation: isolation)
end