title: testing devise and cancan in controller specs (rspec)
body: <p>Now that I have CanCan and Devise working nicely I need to add to my tests.</p>
  
  <p>Should I expect to end up with double the number of tests, maybe more?  I need to test everything as a  "guest" user then test as user and also as admin.</p>
  
  <p>With rspec how would you lay this out?</p>
  
  <pre><code>describe "GET edit" do
      login_admin
      it "assigns the requested forum_topic as @forum_topic" do
        ForumTopic.stub(:find).with("37") { mock_forum_topic }
        get :edit, :id =&gt; "37"
        response.should redirect_to( new_user_session_path )
      end
  
      it "assigns the requested forum_topic as @forum_topic" do
        ForumTopic.stub(:find).with("37") { mock_forum_topic }
        get :edit, :id =&gt; "37"
        assigns(:forum_topic).should be(mock_forum_topic)
      end
  end
  </code></pre>
  
  <p>helper module</p>
  
  <pre><code>  def login_admin
      before(:each) do
        @request.env["devise.mapping"] = Devise.mappings[:admin]
        sign_in Factory.create(:admin)
      end
    end
  
    def login_user
      before(:each) do
        @request.env["devise.mapping"] = Devise.mappings[:user]
        @user = Factory.create(:user)
        sign_in @user
      end
    end
  </code></pre>