Method: Jasmine::SpecBuilder#guess_example_locations

Defined in:
lib/jasmine/spec_builder.rb

#guess_example_locationsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jasmine/spec_builder.rb', line 30

def guess_example_locations
  @example_locations = {}

  example_name_parts = []
  previous_indent_level = 0
  @config.spec_files_full_paths.each do |filename|
    line_number = 1
    File.open(filename, "r") do |file|
      file.readlines.each do |line|
        match = /^(\s*)(describe|it)\s*\(\s*["'](.*)["']\s*,\s*function/.match(line)
        if (match)
          indent_level = match[1].length / 2
          example_name = match[3]
          example_name_parts[indent_level] = example_name

          full_example_name = example_name_parts.slice(0, indent_level + 1).join(" ")
          @example_locations[full_example_name] = "#{filename}:#{line_number}: in `it'"
        end
        line_number += 1
      end
    end
  end
end