├── .gitignore ├── README.textile ├── bin └── testdrb ├── spork-testunit.gemspec └── lib └── spork └── test_framework └── test_unit.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | *.gem 3 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. Test::Unit support for Spork 2 | 3 | This includes a plugin for spork to enable Test::Unit support for spork. It also comes with a very bare-bones drb client to run tests. 4 | 5 | To use it, install the gem, then fire up spork in your project directory (the file test/test_helper.rb must exist to detect that Test::Unit is being used). 6 | 7 | Then, once spork is running, invoke @testdrb@ (e.g. @testdrb -Itest test/your_test.rb@) to run your tests under Spork. 8 | -------------------------------------------------------------------------------- /bin/testdrb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # These fix 1.8.7 test/unit results where a DRbUnknown is returned because the testdrb client doesn't have the classes 4 | # in its local namespace. (See issue #2) 5 | begin 6 | require 'minitest/unit' 7 | rescue LoadError 8 | # MiniTest is Ruby 1.9, and the classes below only exist in the pre 1.9 test/unit 9 | require 'test/unit/testresult' 10 | require 'test/unit/failure' 11 | end 12 | 13 | require 'drb' 14 | DRb.start_service("druby://127.0.0.1:0") # this allows Ruby to do some magical stuff so you can pass an output stream over DRb. 15 | test_server = DRbObject.new_with_uri("druby://127.0.0.1:8988") 16 | result = test_server.run(ARGV, $stderr, $stdout) 17 | 18 | -------------------------------------------------------------------------------- /spork-testunit.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | Gem::Specification.new do |s| 4 | s.name = %q{spork-testunit} 5 | s.version = "0.0.8" 6 | 7 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 8 | s.authors = ["Tim Harper"] 9 | s.date = %q{2012-02-13} 10 | s.default_executable = %q{testdrb} 11 | s.description = %q{Test Unit runner for spork} 12 | s.email = ["timcharper+spork@gmail.com"] 13 | s.executables = ["testdrb"] 14 | s.extra_rdoc_files = [ 15 | "README.textile" 16 | ] 17 | s.files = [ 18 | "bin/testdrb", 19 | "lib/spork/test_framework/test_unit.rb" 20 | ] 21 | s.homepage = %q{http://github.com/timcharper/spork-testunit} 22 | s.rdoc_options = ["--charset=UTF-8"] 23 | s.require_paths = ["lib"] 24 | s.rubyforge_project = %q{spork-testunit} 25 | s.rubygems_version = %q{1.3.4} 26 | s.summary = %q{spork-testunit} 27 | 28 | if s.respond_to? :specification_version then 29 | current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION 30 | s.specification_version = 3 31 | 32 | if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then 33 | s.add_runtime_dependency(%q, [">= 0.6.0"]) 34 | else 35 | s.add_dependency(%q, [">= 0.6.0"]) 36 | end 37 | else 38 | s.add_dependency(%q, [">= 0.6.0"]) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/spork/test_framework/test_unit.rb: -------------------------------------------------------------------------------- 1 | class Spork::TestFramework::TestUnit < Spork::TestFramework 2 | DEFAULT_PORT = 8988 3 | HELPER_FILE = File.join(Dir.pwd, "test/test_helper.rb") 4 | 5 | def run_tests(argv, stderr, stdout) 6 | if defined? MiniTest 7 | # Ruby 1.9 8 | stdout = Purdytest::IO.new(stdout) if defined? Purdytest # rewrap 9 | MiniTest::Unit.output = stdout 10 | old_load_path = $LOAD_PATH.dup 11 | # MiniTest's test/unit does not support -I, -r, or -e 12 | # Extract them and remove from arguments that are passed to testrb. 13 | argv.each_with_index do |arg, idx| 14 | if arg =~ /-I(.*)/ 15 | if $1 == '' 16 | # Path is next argument. 17 | include_path = argv[idx + 1] 18 | argv[idx + 1] = nil # Will be squashed when compact called. 19 | else 20 | include_path = $1 21 | end 22 | $LOAD_PATH << include_path 23 | argv[idx] = nil 24 | elsif arg =~ /-r(.*)/ 25 | if $1 == '' 26 | # File is next argument. 27 | require_file = argv[idx + 1] 28 | argv[idx + 1] = nil # Will be squashed when compact called. 29 | else 30 | require_file = $1 31 | end 32 | require require_file 33 | argv[idx] = nil 34 | elsif arg =~ /^-e$/ 35 | eval argv[idx + 1] 36 | argv[idx] = argv[idx + 1] = nil 37 | end 38 | end 39 | argv.compact! 40 | 41 | require 'test/unit' 42 | if defined? Turn 43 | # Use turn's wrapper around minitest 44 | if argv.empty? 45 | puts "Usage: testrb [options] tests..." 46 | exit 1 47 | end 48 | runner = Turn::MiniRunner.new 49 | config = Turn.config do |c| 50 | c.tests = argv 51 | c.framework = :minitest 52 | c.loadpath = (c.loadpath + $LOAD_PATH - old_load_path).uniq 53 | end 54 | controller = Turn::Controller.new(config) 55 | controller.start 56 | elsif Test::Unit.respond_to?(:setup_argv) 57 | # copied from ruby-1.9.2-p136/bin/testrb: 58 | Test::Unit.setup_argv(argv) {|files| 59 | if files.empty? 60 | puts "Usage: testrb [options] tests..." 61 | exit 1 62 | end 63 | if files.size == 1 64 | $0 = File.basename(files[0]) 65 | else 66 | $0 = files.to_s 67 | end 68 | files 69 | } 70 | 71 | MiniTest::Unit.new.run(argv) 72 | else 73 | # copied from ruby-head/bin/testrb: 74 | tests = Test::Unit::AutoRunner.new(true) 75 | tests.options.banner.sub!(/\[options\]/, '\& tests...') 76 | unless tests.process_args(argv) 77 | abort tests.options.banner 78 | end 79 | files = tests.to_run 80 | $0 = files.size == 1 ? File.basename(files[0]) : files.to_s 81 | tests.run 82 | end 83 | else 84 | # Ruby 1.8 85 | Object.send(:remove_const, :STDOUT); Object.send(:const_set, :STDOUT, stdout) 86 | require 'test/unit/autorunner' 87 | r = Test::Unit::AutoRunner.new(true) 88 | exit(false) unless r.process_args(argv) 89 | r.run 90 | end 91 | rescue => e 92 | puts "-"*30 93 | puts "Error executing #{argv.join(' ')}" 94 | puts e.message 95 | puts e.backtrace 96 | puts "-"*30 97 | end 98 | end 99 | --------------------------------------------------------------------------------