Module: RSpec::Rails::ControllerExampleGroup::ClassMethods

### Home Classes Methods

### In Files

- lib/rspec/rails/example/controller_example_group.rb

### Methods

- ::name
- #controller
- #controller_class
- #routes

### Files

- fixture

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Rails
- RSpec::Rails::AssertionDelegator
- RSpec::Rails::ControllerExampleGroup
- RSpec::Rails::ControllerExampleGroup::BypassRescue
- RSpec::Rails::ControllerExampleGroup::ClassMethods
- RSpec::Rails::Extensions
- RSpec::Rails::Extensions::ActiveRecord
- RSpec::Rails::FeatureExampleGroup
- RSpec::Rails::FixtureSupport
- RSpec::Rails::HelperExampleGroup
- RSpec::Rails::HelperExampleGroup::ClassMethods
- RSpec::Rails::IllegalDataAccessException
- RSpec::Rails::MailerExampleGroup
- RSpec::Rails::MailerExampleGroup::ClassMethods
- RSpec::Rails::Matchers
- RSpec::Rails::Matchers::BeANew
- RSpec::Rails::Matchers::BeANewRecord
- RSpec::Rails::Matchers::BeValid
- RSpec::Rails::Matchers::HaveExtensions
- RSpec::Rails::Matchers::RedirectTo
- RSpec::Rails::Matchers::RedirectTo::RedirectTo
- RSpec::Rails::Matchers::RenderTemplate
- RSpec::Rails::Matchers::RenderTemplate::RenderTemplateMatcher
- RSpec::Rails::Matchers::RoutingMatchers
- RSpec::Rails::Matchers::RoutingMatchers::BeRoutableMatcher
- RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
- RSpec::Rails::Matchers::RoutingMatchers::RouteToMatcher
- RSpec::Rails::MiniTestLifecycleAdapter
- RSpec::Rails::MinitestCounters
- RSpec::Rails::Mocks
- RSpec::Rails::Mocks::ActiveModelInstanceMethods
- RSpec::Rails::Mocks::ActiveModelStubExtensions
- RSpec::Rails::Mocks::ActiveRecordInstanceMethods
- RSpec::Rails::Mocks::ActiveRecordStubExtensions
- RSpec::Rails::ModelExampleGroup
- RSpec::Rails::ModuleInclusion
- RSpec::Rails::RailsExampleGroup
- RSpec::Rails::Railtie
- RSpec::Rails::RequestExampleGroup
- RSpec::Rails::RoutingExampleGroup
- RSpec::Rails::RoutingExampleGroup::ClassMethods
- RSpec::Rails::SetupAndTeardownAdapter
- RSpec::Rails::SetupAndTeardownAdapter::ClassMethods
- RSpec::Rails::TestUnitAssertionAdapter
- RSpec::Rails::TestUnitAssertionAdapter::AssertionDelegator
- RSpec::Rails::TestUnitAssertionAdapter::ClassMethods
- RSpec::Rails::Version
- RSpec::Rails::ViewAssigns
- RSpec::Rails::ViewExampleGroup
- RSpec::Rails::ViewExampleGroup::ClassMethods
- RSpec::Rails::ViewExampleGroup::ExampleMethods
- RSpec::Rails::ViewRendering
- RSpec::Rails::ViewRendering::ClassMethods
- RSpec::Rails::ViewRendering::EmptyTemplateHandler
- RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator
- RSpec::Rails::ViewRendering::EmptyTemplates
- Rspec
- Rspec::Generators
- Rspec::Generators::Base
- Rspec::Generators::ControllerGenerator
- Rspec::Generators::HelperGenerator
- Rspec::Generators::InstallGenerator
- Rspec::Generators::IntegrationGenerator
- Rspec::Generators::MailerGenerator
- Rspec::Generators::ModelGenerator
- Rspec::Generators::ObserverGenerator
- Rspec::Generators::ScaffoldGenerator
- Rspec::Generators::ViewGenerator
- Rails
- Rails::Generators
- Rails::Generators::GeneratedAttribute
- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- ActiveModel
- ActiveModel::Validations
- ActiveRecord
- ActiveRecord::Base
- Autotest
- Autotest::RailsRspec2
- Object
- RequestInstanceMethods

No matching classes.

# RSpec::Rails::ControllerExampleGroup::ClassMethods

### Public Class Methods

name() click to toggle source

    # File lib/rspec/rails/example/controller_example_group.rb, line 63
    def self.name; "AnonymousController"; end

### Public Instance Methods

controller(base_class = nil, &body) click to toggle source

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

    # File lib/rspec/rails/example/controller_example_group.rb, line 57
    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)

      before do
        @orig_routes = self.routes
        self.routes  = ActionDispatch::Routing::RouteSet.new.tap { |r|
          r.draw { resources :anonymous }
        }
      end

      after do
        self.routes  = @orig_routes
        @orig_routes = nil
      end
    end

controller_class() click to toggle source

@private

    # File lib/rspec/rails/example/controller_example_group.rb, line 18
    def controller_class
      described_class
    end

routes(&blk) click to toggle source

Specifies the routeset that will be used for the example group. This is most useful when testing Rails engines.

@example

    describe MyEngine::PostsController do
      routes { MyEngine::Engine.routes }

      # ...
    end

    # File lib/rspec/rails/example/controller_example_group.rb, line 90
    def routes(&blk)
      before do
        self.routes = blk.call
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.