def find_spec_by_name_and_version(gem_name,
                                    version = Gem::Requirement.default,
                                    prerelease = false)
    spec_and_source = nil

    glob = if File::ALT_SEPARATOR then
             gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
           else
             gem_name
           end

    local_gems = Dir["#{glob}*"].sort.reverse

    local_gems.each do |gem_file|
      next unless gem_file =~ /gem$/
      begin
        spec = Gem::Format.from_file_by_path(gem_file).spec
        spec_and_source = [spec, gem_file]
        break
      rescue SystemCallError, Gem::Package::FormatError
      end
    end

    unless spec_and_source then
      dep = Gem::Dependency.new gem_name, version
      dep.prerelease = true if prerelease
      spec_and_sources = find_gems_with_sources(dep).reverse
      spec_and_source = spec_and_sources.find { |spec, source|
        Gem::Platform.match spec.platform
      }
    end

    if spec_and_source.nil? then
      raise Gem::GemNotFoundException.new(
        "Could not find a valid gem '#{gem_name}' (#{version}) locally or in a repository",
        gem_name, version, @errors)
    end

    @specs_and_sources = [spec_and_source]
  end
#
Finds a spec and the source_uri it came from for gem +gem_name+ and
+version+.  Returns an Array of specs and sources required for
installation of the gem.