class Spec::Rails::Example::ControllerExampleGroup

end
response.code.should == “501”
it “should return a 501” do
end
response.response_code.should == 501
it “should return a 501” do
end
response.should be_error
it “should return an error in the header” do
When using Rail’s error handling, you can expect error codes in headers …
end
controller.use_rails_error_handling!
before(:each) do
rails error handling …
Rspec and have Rail’s default behaviour,tell the controller to use
actions and return an error code in the header. If you wish to override
In contrast, Rails will swallow errors that are raised in controller
Rspec on Rails will raise errors that occur in controller actions.
== Expecting Errors
in its benefits.
we encourage you to explore using the isolation mode and revel
developers may find this an easier approach to begin with, however
you get wider coverage from each spec. Experienced rails
controllers and the views. The benefit of this approach is that
rails functional tests run - one set of tests for both the
In this mode, controller specs are run in the same way that
…
integrate_views
describe ThingController do
in your controller context:
To run in this mode, include the integrate_views declaration
== Integration mode
specs, this also provides better fault isolation.
handled later, or by somebody else. Combined w/ separate view
independent of the view, allowing that responsibility to be
benefit of this mode is that can spec the controller completely
No dependencies on views because none are ever rendered. The
== Isolation mode (default)
with minimal changes to the existing specs.
isolation and far enough away from the code to enable refactoring
specs that are close enough to the code to enable quick fault
rails. BDD sits somewhere in between: we want to a balance between
testing common in TDD and the more high level testing built into
Controllers in two modes, which represent the tension between the more granular
Controller Examples use Spec::Rails::Example::ControllerExampleGroup, which supports running specs for
Controller Examples live in $RAILS_ROOT/spec/controllers/.

def _assigns_hash_proxy

def _assigns_hash_proxy
  @_assigns_hash_proxy ||= AssignsHashProxy.new self do
    @response.template
  end
end

def controller_name(name)

...
controller_name :thing
describe "ThingController" do

your controller specs:
You MUST provide a controller_name within the context of
def controller_name(name)
  @controller_class_name = "#{name}_controller".camelize
end

def controller_path #:nodoc:

:nodoc:
def controller_path #:nodoc:
  self.class.name.underscore.gsub('_controller', '')
end

def ensure_that_routes_are_loaded

def ensure_that_routes_are_loaded
  ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
end

def inherited(klass) # :nodoc:

:nodoc:
def inherited(klass) # :nodoc:
  klass.controller_class_name = controller_class_name
  klass.integrate_views(integrate_views?)
  super
end

def initialize(defined_description, options={}, &implementation) #:nodoc:

:nodoc:
def initialize(defined_description, options={}, &implementation) #:nodoc:
  super
  controller_class_name = self.class.controller_class_name
  if controller_class_name
    @controller_class_name = controller_class_name.to_s
  else
    @controller_class_name = self.class.described_type.to_s
  end
  @integrate_views = self.class.integrate_views?
end

def integrate_views(integrate_views = true)

Integration and Isolation modes.
See Spec::Rails::Example::ControllerExampleGroup for more information about

...
integrate_views
describe ThingController do

Use this to instruct RSpec to render views in your controller examples (Integration Mode).
def integrate_views(integrate_views = true)
  @integrate_views = integrate_views
end

def integrate_views? # :nodoc:

:nodoc:
def integrate_views? # :nodoc:
  @integrate_views
end

def params_from(method, path)

=> :controller => 'registrations', :action => 'edit', :id => 1
params_from(:get, '/registrations/1;edit')
== Example
an incoming path so the parameters it generates can be checked
Uses ActionController::Routing::Routes to parse
def params_from(method, path)
  ensure_that_routes_are_loaded
  ActionController::Routing::Routes.recognize_path(path, :method => method)
end

def route_for(options)

=> '/registrations/1;edit'
route_for(:controller => 'registrations', :action => 'edit', :id => 1)
== Example
the correct route for a given set of options.
Uses ActionController::Routing::Routes to generate
def route_for(options)
  ensure_that_routes_are_loaded
  ActionController::Routing::Routes.generate(options)
end