class Spec::Rails::Example::ControllerExampleGroup
are not rescued or handeled with rescue_from.
Rspec on Rails will raise errors that occur in controller actions and
== Expecting Errors
isolation mode and revel in its benefits.
approach to begin with, however we encourage you to explore using the
from each spec. Experienced rails developers may find this an easier
the views. The benefit of this approach is that you get wider coverage
functional tests run - one set of tests for both the controllers and
In this mode, controller specs are run in the same way that rails
…
integrate_views
describe ThingController do
in your controller context:
To run in this mode, include the integrate_views
declaration
== Integration mode
better fault isolation.
somebody else. Combined w/ separate view specs, this also provides
the view, allowing that responsibility to be handled later, or by
of this mode is that can spec the controller completely independent of
No dependencies on views because none are ever rendered. The benefit
== Isolation mode (default)
specs.
the code to enable refactoring with minimal changes to the existing
to the code to enable quick fault isolation and far enough away from
in between: we want to a balance between specs that are close enough
and the more high level testing built into rails. BDD sits somewhere
represent the tension between the more granular testing common in TDD
which supports running specs for Controllers in two modes, which
Controller Examples use Spec::Rails::Example::ControllerExampleGroup,
Controller Examples live in $RAILS_ROOT/spec/controllers/.
def _assigns_hash_proxy
def _assigns_hash_proxy @_assigns_hash_proxy ||= AssignsHashProxy.new(self) {@response.template} end
def bypass_rescue
specified separately.
actions that might be caught by a rescue_from clause that is
in cases in which you want to specify errors coming out of
Bypasses any error rescues defined with rescue_from. Useful
def bypass_rescue if ::Rails::VERSION::STRING >= '2.2' def controller.rescue_action(exception) raise exception end else def controller.rescue_action_with_handler(exception) raise exception end end end
def controller_name(name)
controller_name :thing
describe "ThingController" do
your controller specs:
... then you must provide a controller_name within the context of
describe ThingsController do
When you don't pass a controller to describe, like this:
def controller_name(name) tests "#{name}_controller".camelize.constantize end
def inherited(klass) # :nodoc:
def inherited(klass) # :nodoc: klass.integrate_views(integrate_views?) klass.subject { controller } super end
def integrate_views(integrate_views = true)
See Spec::Rails::Example::ControllerExampleGroup for more
...
integrate_views
describe ThingController do
your controller examples in Integration mode.
Use integrate_views to instruct RSpec to render views in
def integrate_views(integrate_views = true) @integrate_views = integrate_views end
def integrate_views? # :nodoc:
def integrate_views? # :nodoc: @integrate_views end
def integrate_views?
def integrate_views? @integrate_views || self.class.integrate_views? end
def set_description(*args) # :nodoc:
def set_description(*args) # :nodoc: super if described_class && described_class.ancestors.include?(ActionController::Base) controller_klass = if superclass.controller_class.ancestors.include?(ActionController::Base) superclass.controller_class else described_class end tests controller_klass end end