How to fix failing controller specs 91% of the time

Updated . Posted . Visible to the public.

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
Last edit
Michael Leimstädtner
Keywords
authentication, login
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2010-12-02 15:26)