Sha256: eecd77b46e1a32e3a66f214d84bb3fe1b014417b5238f0eabc5d6da1790463e0

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'
require 'net/http'

describe Reel::Server 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
        request.method.should eq 'GET'
        request.version.should eq "1.1"
        request.url.should eq example_path

        connection.respond :ok, response_body
      rescue => ex
      end
    end

    with_reel(handler) do
      response = Net::HTTP.get endpoint
      response.should 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
        request.method.should eq 'POST'
        connection.respond :ok, request.body.to_s
      rescue => ex
      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)
      response.should be_a Net::HTTPOK
      response.body.should == response_body
    end

    raise ex if ex
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reel-0.4.0 spec/reel/server_spec.rb
reel-0.4.0.pre7 spec/reel/server_spec.rb
reel-0.4.0.pre6 spec/reel/server_spec.rb
reel-0.4.0.pre5 spec/reel/server_spec.rb
reel-0.4.0.pre4 spec/reel/server_spec.rb
reel-0.4.0.pre3 spec/reel/server_spec.rb
reel-0.4.0.pre2 spec/reel/server_spec.rb