Skip to content

Instantly share code, notes, and snippets.

@lifo
Created September 30, 2008 18:15
Show Gist options
  • Save lifo/13901 to your computer and use it in GitHub Desktop.
Save lifo/13901 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
require 'test/unit'
class Test::Unit::TestCase
# Monkey it. T::U calls public_instance_methods(true)
def self.suite
method_names = public_instance_methods(false)
tests = method_names.delete_if {|method_name| method_name !~ /^test./}
suite = Test::Unit::TestSuite.new(name)
tests.sort.each do
|test|
catch(:invalid_test) do
suite << new(test)
end
end
if (suite.empty?)
catch(:invalid_test) do
suite << new("default_test")
end
end
suite
end
end
class ExampleTest < Test::Unit::TestCase
class Hello < ExampleTest
setup :hello
def test_hello
assert_equal 1, @hello
assert_nil @world # FAILS
end
private
def hello
@hello = 1
end
class World < Hello
setup :world
def test_world
assert_equal 1, @world
assert_equal 1, @hello
end
private
def world
@world = 1
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment