# File lib/dm-core/spec/lib/spec_helper.rb, line 15
    def self.cleanup_models
      descendants = DataMapper::Model.descendants.to_a

      while model = descendants.shift
        model_name = model.name.to_s.strip

        unless model_name.empty? || model_name[0] == ?#
          parts         = model_name.split('::')
          constant_name = parts.pop.to_sym
          base          = parts.empty? ? Object : Object.full_const_get(parts.join('::'))

          base.class_eval { remove_const(constant_name) if const_defined?(constant_name) }
        end

        remove_ivars(model)
        model.instance_methods(false).each { |method| model.send(:undef_method, method) }

        DataMapper::Model.descendants.delete(model)
      end

      unless DataMapper::Model.descendants.empty?
        raise 'DataMapper::Model.descendants is not empty'
      end
    end