Module: Rails::TestUnit::TestParser
- Defined in:
- railties/lib/rails/test_unit/test_parser.rb
Overview
Parse a test file to extract the line ranges of all tests in both method-style (def test_foo) and declarative-style (test “foo” do)
Class Method Summary collapse
-
.definition_for(method) ⇒ Object
Helper to translate a method object into the path and line range where the method was defined.
- .ranges(filepath) ⇒ Object
Class Method Details
.definition_for(method) ⇒ Object
Helper to translate a method object into the path and line range where the method was defined.
13 14 15 16 17 18 |
# File 'railties/lib/rails/test_unit/test_parser.rb', line 13 def self.definition_for(method) filepath, start_line = method.source_location @begins_to_ends[filepath] ||= ranges(filepath) return unless end_line = @begins_to_ends[filepath][start_line] [filepath, start_line..end_line] end |
.ranges(filepath) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'railties/lib/rails/test_unit/test_parser.rb', line 21 def self.ranges(filepath) queue = [Prism.parse_file(filepath).value] begins_to_ends = {} while (node = queue.shift) case node.type when :def_node begins_to_ends[node.location.start_line] = node.location.end_line when :call_node begins_to_ends[node.location.start_line] = node.location.end_line end queue.concat(node.compact_child_nodes) end begins_to_ends end |