Skip to content

Instantly share code, notes, and snippets.

@hawx
Created April 30, 2013 18:38
Show Gist options
  • Save hawx/5490898 to your computer and use it in GitHub Desktop.
Save hawx/5490898 to your computer and use it in GitHub Desktop.
Additions to minitest
module MiniTestWithHooks
class Unit < MiniTest::Unit
attr_reader :before_suites, :after_suites
def before_suites(&block)
(@before_suites ||= []) << block
end
def after_suites(&block)
(@after_suites ||= []) << block
end
def _run_suites(suites, type)
begin
before_suites.each(&:call)
super(suites, type)
ensure
after_suites.each(&:call)
end
end
def _run_suites(suite, type)
begin
suite.before_suite.each(&:call) if suite.respond_to?(:before_suite)
super(suite, type)
ensure
suite.after_suite.each(&:call) if suite.respond_to?(:after_suite)
end
end
end
end
class MiniTest::Unit
class << self
def before_each_test(&block)
TestCase.add_setup_hook(&block)
end
def after_each_test(&block)
TestCase.add_teardown_hook(&block)
end
end
end
MiniTest::Unit.runner = MiniTestWithHooks::Unit.new
module MiniTest
module Plus
class RedGreenIO
attr_reader :io
def initialize(io)
@io = io
end
def print(o)
case o
when '.' then io.print("\e[32m#{o}\e[0m")
when 'E', 'F' then io.print("\e[31m#{o}\e[0m")
else io.print(o)
end
end
def method_missing(msg, *args)
io.send(msg, *args)
end
end
end
end
MiniTest::Unit.output = MiniTest::Plus::RedGreenIO.new(MiniTest::Unit.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment