lib/testrbl.rb in testrbl-0.1.4 vs lib/testrbl.rb in testrbl-0.1.5

- old
+ new

@@ -1,11 +1,12 @@ require 'testrbl/version' module Testrbl PATTERNS = [ - /^(\s+)(?:should|context|test)\s+['"](.*)['"]\s+do\s*$/, - /^(\s+)def\s+test_([a-z_\d]+)\s*$/ + /^(\s+)(should|test)\s+['"](.*)['"]\s+do\s*$/, + /^(\s+)(context)\s+['"]?(.*?)['"]?\s+do\s*$/, + /^(\s+)def\s+(test_)([a-z_\d]+)\s*$/ ] def self.run_from_cli(argv) # we only work with 1 file with line-number, everything else gets passed thourgh if argv.join(" ") !~ /^\S+:\d+$/ @@ -30,22 +31,35 @@ content = File.readlines(file) search = content[0..(line.to_i-1)].reverse last_spaces = " " * 100 found = search.map{|line| pattern_from_line(line) }.compact - - found.select! do |spaces, name| + found = found.select do |spaces, name| last_spaces = spaces if spaces.size < last_spaces.size end return found.reverse.map(&:last).join(".*") if found.size > 0 raise "no test found before line #{line}" end def self.pattern_from_line(line) PATTERNS.each do |r| - return [$1, Regexp.escape($2).gsub("'",".").gsub("\\ "," ")] if line =~ r + if line =~ r + whitespace, method, test_name = $1, $2, $3 + regex = Regexp.escape(test_name).gsub("'",".").gsub("\\ "," ") + + if method == "should" + regex = "#{method} #{regex}\. $" + elsif method == "test" + regex = "^#{method}: #{regex}$" + end + + return [ + whitespace, + regex + ] + end end nil end end