Sha256: 218b7462a8469e381b481a5323c920794da6aaf25d5dd37656c839e03a24605a

Contents?: true

Size: 1.48 KB

Versions: 37

Compression:

Stored size: 1.48 KB

Contents

Controller specs live in `spec/controllers` or any example group with
`:type => :controller`.

A controller spec is an RSpec wrapper for a Rails functional test
([ActionController::TestCase::Behavior](https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb)).
It allows you to simulate a single http request in each example, and then
specify expected outcomes such as:

* rendered templates
* redirects
* instance variables assigned in the controller to be shared with the view
* cookies sent back with the response

To specify outcomes, you can use:
    
* standard rspec matchers (`response.code.should eq(200)`)
* standard test/unit assertions (`assert_equal 200, response.code`)
* rails assertions (`assert_response 200`)
* rails-specific matchers:
  * `response.should render_template (wraps assert_template)`
  * `response.should redirect_to (wraps assert_redirected_to)`
  * `assigns(:widget).should be_a_new(Widget)`
    
## Examples

    describe TeamsController do
      describe "GET index" do
        it "assigns @teams" do
          team = Team.create
          get :index
          assigns(:teams).should eq([team])
        end

        it "renders the index template" do
          get :index
          response.should render_template("index")
        end
      end
    end

## Views

* by default, views are not rendered. See
  [views are stubbed by default](controller-specs/views-are-stubbed-by-default) and
  [render_views](controller-specs/render-views) for details.

Version data entries

37 entries across 32 versions & 5 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-rails-2.13.0/features/controller_specs/README.md
rspec-rails-2.13.0 features/controller_specs/README.md
rspec-rails-2.12.2 features/controller_specs/README.md
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
rspec-rails-2.12.1 features/controller_specs/README.md
rspec-rails-2.12.0 features/controller_specs/README.md
rspec-rails-2.11.4 features/controller_specs/README.md
gem_repackager-0.1.0 support/gems/rspec-rails-2.11.0/features/controller_specs/README.md
rspec-rails-2.11.0 features/controller_specs/README.md
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rspec-rails-2.10.1/features/controller_specs/README.md