Sha256: 5c3769d35cbdabfc292cbbc548bde183b252ace934cc2a0eb51b62c19fc01f39

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Hatetepe::Support::Message do
  let(:body) { double('body') }
  before { allow(Hatetepe::Body).to receive(:new) { body } }

  describe '.build', 'given a parser holding a request' do
    let(:parser) do
      Struct.new(:http_method, :request_url, :headers, :http_version)
        .new('GET', '/', { 'Key' => 'value' }, [1, 1])
    end
    let(:args) { [:get, '/', { 'Key' => 'value' }, body] }
    let(:request) { double }

    subject { Hatetepe::Support::Message.build(parser) }

    it 'returns a Request object' do
      expect(Hatetepe::Request)
        .to receive(:new).with(*args).and_return(request)
      expect(request).to receive(:http_version=).with(1.1)
      expect(subject).to be(request)
    end
  end

  describe '.build', 'given a parser holding a response' do
    let(:parser) do
      Struct.new(:http_method, :status_code, :headers, :http_version)
        .new(nil, 200, { 'Key' => 'value' }, [1, 0])
    end
    let(:args) { [200, { 'Key' => 'value' }, body] }
    let(:response) { double }

    subject { Hatetepe::Support::Message.build(parser) }

    it 'returns a Response object' do
      expect(Hatetepe::Response)
        .to receive(:new).with(*args).and_return(response)
      expect(response).to receive(:http_version=).with(1.0)
      expect(subject).to be(response)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hatetepe-0.6.0.pre.2 spec/unit/support/message_spec.rb
hatetepe-0.6.0.pre.1 spec/unit/support/message_spec.rb