Sha256: 60faad9c9c643bbeb7733370799963bba9f3df51e3f96119ebae10f85a1eeaa2

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe Goliath::Connection do
  before(:each) do
    @c = Goliath::Connection.new('blah')
  end

  describe 'configuration' do
    it 'accepts an app' do
      app = double('app')
      @c.app = app
      expect(@c.app).to eq(app)
    end

    it 'accepts a logger' do
      logger = double('logger')
      @c.logger = logger
      expect(@c.logger).to eq(logger)
    end

    it 'accepts a status object' do
      status = double('status')
      @c.status = status
      expect(@c.status).to eq(status)
    end

    it 'accepts config' do
      config = double('config')
      @c.config = config
      expect(@c.config).to eq(config)
    end
  end

  describe 'post_init' do
    it 'sets up the parser' do
      @c.post_init
      expect(@c.instance_variable_get("@parser")).not_to be_nil
    end
  end

  describe 'receive_data' do
    it 'passes data to the http parser' do
      request_mock = double("parser").as_null_object
      expect(request_mock).to receive(:<<)

      current_mock = double("current").as_null_object

      @c.instance_variable_set("@parser", request_mock)
      @c.instance_variable_set("@current", current_mock)
      @c.receive_data('more_data')
    end

    it "closes the connection when a parse error is received" do
      current_mock = double("current").as_null_object
      expect(current_mock).to receive(:close)

      @c.instance_variable_set("@current", current_mock)
      expect { @c.receive_data("bad data") }.not_to raise_error
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
goliath-1.0.7 spec/unit/connection_spec.rb
goliath-1.0.6 spec/unit/connection_spec.rb