diff options
author | Mike Moore <mike@blowmage.com> | 2012-09-24 15:37:45 -0600 |
---|---|---|
committer | Mike Moore <mike@blowmage.com> | 2012-09-24 15:37:45 -0600 |
commit | c0a24555f9e2749fb94efe1967cb9943db0b6a7e (patch) | |
tree | c3b61be191c7519b8725340f4fac51c93578348a /actionpack | |
parent | 1949d1f6b29bd374e7e1cb015ec85ee78e52361a (diff) | |
download | rails-c0a24555f9e2749fb94efe1967cb9943db0b6a7e.tar.gz rails-c0a24555f9e2749fb94efe1967cb9943db0b6a7e.tar.bz2 rails-c0a24555f9e2749fb94efe1967cb9943db0b6a7e.zip |
Support helper tests using spec DSL
Improve how helper tests to resolve the helper class from the test name.
Add tests for helper tests using the minitest spec DSL.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 7 | ||||
-rw-r--r-- | actionpack/test/template/test_case_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/test_test.rb | 56 |
3 files changed, 60 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 266cb14cde..a4e8068026 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -61,10 +61,9 @@ module ActionView end def determine_default_helper_class(name) - mod = name.sub(/Test$/, '').constantize - mod.is_a?(Class) ? nil : mod - rescue NameError - nil + determine_constant_from_test_name(name) do |constant| + Module === constant && !(Class === constant) + end end def helper_method(*methods) diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 387aafebd4..5265ae6b3a 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -64,7 +64,7 @@ module ActionView assert_equal 'Howdy!', from_another_helper end - test "determine_default_helper_class returns nil if name.sub(/Test$/, '').constantize resolves to a class" do + test "determine_default_helper_class returns nil if the test name constant resolves to a class" do assert_nil self.class.determine_default_helper_class("String") end diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb index 108a674d95..e843a1deb4 100644 --- a/actionpack/test/template/test_test.rb +++ b/actionpack/test/template/test_test.rb @@ -78,3 +78,59 @@ class CrazyStringHelperTest < ActionView::TestCase assert_equal PeopleHelper, self.class.helper_class end end + +describe PeopleHelper do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe PeopleHelper, :helper_class do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe PeopleHelper do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end + +describe PeopleHelper, :helper_class do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end + +describe "PeopleHelper" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe "PeopleHelperTest" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end +end + +describe "PeopleHelper" do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end + +describe "PeopleHelperTest" do + describe "even while nested" do + it "resolves the right helper_class" do + assert_equal PeopleHelper, self.class.helper_class + end + end +end |