aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/test_case.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/test_case.rb')
-rw-r--r--actionpack/lib/action_controller/test_case.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 77c6f26eac..c09050c390 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -15,6 +15,27 @@ module ActionController
end
end
+ # Superclass for Action Controller functional tests. Infers the controller under test from the test class name,
+ # and creates @controller, @request, @response instance variables.
+ #
+ # class WidgetsControllerTest < ActionController::TestCase
+ # def test_index
+ # get :index
+ # end
+ # end
+ #
+ # * @controller - WidgetController.new
+ # * @request - ActionController::TestRequest.new
+ # * @response - ActionController::TestResponse.new
+ #
+ # (Earlier versions of Rails required each functional test to subclass Test::Unit::TestCase and define
+ # @controller, @request, @response in +setup+.)
+ #
+ # If the controller cannot be inferred from the test class name, you can explicity set it with +tests+.
+ #
+ # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase
+ # tests WidgetController
+ # end
class TestCase < ActiveSupport::TestCase
# When the request.remote_addr remains the default for testing, which is 0.0.0.0, the exception is simply raised inline
# (bystepping the regular exception handling from rescue_action). If the request.remote_addr is anything else, the regular
@@ -41,6 +62,8 @@ module ActionController
@@controller_class = nil
class << self
+ # Sets the controller class name. Useful if the name can't be inferred from test class.
+ # Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>.
def tests(controller_class)
self.controller_class = controller_class
end