Sha256: 4d4da70c480a12c2fe8fdd1413ae550b967c2e20ae7bfd815944fd2d69c1a7d3

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

class RFlow
  module Components
    module HTTP
      describe Server do
        let(:conn) { Server::Connection.new('a') }

        it "should return a default HTTP response" do
          expect(conn).to receive(:send_data).with("HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n")
          expect(conn).to receive(:send_data).with('')
          allow(conn).to receive(:close_connection)

          conn.send_http_response(Message.new("RFlow::Message::Data::HTTP::Response"))
        end

        it "should use proper status reason phrases" do
          expect(conn).to receive(:send_data).with("HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n")
          expect(conn).to receive(:send_data).with('')
          allow(conn).to receive(:close_connection)

          conn.send_http_response(Message.new("RFlow::Message::Data::HTTP::Response").tap {|r| r.data.status_code = 404 })
        end

        it "should return a fully configured HTTP response" do
          m = Message.new("RFlow::Message::Data::HTTP::Response").tap do |m|
            m.data.status_code = 1337
            m.data.status_reason_phrase = "JUST BECAUSE" # ignored as status phrases are overwritten
            m.data.headers['Boom'] = 'Town'
            m.data.content = 'boom'
          end

          expected_body = "boom"

          expect(conn).to receive(:send_data).with("HTTP/1.1 1337\r\nBoom: Town\r\nContent-Length: 4\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n")
          expect(conn).to receive(:send_data).with('boom')
          allow(conn).to receive(:close_connection)

          conn.send_http_response(m)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rflow-components-http-2.0.0 spec/rflow/components/http/server_spec.rb
rflow-components-http-1.1.1 spec/rflow/components/http/server_spec.rb
rflow-components-http-1.1.0 spec/rflow/components/http/server_spec.rb
rflow-components-http-1.0.1 spec/rflow/components/http/server_spec.rb
rflow-components-http-1.0.0 spec/rflow/components/http/server_spec.rb
rflow-components-http-1.0.0a4 spec/rflow/components/http/server_spec.rb