Permalink
Browse files

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.
  • Loading branch information...
1 parent 1949d1f commit c0a24555f9e2749fb94efe1967cb9943db0b6a7e @blowmage blowmage committed Sep 24, 2012
@@ -61,10 +61,9 @@ def tests(helper_class)
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|
@alindeman

alindeman Sep 25, 2012

Contributor

Where does this method come from?

@alindeman

alindeman Sep 25, 2012

Contributor

Ah, it's an implicit dependency. I've fixed with rails/rails#7760

@blowmage

blowmage Sep 25, 2012

Contributor

It is defined in active_support/testing/constant_lookup.rb

+ Module === constant && !(Class === constant)
+ end
end
def helper_method(*methods)
@@ -64,7 +64,7 @@ class GeneralViewTest < ActionView::TestCase
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
@@ -78,3 +78,59 @@ def test_set_helper_class_using_string
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

0 comments on commit c0a2455

Please sign in to comment.