# File lib/rubygems/commands/test_command.rb, line 478
  def execute
    begin
      version = options[:version] || Gem::Requirement.default

      (get_all_gem_names rescue [options[:name]]).each do |name|

        unless name
          alert_error "No gem specified."
          show_help
          terminate_interaction 1
        end

        path, spec = if name =~ /\.gem$/
                       unless File.exist?(name)
                         say "unable to find gem #{name}"
                         next
                       end

                       inst = Gem::Installer.new(name)
                       tmpdir = Dir.mktmpdir
                       @created_tmpdir = true
                       inst.unpack(tmpdir)
                       unless inst.spec.extensions.empty?
                         say "gem #{name} has extensions. Due to limitations in rubygems,"
                         say "the gem must be installed before it can be tested."
                         next
                       end
                       [tmpdir, inst.spec]
                     else

                       if @spec and @gem_dir and File.directory?(@gem_dir)
                         [@gem_dir, @spec]
                       else

                        spec = find_gem(name, version)

                        unless spec
                          say "unable to find gem #{name} #{version}"
                          next
                        end

                        [spec.full_gem_path, spec]
                       end
                     end

        if File.exist?(File.join(path, '.gemtest')) or options[:force]
          # we find rake and the rakefile first to eliminate needlessly installing
          # dependencies.
          find_rakefile(path, spec)
          rake_path = find_rake

          unless $RG_T_INSTALLING_DEPENDENCIES and !config["test_development_dependencies"]
            install_dependencies(spec)
            run_tests(path, spec, rake_path)
          end
        else
          say "Gem '#{name}' (version #{version}) needs to opt-in for testing."
          say ""
          say "Locally available testing helps gems maintain high quality by"
          say "ensuring they work correctly on a wider array of platforms than the"
          say "original developer can access."
          say ""
          say "If you are the author: "
          say " * Add the file '.gemtest' to your spec.files"
          say " * Ensure 'rake test' works and doesn't do system damage"
          say " * Add your tests and Rakefile to your gem."
          say "" 
          say "For more information, please see the rubygems-test README:"
          say "https://github.com/rubygems/rubygems-test/blob/master/README.txt"
        end

        if @created_tmpdir
          FileUtils.rm_rf path
        end
      end
    rescue Gem::TestError => e
      raise if @on_install
      terminate_interaction 1
    end
  end