Class: MightyTest::TestParser

Inherits:
Object
  • Object
show all
Defined in:
lib/mighty_test/test_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_path) ⇒ TestParser

Returns a new instance of TestParser.



3
4
5
# File 'lib/mighty_test/test_parser.rb', line 3

def initialize(test_path)
  @path = test_path.to_s
end

Instance Method Details

#test_name_at_line(number) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/mighty_test/test_parser.rb', line 7

def test_name_at_line(number)
  method_name = nil
  lines = File.read(path).lines
  lines[2...number].reverse_each.find do |line|
    method_name =
      match_minitest_method_name(line) ||
      match_active_support_test_string(line)&.then { "test_#{_1.gsub(/\s+/, '_')}" }
  end
  method_name
end