Skip to content

Instantly share code, notes, and snippets.

@dylanahsmith
Last active October 3, 2015 16:58
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 dylanahsmith/2490403 to your computer and use it in GitHub Desktop.
Save dylanahsmith/2490403 to your computer and use it in GitHub Desktop.
Wrapper script for running ruby tests
#!/usr/bin/env ruby
require 'pathname'
require 'optparse'
USAGE = "Usage: rubytest [OPTIONS] FILE..."
debug = true
args = []
OptionParser.new do |opts|
opts.banner = USAGE
opts.on('-n', '--name TEST_NAME') { |name| args << "-n#{name}" }
opts.on('-u', '--test-string TEST_STRING') { |name| args << ['-n', "test_#{name.tr(' ', '_')}"] }
opts.on('-rLIBRARY') { |name| args << ["-r", name].join }
opts.on('--seed SEED') { |seed| args << "--seed=#{seed}" }
end.parse!
tests = ARGV
tests.empty? and abort USAGE
def find_project_root
path = Pathname.pwd
until path.join('test').directory?
return if path.root?
path = path.parent
end
path
end
def which(program)
paths = ENV['PATH'].split(':').map{ |d| Pathname.new(d).join(program) }
paths.detect(&:executable?)
end
def homedir
Dir.respond_to?(:home) ? Dir.home : ENV['HOME']
end
LOADER_RUBY_PATH = "/rake/rake_test_loader.rb"
RAKE_TEST_LOADER_DIR = $:.detect{ |d| File.exists?(d + LOADER_RUBY_PATH) }
RAKE_TEST_LOADER_PATH = RAKE_TEST_LOADER_DIR + LOADER_RUBY_PATH
ENV['BACKTRACE'] = '1' # show full trace in tests
project_root = find_project_root or abort "Could not find the project's top level directory"
tests.map! do |test|
Pathname.new(test).expand_path.relative_path_from(project_root).to_s
end
Dir.chdir project_root
cmd = ["bundle", "exec", "ruby", "-Ilib:test", "-I#{RAKE_TEST_LOADER_DIR}", RAKE_TEST_LOADER_PATH, *args, *tests]
exec *cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment