Last active
October 3, 2015 16:58
-
-
Save dylanahsmith/2490403 to your computer and use it in GitHub Desktop.
Wrapper script for running ruby tests
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 | |
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