Created
September 26, 2018 21:36
-
-
Save mlpinit/40f0eabc4a2b1a1e46a8df9cc0886dbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if ARGV[0].nil? | |
puts "You must provide a file name." | |
return | |
end | |
ENV['TEST'], line_number = ARGV[0].split(":") | |
line_number = line_number.to_i - 1 | |
if line_number.nil? | |
system("bin/rake test") | |
else | |
begin | |
file = File.read(ENV['TEST']) | |
line = file.lines[line_number] | |
while !line.match(/\A\s+test.*do\s*\z/) && line_number > 0 | |
line_number -= 1 | |
line = file.lines[line_number] | |
end | |
if line_number == 0 | |
puts "There is no test above this line" | |
return | |
end | |
start = file.lines[line_number].index(/("|')/) + 1 | |
finish = file.lines[line_number].size - | |
file.lines[line_number].reverse.index(/("|')/) - 2 | |
test_name = file.lines[line_number][start..finish].gsub(" ", "_") | |
ENV['TESTOPTS'] = "--name=test_#{test_name}" | |
rescue => e | |
puts e.message | |
end | |
end | |
system("bin/rake test") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment