Sha256: 664a339afcef77392d01dcca7c6be9ccf21d2f859796a3c0aed8d25cee3f0d28

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

RSpec.describe HTTP::Response::Parser do
  subject(:parser) { described_class.new }
  let(:raw_response) do
    "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMyHeader: val\r\nEmptyHeader: \r\n\r\n{}"
  end
  let(:expected_headers) do
    {
      "Content-Length" => "2",
      "Content-Type"   => "application/json",
      "MyHeader"       => "val",
      "EmptyHeader"    => ""
    }
  end
  let(:expected_body) { "{}" }

  before do
    parts.each { |part| subject.add(part) }
  end

  context "whole response in one part" do
    let(:parts) { [raw_response] }

    it "parses headers" do
      expect(subject.headers.to_h).to eq(expected_headers)
    end

    it "parses body" do
      expect(subject.read(expected_body.size)).to eq(expected_body)
    end
  end

  context "response in many parts" do
    let(:parts) { raw_response.split(//) }

    it "parses headers" do
      expect(subject.headers.to_h).to eq(expected_headers)
    end

    it "parses body" do
      expect(subject.read(expected_body.size)).to eq(expected_body)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
http-5.0.0.pre2 spec/lib/http/response/parser_spec.rb