lib/testrbl.rb in testrbl-0.4.1 vs lib/testrbl.rb in testrbl-0.5.0

- old
+ new

@@ -17,11 +17,11 @@ load_options, options = partition_options(options) if files.size == 1 and files.first =~ /^(\S+):(\d+)$/ file = $1 line = $2 - run(ruby + load_options + [file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"] + options) + run(ruby + load_options + line_pattern_option(file, line) + options) else if files.size == 1 and File.file?(files.first) run(ruby + load_options + files + options) elsif options.none? { |arg| arg =~ /^-n/ } files = files.map { |f| File.directory?(f) ? all_test_files_in(f) : f }.flatten @@ -31,10 +31,15 @@ run ["testrb"] + argv end end end + # overwritten by maxitest to just return line + def self.line_pattern_option(file, line) + [file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"] + end + # usable via external tools like zeus def self.pattern_from_file(lines, line) possible_lines = lines[0..(line.to_i-1)].reverse found = possible_lines.map { |line| test_pattern_from_line(line) || block_start_from_line(line) }.compact @@ -138,25 +143,29 @@ end def self.test_pattern_from_match(method, test_name) regex = Regexp.escape(test_name).gsub("\\ "," ").gsub(INTERPOLATION, ".*") - regex = case method - when "should" - optional_test_name = "(?:\(.*\))?" - "#{method} #{regex}\. #{optional_test_name}$" - when "describe" - "#{test_name}(::)?" - when "test" + regex = if method == "test" # test "xxx -_ yyy" # test-unit: "test: xxx -_ yyy" # activesupport: "test_xxx_-__yyy" "^test(: |_)#{regex.gsub(" ", ".")}$" - when "it" + elsif method == "describe" || (method == "context" && !via_shoulda?) + "#{test_name}(::)?" + elsif method == "should" && via_shoulda? + optional_test_name = "(?:\(.*\))?" + "#{method} #{regex}\. #{optional_test_name}$" + elsif ["it", "should"].include?(method) # minitest aliases for shoulda "#test_\\d+_#{test_name}$" else regex end regex.gsub("'", ".") + end + + def self.via_shoulda? + return @via_shoulda if defined?(@via_shoulda) + @via_shoulda = !File.exist?("Gemfile.lock") || File.read("Gemfile.lock").include?(" shoulda-context ") end end