require 'shoulda_runner/ast_builder' module ShouldaRunner class Parser def initialize(test_file_path) @source = File.read(test_file_path) end def select_test(linenumber) test_names[linenumber] end private def test_names @asts ||= build_asts hash = {} @asts.each do |ast| ast.each do |node| if node.children.empty? from = node.content[:line_range][:from] to = node.content[:line_range][:to] test_name = build_test_name(node) from.upto(to) do |line| hash[line] = test_name end end end end hash end def build_test_name(node) test_name_string = node.content[:name] parent = node.parent while parent != nil test_name_string = "#{parent.content[:name]}#{test_name_string}" parent = parent.parent end test_name_string end def build_asts ast_builder = AstBuilder.new(@source) ast_builder.parse @asts = ast_builder.asts end end end