Module: RSpec::Rails::ControllerExampleGroup Private

Extended by:
ActiveSupport::Concern
Includes:
ActionController::TestCase::Behavior, AssertionDelegator.new( ActionDispatch::Assertions::RoutingAssertions ), Matchers::RedirectTo, Matchers::RenderTemplate, Matchers::RoutingMatchers, RailsExampleGroup, ViewRendering
Defined in:
lib/rspec/rails/example/controller_example_group.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Container module for controller spec functionality.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Matchers::RoutingMatchers

#be_routable, #route_to

Methods included from Matchers::RenderTemplate

#have_rendered

Methods included from Matchers::RedirectTo

#redirect_to

Methods included from ViewRendering

#render_views?

Methods included from Matchers

#be_a_new, #be_new_record, #be_valid, #have_http_status

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

If method is a named_route, delegates to the RouteSet associated with this controller.



171
172
173
174
175
176
177
# File 'lib/rspec/rails/example/controller_example_group.rb', line 171

def method_missing(method, *args, &block)
  if route_available?(method)
    controller.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#controllerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the controller object instance under test.



127
128
129
# File 'lib/rspec/rails/example/controller_example_group.rb', line 127

def controller
  @controller
end

#routesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the Rails routes used for the spec.



131
132
133
# File 'lib/rspec/rails/example/controller_example_group.rb', line 131

def routes
  @routes
end

Instance Method Details

#bypass_rescueObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extends the controller with a module that overrides rescue_with_handler to raise the exception passed to it. Use this to specify that an action should raise an exception given appropriate conditions.

Examples:

describe ProfilesController do
  it "raises a 403 when a non-admin user tries to view another user's profile" do
    profile = create_profile
     profile.user

    expect do
      bypass_rescue
      get :show, :id => profile.id + 1
    end.to raise_error(/403 Forbidden/)
  end
end


165
166
167
# File 'lib/rspec/rails/example/controller_example_group.rb', line 165

def bypass_rescue
  controller.extend(BypassRescue)
end