Permalink
Browse files

Add helper lookup similar to controller and mailer lookup

Allow helper spec tests to be nested just like controller spec tests.
Add test coverage for helper spec tests and helper_class lookup.
  • Loading branch information...
blowmage committed Sep 22, 2012
1 parent 701800c commit 0d6aead20fda256e0f03a2bd300bff0b69dd9c07
@@ -7,13 +7,16 @@ module ActionView
class TestCase < MiniTest::Rails::ActiveSupport::TestCase
TestController = ::ActionView::TestCase::TestController
- # Register by name, because Helpers are just modules
- register_spec_type(/Helper( ?Test)?\z/i, self)
-
- # View specs
- register_spec_type(/View( ?Test)?\z/i, self)
+ # Use AV::TestCase for the base class for helpers and views
+ register_spec_type(/(Helper|View)( ?Test)?\z/i, self)
include ::ActionView::TestCase::Behavior
+
+ def self.determine_default_helper_class(name)
+ determine_constant_from_test_name(name) do |constant|
+ Module === constant
+ end
+ end
end
end
end
@@ -0,0 +1,76 @@
+require "minitest/autorun"
+require "rails"
+
+require "minitest/rails/action_view"
+
+module PeopleHelper
+ def title(text)
+ content_tag(:h1, text)
+ end
+
+ def homepage_path
+ people_path
+ end
+
+ def homepage_url
+ people_url
+ end
+
+ def link_to_person(person)
+ link_to person.name, person
+ end
+end
+
+# From Rails...
+class CrazyHelperTest < MiniTest::Rails::ActionView::TestCase
+ tests PeopleHelper
+
+ def test_helper_class_can_be_set_manually_not_just_inferred
+ assert_equal PeopleHelper, self.class.helper_class
+ end
+end
+
+class CrazySymbolHelperTest < MiniTest::Rails::ActionView::TestCase
+ tests :people
+
+ def test_set_helper_class_using_symbol
+ assert_equal PeopleHelper, self.class.helper_class
+ end
+end
+
+class CrazyStringHelperTest < MiniTest::Rails::ActionView::TestCase
+ tests 'people'
+
+ def test_set_helper_class_using_string
+ assert_equal PeopleHelper, self.class.helper_class
+ end
+end
+
+# New tests...
+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

0 comments on commit 0d6aead

Please sign in to comment.