lib/testrbl.rb in testrbl-0.1.6 vs lib/testrbl.rb in testrbl-0.1.7

- old
+ new

@@ -1,34 +1,46 @@ require 'testrbl/version' module Testrbl PATTERNS = [ - /^(\s+)(should|test)\s+['"](.*)['"]\s+do\s*$/, + /^(\s+)(should|test|it)\s+['"](.*)['"]\s+do\s*$/, /^(\s+)(context)\s+['"]?(.*?)['"]?\s+do\s*$/, /^(\s+)def\s+(test_)([a-z_\d]+)\s*$/ ] + # copied from minitest + MINITEST_NAME_RE = if RUBY_VERSION >= "1.9" + Regexp.new("[^[[:word:]]]+") + else + /\W+/u + end + 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+$/ + command = argv.join(" ") + if command =~ /^\S+:\d+$/ + file, line = argv.first.split(':') + 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, line)}/'" + elsif File.file?(command) + run "#{bundle_exec}ruby #{command}" + 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 - file, line = argv.first.split(':') - file = "./#{file}" if file =~ /^[a-z]/ # fix 1.9 not being able to load local files - run "testrb #{file} -n '/#{pattern_from_file(file, line)}/'" + private + + def self.bundle_exec + "bundle exec " if File.file?("Gemfile") end def self.run(command) - safe_to_bundle_exec = (File.exist?('Gemfile.lock') and File.read('Gemfile.lock').include?(" test-unit ")) - command = "#{"bundle exec " if safe_to_bundle_exec}#{command}" puts command exec command end - private - def self.pattern_from_file(file, line) content = File.readlines(file) search = content[0..(line.to_i-1)].reverse last_spaces = " " * 100 @@ -50,9 +62,11 @@ if method == "should" regex = "#{method} #{regex}\. $" elsif method == "test" regex = "^#{method}: #{regex}$" + elsif method == "it" + regex = "\\d+_#{test_name.gsub(MINITEST_NAME_RE, '_').downcase}$" end return [ whitespace, regex