old_controller = @controller @controller = LoginController.new post( :attempt_login, {:user => {:name => 'joe', :password => 'password'}} ) @controller = old_controller
If you have several login methods, such as a #login_admin and #login_regular, you could make a wrapper to reduce duplication:
def wrap_with_controller( new_controller = LoginController ) old_controller = @controller @controller = new_controller.new yield @controller = old_controller end def login_admin wrap_with_controller do post( :attempt_login, {:user => {:name => 'root', :password => 'password'}} ) end end def login_regular wrap_with_controller do post( :attempt_login, {:user => {:name => 'joe', :password => 'password'}} ) end end