Module: RSpec::Rails::ControllerExampleGroup

Extended by:
ActiveSupport::Concern
Includes:
ActionController::TestCase::Behavior, Matchers::RedirectTo, Matchers::RenderTemplate, Matchers::RoutingMatchers, RailsExampleGroup, ViewRendering
Defined in:
lib/rspec/rails/example/controller_example_group.rb

Defined Under Namespace

Modules: BypassRescue, ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Matchers::RoutingMatchers

#be_routable, #route_to

Methods included from Matchers::RenderTemplate

#render_template

Methods included from Matchers::RedirectTo

#redirect_to

Methods included from ViewRendering

#render_views?

Methods included from Matchers

#be_a_new, #be_new_record

Methods included from TestUnitAssertionAdapter

#assertion_delegator

Methods included from SetupAndTeardownAdapter

#method_name

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

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



109
110
111
112
113
114
115
# File 'lib/rspec/rails/example/controller_example_group.rb', line 109

def method_missing(method, *args, &block)
  if @orig_routes && @orig_routes.named_routes.helpers.include?(method)
    controller.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



77
78
79
# File 'lib/rspec/rails/example/controller_example_group.rb', line 77

def controller
  @controller
end

#routesObject (readonly)

Returns the value of attribute routes.



77
78
79
# File 'lib/rspec/rails/example/controller_example_group.rb', line 77

def routes
  @routes
end

Instance Method Details

#bypass_rescueObject

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


103
104
105
# File 'lib/rspec/rails/example/controller_example_group.rb', line 103

def bypass_rescue
  controller.extend(BypassRescue)
end