Created
December 1, 2015 00:17
-
-
Save tenderlove/43d47768cf44adf134cb 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 --disable-gems | |
# Tab completion for minitest tests. | |
# | |
# INSTALLATION: | |
# | |
# 1. Put this file in a directory in your $PATH. Make sure it's executable | |
# 2. Run this: | |
# | |
# $ complete -o bashdefault -f -C /path/to/this/file.rb ruby | |
# | |
# Running individual minitest tests will now have tab completion for the | |
# method names. | |
# | |
# USAGE: | |
# | |
# When running tests, just hit tab after -n. For example: | |
# | |
# $ ruby -I lib:test test/test_whatever.rb -n test_<TAB> | |
# | |
require 'optparse' | |
require 'shellwords' | |
argv = Shellwords.split(ENV['COMP_LINE']).drop 1 | |
options = {} | |
begin | |
OptionParser.new do |opts| | |
opts.on("-n", "--name [METHOD]", "Test method") do |m| | |
options[:method] = m | |
end | |
end.parse!(argv) | |
rescue | |
retry # ignore options passed to Ruby | |
end | |
file = argv.find { |f| File.file?(f) && !File.directory?(f) } | |
exit unless options.key?(:method) && file | |
require 'ripper' | |
methods = [] | |
K = Class.new(Ripper) { define_method(:on_def) { |n,_,_| methods << n } } | |
begin | |
K.parse File.read(file), file, 1 | |
methods = methods.grep(/^#{options[:method]}/) if options[:method] | |
puts methods.join("\n") | |
rescue # give up on parse errors | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment