Created
September 28, 2015 19:44
-
-
Save jtrim/2f52be6b8b7bb1304e93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
def print_usage | |
puts "USAGE: test-unit-runner path/to/spec.rb[:<line-number>]" | |
end | |
unless ARGV.first | |
print_usage | |
exit 1 | |
end | |
filename = ARGV.first.split(":").first | |
line_number = ARGV.first.split(":").last.to_i | |
file_contents = File.read Pathname.new(".").join(filename).to_s | |
if line_number | |
nearest_test_definition = file_contents.lines[0...line_number].reverse.find do |line| | |
line.strip =~ /(?:test|should|context|describe)\s+(?:['"]|%[qQ][\[{|\(])(.*)[|\]}'"]/ | |
end | |
if nearest_test_definition | |
ARGV << "--name" | |
ARGV << "\"/#{$1.gsub(/"/, %q|"'"'"|)}/\"" | |
end | |
end | |
puts "NO_COVERAGE_REPORT=true ruby -Ilib:test #{filename} #{ARGV[1..-1].join(" ")}" | |
exec "NO_COVERAGE_REPORT=true ruby -Ilib:test #{filename} #{ARGV[1..-1].join(" ")}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment