Class | Spec::Runner::SpecParser
In: | lib/spec/runner/spec_parser.rb
Parent: | Object

Parses a spec file and finds the nearest example for a given line number.

### Methods

consider_example_for_best_match consider_example_groups_for_best_match is_best_match? new parse_backtrace spec_name_for

### Attributes

best_match | [R] |

### Public Class methods

new()

[Source]

       # File lib/spec/runner/spec_parser.rb, line 7
    7:       def initialize
    8:         @best_match = {}
    9:       end

### Public Instance methods

spec_name_for(file, line_number)

[Source]

        # File lib/spec/runner/spec_parser.rb, line 11
    11:       def spec_name_for(file, line_number)
    12:         best_match.clear
    13:         file = File.expand_path(file)
    14:         rspec_options.example_groups.each do |example_group|
    15:           consider_example_groups_for_best_match example_group, file, line_number
    16:
    17:           example_group.examples.each do |example|
    18:             consider_example_for_best_match example, example_group, file, line_number
    19:           end
    20:         end
    21:         if best_match[:example_group]
    22:           if best_match[:example]
    23:             "#{best_match[:example_group].description} #{best_match[:example].description}"
    24:           else
    25:             best_match[:example_group].description
    26:           end
    27:         else
    28:           nil
    29:         end
    30:       end

### Protected Instance methods

consider_example_for_best_match(example, example_group, file, line_number)

[Source]

        # File lib/spec/runner/spec_parser.rb, line 45
    45:       def consider_example_for_best_match(example, example_group, file, line_number)
    46:         parsed_backtrace = parse_backtrace(example.implementation_backtrace)
    47:         parsed_backtrace.each do |example_file, example_line|
    48:           if is_best_match?(file, line_number, example_file, example_line)
    49:             best_match.clear
    50:             best_match[:example_group] = example_group
    51:             best_match[:example] = example
    52:             best_match[:line] = example_line
    53:           end
    54:         end
    55:       end

consider_example_groups_for_best_match(example_group, file, line_number)

[Source]

        # File lib/spec/runner/spec_parser.rb, line 34
    34:       def consider_example_groups_for_best_match(example_group, file, line_number)
    35:         parsed_backtrace = parse_backtrace(example_group.registration_backtrace)
    36:         parsed_backtrace.each do |example_file, example_line|
    37:           if is_best_match?(file, line_number, example_file, example_line)
    38:             best_match.clear
    39:             best_match[:example_group] = example_group
    40:             best_match[:line] = example_line
    41:           end
    42:         end
    43:       end

is_best_match?(file, line_number, example_file, example_line)

[Source]

        # File lib/spec/runner/spec_parser.rb, line 57
    57:       def is_best_match?(file, line_number, example_file, example_line)
    58:         file == File.expand_path(example_file) &&
    59:         example_line <= line_number &&
    60:         example_line > best_match[:line].to_i
    61:       end

parse_backtrace(backtrace)

[Source]

        # File lib/spec/runner/spec_parser.rb, line 63
    63:       def parse_backtrace(backtrace)
    64:         backtrace.collect do |trace_line|
    65:           split_line = trace_line.split(':')
    66:           [split_line[0], Integer(split_line[1])]
    67:         end
    68:       end

[Validate]