Skip to content

Instantly share code, notes, and snippets.

@vidmantas
Created March 30, 2010 15:19
Show Gist options
  • Save vidmantas/349188 to your computer and use it in GitHub Desktop.
Save vidmantas/349188 to your computer and use it in GitHub Desktop.
# in spec_helper.rb
config.mock_with :mocha
#...
end
# returns current fake user
def current_user
@current_user ||= User.make
end
# returns current session mock
def user_session
@user_session = mock
@user_session.stubs(:user).returns(current_user)
@user_session.stubs(:record)
@user_session
end
# logges me in
def login_stub
UserSession.any_instance.stubs(:find).returns(user_session)
controller.stubs(:current_user).returns(current_user)
end
# logges me out
def logout
@user_session = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment