diff options
author | Mike Moore <mike@blowmage.com> | 2012-09-24 13:44:49 -0600 |
---|---|---|
committer | Mike Moore <mike@blowmage.com> | 2012-09-24 13:44:49 -0600 |
commit | 4894eef448b19b326946096d0ec08700f67cd649 (patch) | |
tree | 81f1c401e873ad20a130694e1b1eaa5a12802970 /activesupport/test/testing | |
parent | 1dbe4baef5120dce845c46abe0014abf64e4b0ca (diff) | |
download | rails-4894eef448b19b326946096d0ec08700f67cd649.tar.gz rails-4894eef448b19b326946096d0ec08700f67cd649.tar.bz2 rails-4894eef448b19b326946096d0ec08700f67cd649.zip |
Create ActiveSupport::Testing::ConstantLookup
AS::TC::ConstantLookup walks the test's name to find the constant it is describing.
This additional lookup logic is needed to better support minitest's spec DSL.
Diffstat (limited to 'activesupport/test/testing')
-rw-r--r-- | activesupport/test/testing/constant_lookup_test.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/activesupport/test/testing/constant_lookup_test.rb b/activesupport/test/testing/constant_lookup_test.rb new file mode 100644 index 0000000000..f39d38e5cd --- /dev/null +++ b/activesupport/test/testing/constant_lookup_test.rb @@ -0,0 +1,58 @@ +require 'abstract_unit' + +class Foo; end +class Bar < Foo; + def index; end + def self.index; end +end +class Baz < Bar; end +module FooBar; end + +class TestLookup < ActiveSupport::TestCase + + def find_foo(name) + self.class.determine_constant_from_test_name(name) do |constant| + Class === constant && constant < Foo + end + end + + def find_module(name) + self.class.determine_constant_from_test_name(name) do |constant| + Module === constant + end + end + + def test_find_bar_from_foo + assert_equal Bar, find_foo("Bar") + assert_equal Bar, find_foo("Bar::index") + assert_equal Bar, find_foo("Bar::index::authenticated") + assert_equal Bar, find_foo("BarTest") + assert_equal Bar, find_foo("BarTest::index") + assert_equal Bar, find_foo("BarTest::index::authenticated") + end + + def test_find_module + assert_equal FooBar, find_module("FooBar") + assert_equal FooBar, find_module("FooBar::index") + assert_equal FooBar, find_module("FooBar::index::authenticated") + assert_equal FooBar, find_module("FooBarTest") + assert_equal FooBar, find_module("FooBarTest::index") + assert_equal FooBar, find_module("FooBarTest::index::authenticated") + end + + def test_returns_nil_when_cant_find_foo + assert_nil find_foo("DoesntExist") + assert_nil find_foo("DoesntExistTest") + assert_nil find_foo("DoesntExist::Nadda") + assert_nil find_foo("DoesntExist::Nadda::Nope") + assert_nil find_foo("DoesntExist::Nadda::Nope::NotHere") + end + + def test_returns_nil_when_cant_find_module + assert_nil find_module("DoesntExist") + assert_nil find_module("DoesntExistTest") + assert_nil find_module("DoesntExist::Nadda") + assert_nil find_module("DoesntExist::Nadda::Nope") + assert_nil find_module("DoesntExist::Nadda::Nope::NotHere") + end +end |