Iain has published a solution for using layouts with AuthLogic . To rephrase, the following helpers are included in spec_helpers.rb :
def current_user(stubs = {}) @current_user ||= mock_model(User, stubs) end def user_session(stubs = {}, user_stubs = {}) @current_user_session ||= mock_model(UserSession, {:user => current_user(user_stubs)}.merge(stubs)) end def login(session_stubs = {}, user_stubs = {}) UserSession.stub!(:find).and_return(user_session(session_stubs, user_stubs)) end def logout @user_session = nil end
I have included this in my specifications and I find that it does exactly what I was hoping for. I have specifications of a working controller that explicate the model layout for login, so now they donโt all break when I add a field to User. An example implementation of this in the specification is as follows:
describe SecretsController do before { login } it "should be very very secret!" end
PS I hate answering my question, but this is the answer I was looking for; I just did not find it early enough.
source share