lib/rspec/rails/example/controller_example_group.rb
def controller(base_class = nil, &body)
          base_class ||= RSpec.configuration.infer_base_class_for_anonymous_controllers? ?
            controller_class :
            ApplicationController

          metadata[:example_group][:described_class] = Class.new(base_class) do
            def self.name; "AnonymousController"; end
          end
          metadata[:example_group][:described_class].class_eval(&body)

          with_routing do |set|
            set.draw do |map|
              map.resources :anonymous
              map.connect 'anonymous/:action', :controller => :anonymous
              map.connect 'anonymous/:action/:id', :controller => :anonymous
            end
          end
        end
# Supports a simple DSL for specifying behavior of ApplicationController.
# Creates an anonymous subclass of ApplicationController and evals the
# `body` in that context. Also sets up implicit routes for this
# controller, that are separate from those defined in "config/routes.rb".
#
# @note Due to Ruby 1.8 scoping rules in anoymous subclasses, constants
#   defined in `ApplicationController` must be fully qualified (e.g.
#   `ApplicationController::AccessDenied`) in the block passed to the
#   `controller` method. Any instance methods, filters, etc, that are
#   defined in `ApplicationController`, however, are accessible from
#   within the block.
#
# @example
#
#     describe ApplicationController do
#       controller do
#         def index
#           raise ApplicationController::AccessDenied
#         end
#       end
#
#       describe "handling AccessDenied exceptions" do
#         it "redirects to the /401.html page" do
#           get :index
#           response.should redirect_to("/401.html")
#         end
#       end
#     end
#
# If you would like to spec a subclass of ApplicationController, call
# controller like so:
#
#     controller(ApplicationControllerSubclass) do
#       # ....
#     end
Supports a simple DSL for specifying behavior of ApplicationController.
Creates an anonymous subclass of ApplicationController and evals the
`body` in that context. Also sets up implicit routes for this
controller, that are separate from those defined in "config/routes.rb".
Supports a simple DSL for specifying behavior of ApplicationController . Creates an anonymous subclass of ApplicationController and evals the ` body ` in that context . Also sets up implicit routes for this controller that are separate from those defined in " config / routes . rb " .
def controller(base_class = nil, &body)
          base_class ||= RSpec.configuration.infer_base_class_for_anonymous_controllers? ?
            controller_class :
            ApplicationController
          metadata[:example_group][:described_class] = Class.new(base_class) do
            def self.name; "AnonymousController"; end
          end
          metadata[:example_group][:described_class].class_eval(&body)
          with_routing do |set|
            set.draw do |map|
              map.resources :anonymous
              map.connect 'anonymous/:action', :controller => :anonymous
              map.connect 'anonymous/:action/:id', :controller => :anonymous
            end
          end
        end
def controller ( base_class = nil , & body ) base_class ||= RSpec . configuration . infer_base_class_for_anonymous_controllers? ? controller_class : ApplicationController metadata [ :example_group ] [ :described_class ] = Class . new ( base_class ) do def self . name ; "AnonymousController" ; end end metadata [ :example_group ] [ :described_class ] . class_eval ( & body ) with_routing do | set | set . draw do | map | map . resources :anonymous map . connect 'anonymous/:action' , :controller => :anonymous map . connect 'anonymous/:action/:id' , :controller => :anonymous end end end
Supports a simple DSL for specifying behavior of ApplicationController.
Supports a simple DSL for specifying behavior of ApplicationController .
base_class
body
note
Due to Ruby 1.8 scoping rules in anoymous subclasses, constants defined in `ApplicationController` must be fully qualified  in the block passed to the `controller` method. Any instance methods, filters, etc, that are defined in `ApplicationController`, however, are accessible from within the block.
Due to Ruby 1 . 8 scoping rules in anoymous subclasses constants defined in ` ApplicationController ` must be fully qualified in the block passed to the ` controller ` method . Any instance methods filters etc that are defined in ` ApplicationController ` however are accessible from within the block .
example
describe ApplicationController do controller do def index raise ApplicationController::AccessDenied end end describe "handling AccessDenied exceptions" do it "redirects to the /401.html page" do get :index response.should redirect_to("/401.html") end end end If you would like to spec a subclass of ApplicationController, call controller like so: controller(ApplicationControllerSubclass) do # .... end
describe ApplicationController do controller do def index raise ApplicationController :: AccessDenied end end describe " handling AccessDenied exceptions " do it " redirects to the / 401 . html page " do get : index response . should redirect_to ( " / 401 . html " ) end end end If you would like to spec a subclass of ApplicationController call controller like so : controller ( ApplicationControllerSubclass ) do # .... end