Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: e0fe8095f7
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (26 sloc) 1.2 KB

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, including:

  • 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)



  • pass the controller being specified to the outermost describe method.

    describe AccountController do # ...


Jump to Line
Something went wrong with that request. Please try again.