Skip to content

Instantly share code, notes, and snippets.

@mlpinit
Created September 26, 2018 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlpinit/40f0eabc4a2b1a1e46a8df9cc0886dbb to your computer and use it in GitHub Desktop.
Save mlpinit/40f0eabc4a2b1a1e46a8df9cc0886dbb to your computer and use it in GitHub Desktop.
#!/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