Created
September 30, 2008 18:15
-
-
Save lifo/13901 to your computer and use it in GitHub Desktop.
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
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