summaryrefslogtreecommitdiffstats
path: root/test/lib/spec/runner/spec_parser.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-23 11:52:31 -0500
committerLuke Kanies <luke@madstop.com>2007-08-23 11:52:31 -0500
commit58494cc8566da04711715e54274f472377b1aba0 (patch)
tree66bd610d359f549fc68e9985accf7b4141b7982e /test/lib/spec/runner/spec_parser.rb
parentd59315a07a8a01ca65952d8e8fe9d2f1bb84d30e (diff)
downloadpuppet-58494cc8566da04711715e54274f472377b1aba0.tar.gz
puppet-58494cc8566da04711715e54274f472377b1aba0.tar.xz
puppet-58494cc8566da04711715e54274f472377b1aba0.zip
Building a stand-alone spec directory for creating the new spec-based tests.
Diffstat (limited to 'test/lib/spec/runner/spec_parser.rb')
-rw-r--r--test/lib/spec/runner/spec_parser.rb50
1 files changed, 0 insertions, 50 deletions
diff --git a/test/lib/spec/runner/spec_parser.rb b/test/lib/spec/runner/spec_parser.rb
deleted file mode 100644
index bc9170065..000000000
--- a/test/lib/spec/runner/spec_parser.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-module Spec
- module Runner
- # Parses a spec file and finds the nearest example for a given line number.
- class SpecParser
- 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
-
- protected
-
- def behaviour_at_line(source, line_number)
- find_above(source, line_number, /^\s*(context|describe)\s+(.*)\s+do/)
- end
-
- def example_at_line(source, line_number)
- find_above(source, line_number, /^\s*(specify|it)\s+(.*)\s+do/)
- end
-
- # Returns the context/describe or specify/it name and the line number
- def find_above(source, line_number, pattern)
- lines_above_reversed(source, line_number).each_with_index do |line, n|
- return [parse_description($2), line_number-n] if line =~ pattern
- end
- nil
- end
-
- def lines_above_reversed(source, line_number)
- lines = source.split("\n")
- lines[0...line_number].reverse
- end
-
- def parse_description(str)
- return str[1..-2] if str =~ /^['"].*['"]$/
- if matches = /^(.*)\s*,\s*['"](.*)['"]$/.match(str)
- return ::Spec::DSL::Description.generate_description(matches[1], matches[2])
- end
- return str
- end
- end
- end
-end