Created — forked from jferris/gist:73948

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

tu/tf autocompletion for zsh

View .zshrc
1 2 3 4 5 6 7 8 9 10 11 12
# autocompletion for ruby_test
# # works with tu/tf aliases
# # see also ~/bin/ruby_test.rb
_ruby_tests() {
if [[ -n $words[2] ]]; then
compadd `ruby_test -l ${words[2]}`
fi
}
compdef _ruby_tests ruby_test
alias tu="ruby_test unit"
alias tf="ruby_test functional"
alias ti="ruby_test integration"
View .zshrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#!/usr/bin/env ruby
 
require 'fileutils'
 
class TestFinder
attr_reader :prefix
def initialize(prefix)
@prefix = prefix
end
 
 
def name_to_file(name)
"#{prefix}/#{name}_test.rb"
end
 
def file_to_name(file)
file.sub(%r{^#{Regexp.escape(prefix)}/}, '').sub(%r{_test\.rb$}, '')
end
 
def test_files
@test_files ||= Dir["#{prefix}/**/*_test.rb"]
end
 
def test_names
@test_names ||= test_files.collect {|file| file_to_name(file) }
end
 
def run(tests)
if tests.empty?
if test_files.empty?
puts "Nothing to do."
else
run(test_files)
end
else
tests = tests.collect {|test| force_test_file(test) }
command = command_to_run(tests)
puts command
exec command
end
end
 
def list
puts test_names.sort.join("\n")
end
 
private
 
def force_test_file(test)
if test_files.include?(test)
test
elsif test_names.include?(test)
name_to_file(test)
else
raise "No such test: #{test.inspect}"
end
end
 
def command_to_run(files)
files_string = files.inspect
require_string = 'require "#{f}"'
%{ruby -Itest -e '#{files_string}.each {|f| #{require_string} }'}
end
end
 
list = ARGV.delete('-l') || ARGV.delete('--list')
prefix = ARGV.shift
prefix = prefix ? "test/#{prefix}" : 'test'
finder = TestFinder.new(prefix)
tests = ARGV.dup
 
if list
finder.list
else
finder.run(tests)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.