aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
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 /actionpack
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 'actionpack')
-rw-r--r--actionpack/lib/action_controller/test_case.rb9
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb3
-rw-r--r--actionpack/lib/action_view/test_case.rb10
-rw-r--r--actionpack/test/controller/spec_style_test.rb208
-rw-r--r--actionpack/test/controller/spec_type_test.rb37
-rw-r--r--actionpack/test/dispatch/spec_type_test.rb41
-rw-r--r--actionpack/test/template/spec_type_test.rb39
-rw-r--r--actionpack/test/template/test_case_test.rb2
-rw-r--r--actionpack/test/template/test_test.rb56
9 files changed, 397 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index bb693c6494..a28033fb32 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -347,10 +347,11 @@ module ActionController
# assert_redirected_to page_url(:title => 'foo')
class TestCase < ActiveSupport::TestCase
- # Use AS::TestCase for the base class when describing a model
+ # Use AC::TestCase for the base class when describing a controller
register_spec_type(self) do |desc|
- Class === desc && desc < ActionController::Base
+ Class === desc && desc < ActionController::Metal
end
+ register_spec_type(/Controller( ?Test)?\z/i, self)
module Behavior
extend ActiveSupport::Concern
@@ -391,7 +392,9 @@ module ActionController
end
def determine_default_controller_class(name)
- name.sub(/Test$/, '').safe_constantize
+ determine_constant_from_test_name(name) do |constant|
+ Class === constant && constant < ActionController::Metal
+ end
end
def prepare_controller_class(new_class)
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index a8b27ffafd..4bd7b69642 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -490,6 +490,9 @@ module ActionDispatch
include ActionController::TemplateAssertions
include ActionDispatch::Routing::UrlFor
+ # Use AD::IntegrationTest for acceptance tests
+ register_spec_type(/(Acceptance|Integration) ?Test\z/i, self)
+
@@app = nil
def self.app
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 434fc8cc14..a4e8068026 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -30,6 +30,9 @@ module ActionView
end
end
+ # Use AV::TestCase for the base class for helpers and views
+ register_spec_type(/(Helper|View)( ?Test)?\z/i, self)
+
module Behavior
extend ActiveSupport::Concern
@@ -58,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/controller/spec_style_test.rb b/actionpack/test/controller/spec_style_test.rb
new file mode 100644
index 0000000000..e118c584ca
--- /dev/null
+++ b/actionpack/test/controller/spec_style_test.rb
@@ -0,0 +1,208 @@
+require "abstract_unit"
+
+class ApplicationController < ActionController::Base; end
+class ModelsController < ApplicationController; end
+module Admin
+ class WidgetsController < ApplicationController; end
+end
+
+# ApplicationController
+describe ApplicationController do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ApplicationController, @controller
+ end
+ end
+ end
+end
+
+describe ApplicationController, :index do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ApplicationController, @controller
+ end
+ end
+ end
+end
+
+describe ApplicationController, "unauthenticated user" do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ApplicationController, @controller
+ end
+ end
+ end
+end
+
+describe "ApplicationControllerTest" do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ApplicationController, @controller
+ end
+ end
+ end
+end
+
+describe "ApplicationControllerTest", :index do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ApplicationController, @controller
+ end
+ end
+ end
+end
+
+describe "ApplicationControllerTest", "unauthenticated user" do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ApplicationController, @controller
+ end
+ end
+ end
+end
+
+# ModelsController
+describe ModelsController do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ModelsController, @controller
+ end
+ end
+ end
+end
+
+describe ModelsController, :index do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ModelsController, @controller
+ end
+ end
+ end
+end
+
+describe ModelsController, "unauthenticated user" do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ModelsController, @controller
+ end
+ end
+ end
+end
+
+describe "ModelsControllerTest" do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ModelsController, @controller
+ end
+ end
+ end
+end
+
+describe "ModelsControllerTest", :index do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ModelsController, @controller
+ end
+ end
+ end
+end
+
+describe "ModelsControllerTest", "unauthenticated user" do
+ describe "nested" do
+ describe "even deeper" do
+ it "exists" do
+ assert_kind_of ModelsController, @controller
+ end
+ end
+ end
+end
+
+# Nested Admin::WidgetsControllerTest
+module Admin
+ class WidgetsControllerTest < ActionController::TestCase
+ test "exists" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+
+ describe WidgetsController do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+ end
+
+ describe WidgetsController, "unauthenticated users" do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+ end
+end
+
+class Admin::WidgetsControllerTest < ActionController::TestCase
+ test "exists here too" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+end
+
+describe Admin::WidgetsController do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+end
+
+describe Admin::WidgetsController, "unauthenticated users" do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+end
+
+describe "Admin::WidgetsController" do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+end
+
+describe "Admin::WidgetsControllerTest" do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+end
+
+describe "Admin::WidgetsController", "unauthenticated users" do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+end
+
+describe "Admin::WidgetsControllerTest", "unauthenticated users" do
+ describe "index" do
+ it "respond successful" do
+ assert_kind_of Admin::WidgetsController, @controller
+ end
+ end
+end
diff --git a/actionpack/test/controller/spec_type_test.rb b/actionpack/test/controller/spec_type_test.rb
new file mode 100644
index 0000000000..caeb0fd4dd
--- /dev/null
+++ b/actionpack/test/controller/spec_type_test.rb
@@ -0,0 +1,37 @@
+require "abstract_unit"
+
+class ApplicationController < ActionController::Base; end
+class ModelsController < ApplicationController; end
+
+class SpecTypeTest < ActiveSupport::TestCase
+ def assert_controller actual
+ assert_equal ActionController::TestCase, actual
+ end
+
+ def refute_controller actual
+ refute_equal ActionController::TestCase, actual
+ end
+
+ def test_spec_type_resolves_for_class_constants
+ assert_controller MiniTest::Spec.spec_type(ApplicationController)
+ assert_controller MiniTest::Spec.spec_type(ModelsController)
+ end
+
+ def test_spec_type_resolves_for_matching_strings
+ assert_controller MiniTest::Spec.spec_type("WidgetController")
+ assert_controller MiniTest::Spec.spec_type("WidgetControllerTest")
+ assert_controller MiniTest::Spec.spec_type("Widget Controller Test")
+ # And is not case sensitive
+ assert_controller MiniTest::Spec.spec_type("widgetcontroller")
+ assert_controller MiniTest::Spec.spec_type("widgetcontrollertest")
+ assert_controller MiniTest::Spec.spec_type("widget controller test")
+ end
+
+ def test_spec_type_wont_match_non_space_characters
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\tTest")
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\rTest")
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\nTest")
+ refute_controller MiniTest::Spec.spec_type("Widget Controller\fTest")
+ refute_controller MiniTest::Spec.spec_type("Widget ControllerXTest")
+ end
+end
diff --git a/actionpack/test/dispatch/spec_type_test.rb b/actionpack/test/dispatch/spec_type_test.rb
new file mode 100644
index 0000000000..6cd19fd333
--- /dev/null
+++ b/actionpack/test/dispatch/spec_type_test.rb
@@ -0,0 +1,41 @@
+require "abstract_unit"
+
+class SpecTypeTest < ActiveSupport::TestCase
+ def assert_dispatch actual
+ assert_equal ActionDispatch::IntegrationTest, actual
+ end
+
+ def refute_dispatch actual
+ refute_equal ActionDispatch::IntegrationTest, actual
+ end
+
+ def test_spec_type_resolves_for_matching_acceptance_strings
+ assert_dispatch MiniTest::Spec.spec_type("WidgetAcceptanceTest")
+ assert_dispatch MiniTest::Spec.spec_type("Widget Acceptance Test")
+ assert_dispatch MiniTest::Spec.spec_type("widgetacceptancetest")
+ assert_dispatch MiniTest::Spec.spec_type("widget acceptance test")
+ end
+
+ def test_spec_type_wont_match_non_space_characters_acceptance
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\tTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\rTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\nTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget Acceptance\fTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget AcceptanceXTest")
+ end
+
+ def test_spec_type_resolves_for_matching_integration_strings
+ assert_dispatch MiniTest::Spec.spec_type("WidgetIntegrationTest")
+ assert_dispatch MiniTest::Spec.spec_type("Widget Integration Test")
+ assert_dispatch MiniTest::Spec.spec_type("widgetintegrationtest")
+ assert_dispatch MiniTest::Spec.spec_type("widget integration test")
+ end
+
+ def test_spec_type_wont_match_non_space_characters_integration
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\tTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\rTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\nTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget Integration\fTest")
+ refute_dispatch MiniTest::Spec.spec_type("Widget IntegrationXTest")
+ end
+end
diff --git a/actionpack/test/template/spec_type_test.rb b/actionpack/test/template/spec_type_test.rb
new file mode 100644
index 0000000000..b35985d5f9
--- /dev/null
+++ b/actionpack/test/template/spec_type_test.rb
@@ -0,0 +1,39 @@
+require 'abstract_unit'
+
+class SpecTypeTest < ActiveSupport::TestCase
+ def assert_view actual
+ assert_equal ActionView::TestCase, actual
+ end
+
+ def refute_view actual
+ refute_equal ActionView::TestCase, actual
+ end
+
+ def test_spec_type_resolves_for_matching_helper_strings
+ assert_view MiniTest::Spec.spec_type("WidgetHelper")
+ assert_view MiniTest::Spec.spec_type("WidgetHelperTest")
+ assert_view MiniTest::Spec.spec_type("Widget Helper Test")
+ # And is not case sensitive
+ assert_view MiniTest::Spec.spec_type("widgethelper")
+ assert_view MiniTest::Spec.spec_type("widgethelpertest")
+ assert_view MiniTest::Spec.spec_type("widget helper test")
+ end
+
+ def test_spec_type_resolves_for_matching_view_strings
+ assert_view MiniTest::Spec.spec_type("WidgetView")
+ assert_view MiniTest::Spec.spec_type("WidgetViewTest")
+ assert_view MiniTest::Spec.spec_type("Widget View Test")
+ # And is not case sensitive
+ assert_view MiniTest::Spec.spec_type("widgetview")
+ assert_view MiniTest::Spec.spec_type("widgetviewtest")
+ assert_view MiniTest::Spec.spec_type("widget view test")
+ end
+
+ def test_spec_type_wont_match_non_space_characters
+ refute_view MiniTest::Spec.spec_type("Widget Helper\tTest")
+ refute_view MiniTest::Spec.spec_type("Widget Helper\rTest")
+ refute_view MiniTest::Spec.spec_type("Widget Helper\nTest")
+ refute_view MiniTest::Spec.spec_type("Widget Helper\fTest")
+ refute_view MiniTest::Spec.spec_type("Widget HelperXTest")
+ end
+end
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