How to fix failing controller specs 91% of the time

If your controller spec never reaches your controller code:

  1. Make sure you are signed in.

  2. Make sure you are actually triggering a request by saying get :edit or something siliar.

  3. Know that views are not rendered by default for controller specs unless you tell them to (render_views).
    ^
    describe UsersController do
    describe '#edit' do
    it 'should work' do
    sign_in
    get :edit
    end
    end
    end

    define something like this in your spec_helper.rb:

    def sign_in(user = User.new)
    controller.instance_variable_set('@current_user', user)
    end

Arne Hartherz Over 13 years ago