Skip to content
This repository

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

..
Octocat-spinner-32 README.md
Octocat-spinner-32 anonymous_controller.feature
Octocat-spinner-32 controller_spec.feature
Octocat-spinner-32 isolation_from_views.feature
Octocat-spinner-32 render_views.feature
README.md

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:

  • 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

Something went wrong with that request. Please try again.