aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-09-25 09:26:42 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-09-25 09:26:42 -0700
commitc96b20f8d985c6fa87a8efda7a4884e3c35e5739 (patch)
tree4fd35e201d0636a50c398525d81e62b8adba536a /actionmailer
parenta05a079c109ebbafd8112be0044c9d82b4a28d97 (diff)
parent64f254ccf74242453421d0c495388293dbc06c71 (diff)
downloadrails-c96b20f8d985c6fa87a8efda7a4884e3c35e5739.tar.gz
rails-c96b20f8d985c6fa87a8efda7a4884e3c35e5739.tar.bz2
rails-c96b20f8d985c6fa87a8efda7a4884e3c35e5739.zip
Merge pull request #7749 from blowmage/minitest
Improve support for minitest's spec DSL
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/test_case.rb15
-rw-r--r--actionmailer/test/spec_type_test.rb37
-rw-r--r--actionmailer/test/test_test.rb144
3 files changed, 193 insertions, 3 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb
index 108969ed4c..e60dda9694 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
@@ -42,9 +49,11 @@ module ActionMailer
end
def determine_default_mailer(name)
- name.sub(/Test$/, '').constantize
- rescue NameError
- raise NonInferrableMailerError.new(name)
+ mailer = determine_constant_from_test_name(name) do |constant|
+ Class === constant && constant < ActionMailer::Base
+ end
+ raise NonInferrableMailerError.new(name) if mailer.nil?
+ mailer
end
end
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
diff --git a/actionmailer/test/test_test.rb b/actionmailer/test/test_test.rb
index 86fd37bea6..139eb53359 100644
--- a/actionmailer/test/test_test.rb
+++ b/actionmailer/test/test_test.rb
@@ -26,3 +26,147 @@ class CrazyStringNameMailerTest < ActionMailer::TestCase
assert_equal TestTestMailer, self.class.mailer_class
end
end
+
+describe TestTestMailer do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe TestTestMailer, :action do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe TestTestMailer do
+ describe "nested" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe TestTestMailer, :action do
+ describe "nested" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "TestTestMailer" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "TestTestMailerTest" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "TestTestMailer" do
+ describe "nested" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "TestTestMailerTest" do
+ describe "nested" do
+ it "gets the mailer from the test name" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "AnotherCrazySymbolNameMailerTest" do
+ tests :test_test_mailer
+
+ it "gets the mailer after setting it with a symbol" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "AnotherCrazyStringNameMailerTest" do
+ tests 'test_test_mailer'
+
+ it "gets the mailer after setting it with a string" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "Another Crazy Name Mailer Test" do
+ tests TestTestMailer
+
+ it "gets the mailer after setting it manually" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "Another Crazy Symbol Name Mailer Test" do
+ tests :test_test_mailer
+
+ it "gets the mailer after setting it with a symbol" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "Another Crazy String Name Mailer Test" do
+ tests 'test_test_mailer'
+
+ it "gets the mailer after setting it with a string" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end
+
+describe "AnotherCrazySymbolNameMailerTest" do
+ tests :test_test_mailer
+
+ describe "nested" do
+ it "gets the mailer after setting it with a symbol" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "AnotherCrazyStringNameMailerTest" do
+ tests 'test_test_mailer'
+
+ describe "nested" do
+ it "gets the mailer after setting it with a string" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "Another Crazy Name Mailer Test" do
+ tests TestTestMailer
+
+ describe "nested" do
+ it "gets the mailer after setting it manually" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "Another Crazy Symbol Name Mailer Test" do
+ tests :test_test_mailer
+
+ describe "nested" do
+ it "gets the mailer after setting it with a symbol" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+ end
+end
+
+describe "Another Crazy String Name Mailer Test" do
+ tests 'test_test_mailer'
+
+ it "gets the mailer after setting it with a string" do
+ assert_equal TestTestMailer, self.class.mailer_class
+ end
+end