Parent

Class Index [+]

Quicksearch

Spec::Runner::LineNumberQuery

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

Attributes

best_match[R]

Public Class Methods

new(run_options) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 7
 7:       def initialize(run_options)
 8:         @best_match = {}
 9:         @run_options = run_options
10:       end

Public Instance Methods

example_line_for(file, line_number) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 27
27:       def example_line_for(file, line_number)
28:         determine_best_match(file, line_number)
29:         best_match[:line]
30:       end
spec_name_for(file, line_number) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 12
12:       def spec_name_for(file, line_number)
13:         best_match.clear
14:         file = File.expand_path(file)
15:         determine_best_match(file, line_number)
16:         if best_match[:example_group]
17:           if best_match[:example]
18:             "#{best_match[:example_group].description} #{best_match[:example].description}"
19:           else
20:             best_match[:example_group].description
21:           end
22:         else
23:           nil
24:         end
25:       end

Protected Instance Methods

consider_example_for_best_match(example, example_group, file, line_number) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 56
56:       def consider_example_for_best_match(example, example_group, file, line_number)
57:         example_file, example_line = parse_location(example.location)
58:         if is_best_match?(file, line_number, example_file, example_line)
59:           best_match.clear
60:           best_match[:example_group] = example_group
61:           best_match[:example] = example
62:           best_match[:line] = example_line
63:         end
64:       end
consider_example_group_for_best_match(example_group, file, line_number) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 47
47:       def consider_example_group_for_best_match(example_group, file, line_number)
48:         example_group_file, example_group_line = parse_location(example_group.location)
49:         if is_best_match?(file, line_number, example_group_file, example_group_line)
50:           best_match.clear
51:           best_match[:example_group] = example_group
52:           best_match[:line] = example_group_line
53:         end
54:       end
determine_best_match(file, line_number) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 34
34:       def determine_best_match(file, line_number)
35:         best_match.clear
36:         file = File.expand_path(file)
37:         @run_options.example_groups.each do |example_group|
38:           next unless example_group.location
39:           consider_example_group_for_best_match(example_group, file, line_number)
40: 
41:           example_group.examples.each do |example|
42:             consider_example_for_best_match(example, example_group, file, line_number)
43:           end
44:         end
45:       end
is_best_match?(file, line_number, example_file, example_line) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 66
66:       def is_best_match?(file, line_number, example_file, example_line)
67:         file == File.expand_path(example_file) &&
68:                 example_line <= line_number &&
69:                 example_line > best_match[:line].to_i
70:       end
parse_location(location) click to toggle source
    # File lib/spec/runner/line_number_query.rb, line 72
72:       def parse_location(location)
73:         location =~ /(.*)\:(\d*)(\:|$)/
74:         return $1, Integer($2)
75:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.