Class: Spec::Runner::LineNumberQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(run_options) ⇒ LineNumberQuery

Returns a new instance of LineNumberQuery.



7
8
9
10
# File 'lib/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb', line 7

def initialize(run_options)
  @best_match = {}
  @run_options = run_options
end

Instance Attribute Details

#best_matchObject (readonly)

Returns the value of attribute best_match.



5
6
7
# File 'lib/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb', line 5

def best_match
  @best_match
end

Instance Method Details

#example_line_for(file, line_number) ⇒ Object



27
28
29
30
# File 'lib/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb', line 27

def example_line_for(file, line_number)
  determine_best_match(file, line_number)
  best_match[:line]
end

#spec_name_for(file, line_number) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vendor/plugins/rspec/lib/spec/runner/line_number_query.rb', line 12

def spec_name_for(file, line_number)
  best_match.clear
  file = File.expand_path(file)
  determine_best_match(file, line_number)
  if best_match[:example_group]
    if best_match[:example]
      "#{best_match[:example_group].description} #{best_match[:example].description}"
    else
      best_match[:example_group].description
    end
  else
    nil
  end
end