require File.join(File.dirname(__FILE__), 'ptk_helper') class ActiveTest::Untouched < ActiveTest::Base def setup @untouched = true end def teardown @untouched_teardown = true end end class ExposedTest < ActiveTest::Untouched def setup @stack = [] end def teardown assert @untouched_teardown, "No inherited teardown" end def test_should_have_untouched assert @untouched, "Not inheriting from parent" end def test_should_have_stack assert @stack.empty?, "Not executing its own setup" end def test_should_not_have_second_stack assert @second_stack.nil?, "Leaking from child" end def test_should_not_have_third_stack assert @third_stack.nil?, "Leaking from child" end end class ChildExposedTest < ExposedTest def setup @second_stack = [] end def teardown assert @untouched_teardown, "No inherited teardown" end def test_should_have_untouched assert @untouched, "Not inheriting from grandparent" end def test_should_have_stack assert !@stack.nil?, "Not inheriting from parent" end undef_method(:test_should_not_have_second_stack) def test_should_have_second_stack assert !@second_stack.nil?, "Not executing its own setup" end end class SiblingExposed < ExposedTest def setup @fourth_stack = [] end def test_should_not_have_second_stack assert @second_stack.nil?, "Leaking from sibling" end def test_should_have_fourth_stack assert @fourth_stack, "Not executing its own setup" end end class ChildOverwriterTest < ExposedTest standalone_setup do @third_stack = [] end standalone_teardown do assert @untouched_teardown.nil?, "Inherited teardown" end undef_method(:test_should_have_untouched) def test_should_not_have_untouched assert @untouched.nil?, "Inheriting setup from grandparent" end undef_method(:test_should_have_stack) def test_should_not_have_stack assert @stack.nil?, "Inheriting setup from parent" end def test_should_not_have_second_stack assert @second_stack.nil?, "Leaking from sibling... ?!" end undef_method(:test_should_not_have_third_stack) def test_should_have_third_stack assert !@third_stack.nil?, "Not executing its own setup" end end