Module: Testrbl
- Defined in:
- lib/testrbl.rb,
lib/testrbl/version.rb
Constant Summary collapse
- PATTERNS =
[ /^(\s+)(should|test|it)\s+['"](.*)['"]\s+do\s*(?:#.*)?$/, /^(\s+)(context|describe)\s+['"]?(.*?)['"]?\s+do\s*(?:#.*)?$/, /^(\s+)def\s+(test_)([a-z_\d]+)\s*(?:#.*)?$/ ]
- OPTION_WITH_ARGUMENT =
["-I", "-r", "-n", "-e"]
- INTERPOLATION =
/\\\#\\\{.*?\\\}/
- VERSION =
'0.3.0'
Class Method Summary collapse
-
.filter_duplicate_final(patterns) ⇒ Object
only keep 1 pattern that stops matching via $.
-
.pattern_from_file(lines, line) ⇒ Object
usable via external tools like zeus.
- .run_from_cli(argv) ⇒ Object
Class Method Details
.filter_duplicate_final(patterns) ⇒ Object
only keep 1 pattern that stops matching via $
50 51 52 53 |
# File 'lib/testrbl.rb', line 50 def self.filter_duplicate_final(patterns) found_final = 0 patterns.reject { |p| p.end_with?("$") and (found_final += 1) > 1 } end |
.pattern_from_file(lines, line) ⇒ Object
usable via external tools like zeus
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/testrbl.rb', line 33 def self.pattern_from_file(lines, line) possible_lines = lines[0..(line.to_i-1)].reverse last_spaces = " " * 100 found = possible_lines.map { |line| test_pattern_from_line(line) }.compact # pattern and the groups it is nested under (like describe - describe - it) patterns = found.select do |spaces, name| last_spaces = spaces if spaces.size < last_spaces.size end.map(&:last) return filter_duplicate_final(patterns).reverse.join(".*") if found.size > 0 raise "no test found before line #{line}" end |
.run_from_cli(argv) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/testrbl.rb', line 13 def self.run_from_cli(argv) files, = partition_argv(argv) files = files.map { |f| localize(f) } , = () if files.size == 1 and files.first =~ /^(\S+):(\d+)$/ file = $1 line = $2 run(ruby + + [file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"] + ) else if files.all? { |f| File.file?(f) } and .none? { |arg| arg =~ /^-n/ } run(ruby + + files.map { |f| "-r#{f}" } + + ["-e", ""]) else # pass though # no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb run ["testrb"] + argv end end end |