Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support controller tests using spec DSL - fixes #7743

Add tests for controller tests using the minitest spec DSL.
  • Loading branch information...
commit fdc11fd01a4cc4f5580bf9e5a782f2a97c8442f7 1 parent 4894eef
@blowmage blowmage authored
View
8 actionpack/lib/action_controller/test_case.rb
@@ -347,9 +347,9 @@ def exists?
# 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
module Behavior
@@ -391,7 +391,9 @@ def controller_class
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)
View
116 actionpack/test/controller/spec_style_test.rb
@@ -0,0 +1,116 @@
+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
+
+# 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
+
+# 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
Please sign in to comment.
Something went wrong with that request. Please try again.