title: How can I spec out an authlogic sessions controller using using a stub?
body: <p>I want to test my User Session Controller testing that a user session is first built then saved. My UserSession class looks like this:</p>
  
  <pre><code>class UserSession &lt; Authlogic::Session::Base
  end
  </code></pre>
  
  <p>The create method of my UserSessionsController looks like this:</p>
  
  <pre><code>def create
      @user_session = UserSession.new(params[:user_session])
      if @user_session.save
          flash[:notice] = "Successfully logged in."
          redirect_back_or_default administer_home_page_url
      else
          render :new
      end
  end
  </code></pre>
  
  <p>and my controller spec looks like this:</p>
  
  <pre><code>describe UserSessionsController do
  
      it "should build a new user session" do
          UserSession.stub!(:new).with(:email, :password)
          UserSession.should_receive(:new).with(:email =&gt; "some_email@gmail.com", :password =&gt; "foobar")
          post :create, :user_session =&gt; { :email =&gt; "some_email@gmail.com", :password =&gt; "foobar" }
      end
  end
  </code></pre>
  
  <p>I stub out the new method but I still get the following error when I run the test:</p>
  
  <pre><code>Spec::Mocks::MockExpectationError in 'UserSessionsController should build a new user session'
  &lt;UserSession (class)&gt; received :new with unexpected arguments
    expected: ({:password=&gt;"foobar", :email=&gt;"some_email@gmail.com"})
         got: ({:priority_record=&gt;nil}, nil)
  </code></pre>
  
  <p>It's although the new method is being called on UserSession before my controller code is getting called. Calling activate_authlogic makes no difference.</p>