Sha256: 39935dacff5bbfbffa3cf3e75d8831e66efd851f24bf8f692273e5508e69faa3

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

class FakeGemServer
  include SpecHelpers

  def index(name, version)
    [name, Gem::Version.new(version), "ruby"]
  end

  def call(env)
    request = Rack::Request.new(env)

    if request.path =~ /latest_specs/
      latest_index = [
        index("builder",  "3.0.0"),
        index("highline", "1.6.1"),
        index("rake",     "0.8.7"),
      ]
      [200, {"Content-Type" => "application/octet-stream"}, compress(latest_index)]
    elsif request.path =~ /prerelease_specs/
      prerelease_index = [
        index("bundler",  "1.1.pre")
      ]
      [200, {"Content-Type" => "application/octet-stream"}, compress(prerelease_index)]
    elsif request.path =~ /specs/
      big_index = [
        index("builder",  "3.0.0"),
        index("highline", "1.6.1"),
        index("rake",     "0.8.7"),
        index("rake",     "0.8.6"),
      ]
      [200, {"Content-Type" => "application/octet-stream"}, compress(big_index)]
    elsif request.path =~ /\/quick\/Marshal\.4\.8\/(.*\.gem)spec\.rz$/
      spec  = Gem::Format.from_file_by_path(fixtures($1).to_s).spec
      value = Gem.deflate(Marshal.dump(spec))

      [200, {"Content-Type" => "application/octet-stream"}, value]
    elsif request.path =~ /\/gems\/(.*\.gem)$/
      [200, {"Content-Type" => "application/octet-stream"}, File.read(fixtures($1))]
    else
      [200, {"Content-Type" => "text/plain"}, "fake gem server"]
    end
  end

  def compress(index)
    compressed = StringIO.new
    gzip = Zlib::GzipWriter.new(compressed)
    gzip.write(Marshal.dump(index))
    gzip.close
    compressed.string
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spade-0.0.1 spec/support/fake_gem_server.rb