Sha256: 82b8e5b97fb108349399e4444eca26c629b94ff39edd2dfa6c1208b08e230477

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'
require 'net/http'

RSpec.describe Reel::Server::HTTP do
  let(:endpoint) { URI(example_url) }
  let(:response_body) { "ohai thar" }

  it "receives HTTP requests and sends responses" do
    ex = nil

    handler = proc do |connection|
      begin
        request = connection.request
        expect(request.method).to eq 'GET'
        expect(request.version).to eq "1.1"
        expect(request.url).to eq example_path
        connection.respond :ok, response_body
      end
    end

    with_reel(handler) do
      response = Net::HTTP.get endpoint
      expect(response).to eq response_body
    end

    raise ex if ex
  end

  it "echoes request bodies as response bodies" do
    ex = nil

    handler = proc do |connection|
      begin
        request = connection.request
        expect(request.method).to eq 'POST'
        connection.respond :ok, request.body.to_s
      end
    end

    with_reel(handler) do
      http = Net::HTTP.new(endpoint.host, endpoint.port)
      request = Net::HTTP::Post.new(endpoint.request_uri)
      request['connection'] = 'close'
      request.body = response_body
      response = http.request(request)
      expect(response).to be_a Net::HTTPOK
      expect(response.body).to eq(response_body)
    end

    raise ex if ex
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reel-0.6.0.pre5 spec/reel/http_server_spec.rb
reel-0.6.0.pre4 spec/reel/http_server_spec.rb
reel-0.6.0.pre3 spec/reel/http_server_spec.rb
reel-0.6.0.pre2 spec/reel/http_server_spec.rb
reel-0.6.0.pre1 spec/reel/http_server_spec.rb