lib/testrbl.rb in testrbl-0.1.12 vs lib/testrbl.rb in testrbl-0.1.13
- old
+ new
@@ -15,17 +15,16 @@
end
INTERPOLATION = /\\\#\\\{.*?\\\}/
def self.run_from_cli(argv)
- command = argv.join(" ")
- if command =~ /^\S+:\d+$/
- file, line = argv.first.split(':')
+ i_test, file, line = detect_usable(argv)
+ if file and line
file = "./#{file}" if file =~ /^[a-z]/ # fix 1.9 not being able to load local files
- run "#{bundle_exec}ruby #{file} -n '/#{pattern_from_file(File.readlines(file), line)}/'"
- elsif File.file?(command)
- run "#{bundle_exec}ruby #{command}"
+ run "#{bundle_exec}ruby #{i_test}#{file} -n '/#{pattern_from_file(File.readlines(file), line)}/'"
+ elsif file
+ run "#{bundle_exec}ruby #{i_test}#{file}"
else # pass though
# no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb
run "testrb #{argv.map{|a| a.include?(' ') ? "'#{a}'" : a }.join(' ')}"
end
end
@@ -54,16 +53,30 @@
raise "no test found before line #{line}"
end
private
+ def self.detect_usable(argv)
+ argv = argv.dup # do not mess up args
+ i_test = "-Itest " if ((argv.delete("-I") and argv.delete("test")) or argv.delete("-Itest"))
+
+ return unless argv.size == 1
+
+ if argv.first =~ /^(\S+):(\d+)$/
+ [i_test, $1, $2]
+ elsif File.file?(argv.first)
+ [i_test, argv.first, false]
+ end
+ end
+
def self.bundle_exec
"bundle exec " if File.file?("Gemfile")
end
def self.run(command)
puts command
+ STDOUT.flush # if exec fails horribly we at least see some output
exec command
end
def self.pattern_from_line(line)
PATTERNS.each do |r|
@@ -78,10 +91,10 @@
# test "xxx -_ yyy"
# test-unit: "test: xxx -_ yyy"
# activesupport: "test_xxx_-__yyy"
regex = "^test(: |_)#{regex.gsub(" ", ".")}$"
elsif method == "it"
- regex = "\\d+_#{test_name.gsub(MINITEST_NAME_RE, '_').downcase}$"
+ regex = "^test_\\d+_#{test_name}$"
end
return [
whitespace,
regex