    # File lib/rubygems/dependency_installer.rb, line 162
      def find_spec_by_name_and_version gem_name, version = Gem::Requirement.default
        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

        unless local_gems.empty? then
          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
        end

        if spec_and_source.nil? then
          dep = Gem::Dependency.new gem_name, version
          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,
            "could not find gem #{gem_name} locally or in a repository"
        end

        @specs_and_sources = [spec_and_source]
      end