Contents

Controller specs

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). It allows you to simulate a single http request in each example, and then specify expected outcomes such as:

To specify outcomes, you can use:

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

Source: features/controller_specs/README.md at v2.9.0, RSpec Rails (MIT license).