module Minitest::Line
def describes_with_lines(target_file)
def describes_with_lines(target_file) runnables.map do |runnable| next unless caller = runnable.instance_variable_get(:@minitest_line_caller) next unless line = caller.detect { |line| line.include?(target_file) } ["/#{Regexp.escape(runnable.name)}/", line[/:(\d+):in/, 1].to_i] end.compact end
def methods_with_lines(target_file)
def methods_with_lines(target_file) runnables.flat_map do |runnable| rname = Class.instance_method(:name).bind(runnable).call runnable.runnable_methods.map do |name| file, line = runnable.instance_method(name).source_location next unless file == target_file test_name = (rname ? "#{rname}##{name}" : name) [test_name, line] end end.uniq.compact end
def runnables
def runnables Minitest::Runnable.runnables end
def target_file
def target_file runnables.each do |r| r.runnable_methods.each do |m| file, line = r.instance_method(m).source_location return file if file end end nil end
def tests_with_lines
def tests_with_lines target_file = target_file() methods_with_lines(target_file).concat describes_with_lines(target_file) end