diff options
author | Mike Moore <mike@blowmage.com> | 2012-09-24 14:31:05 -0600 |
---|---|---|
committer | Mike Moore <mike@blowmage.com> | 2012-09-24 14:31:05 -0600 |
commit | 0ce383db58b4718147433ca0e06d7e88efd6c184 (patch) | |
tree | 3a353bed6a4ed139a1c42ad8631505b8d0ac254c | |
parent | 52db1f914843049dc4c49730c7030b94e8f1d881 (diff) | |
download | rails-0ce383db58b4718147433ca0e06d7e88efd6c184.tar.gz rails-0ce383db58b4718147433ca0e06d7e88efd6c184.tar.bz2 rails-0ce383db58b4718147433ca0e06d7e88efd6c184.zip |
Register mailer tests for minitest's spec DSL
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 7 | ||||
-rw-r--r-- | actionmailer/test/spec_type_test.rb | 37 |
2 files changed, 44 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 108969ed4c..251705ae50 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -10,6 +10,13 @@ module ActionMailer end class TestCase < ActiveSupport::TestCase + + # Use AM::TestCase for the base class when describing a mailer + register_spec_type(self) do |desc| + Class === desc && desc < ActionMailer::Base + end + register_spec_type(/Mailer( ?Test)?\z/i, self) + module Behavior extend ActiveSupport::Concern diff --git a/actionmailer/test/spec_type_test.rb b/actionmailer/test/spec_type_test.rb new file mode 100644 index 0000000000..90db59c2d2 --- /dev/null +++ b/actionmailer/test/spec_type_test.rb @@ -0,0 +1,37 @@ +require 'abstract_unit' + +class NotificationMailer < ActionMailer::Base; end +class Notifications < ActionMailer::Base; end + +class SpecTypeTest < ActiveSupport::TestCase + def assert_mailer actual + assert_equal ActionMailer::TestCase, actual + end + + def refute_mailer actual + refute_equal ActionMailer::TestCase, actual + end + + def test_spec_type_resolves_for_class_constants + assert_mailer MiniTest::Spec.spec_type(NotificationMailer) + assert_mailer MiniTest::Spec.spec_type(Notifications) + end + + def test_spec_type_resolves_for_matching_strings + assert_mailer MiniTest::Spec.spec_type("WidgetMailer") + assert_mailer MiniTest::Spec.spec_type("WidgetMailerTest") + assert_mailer MiniTest::Spec.spec_type("Widget Mailer Test") + # And is not case sensitive + assert_mailer MiniTest::Spec.spec_type("widgetmailer") + assert_mailer MiniTest::Spec.spec_type("widgetmailertest") + assert_mailer MiniTest::Spec.spec_type("widget mailer test") + end + + def test_spec_type_wont_match_non_space_characters + refute_mailer MiniTest::Spec.spec_type("Widget Mailer\tTest") + refute_mailer MiniTest::Spec.spec_type("Widget Mailer\rTest") + refute_mailer MiniTest::Spec.spec_type("Widget Mailer\nTest") + refute_mailer MiniTest::Spec.spec_type("Widget Mailer\fTest") + refute_mailer MiniTest::Spec.spec_type("Widget MailerXTest") + end +end |