Class: Spec::Runner::SpecParser

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/runner/spec_parser.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#spec_name_for(io, line_number) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/spec/runner/spec_parser.rb', line 5

def spec_name_for(io, line_number)
  source  = io.read
  behaviour, behaviour_line = behaviour_at_line(source, line_number)
  example, example_line = example_at_line(source, line_number)
  if behaviour && example && (behaviour_line < example_line)
    "#{behaviour} #{example}"
  elsif behaviour
    behaviour
  else
    nil
  end
end