Skip to content
This repository has been archived by the owner on May 31, 2018. It is now read-only.

Respect minitest/pride if it was loaded. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 44 additions & 15 deletions lib/spork/test_framework/minitest.rb
Expand Up @@ -5,22 +5,51 @@ class Spork::TestFramework::MiniTest < Spork::TestFramework
def run_tests(argv, stderr, stdout)
require "minitest/unit"
$LOAD_PATH << "test" << "."
::MiniTest::Unit.output = stdout

paths, opts = parse_options(argv)

paths.each do |path|
require path

io_class = ::MiniTest::Unit.output.class
if defined?(PrideIO) and io_class == PrideIO or defined?(PrideLOL) and io_class == PrideLOL
# Respect minitest/pride
::MiniTest::Unit.output = io_class.new(stdout)
else
::MiniTest::Unit.output = stdout
end

# MiniTest's test/unit does not support -I, -r, or -e
# Extract them and remove from arguments that are passed to testrb.
argv.each_with_index do |arg, idx|
if arg =~ /-I(.*)/
if $1 == ''
# Path is next argument.
include_path = argv[idx + 1]
argv[idx + 1] = nil # Will be squashed when compact called.
else
include_path = $1
end
$LOAD_PATH << include_path
argv[idx] = nil
elsif arg =~ /-r(.*)/
if $1 == ''
# File is next argument.
require_file = argv[idx + 1]
argv[idx + 1] = nil # Will be squashed when compact called.
else
require_file = $1
end
require require_file
argv[idx] = nil
elsif arg =~ /^-e$/
eval argv[idx + 1]
argv[idx] = argv[idx + 1] = nil
elsif arg == '--'
argv[idx] = nil
break
elsif !arg.nil?
require arg
argv[idx] = nil
end
end
argv.compact!

::MiniTest::Unit.new.run(opts)
end

def parse_options(argv)
paths, opts = argv.slice_before("--").to_a
paths ||= []
opts ||= []
opts.shift
[paths, opts]
::MiniTest::Unit.new.run(argv)
end
end