Sha256: 95b636dc0e59616a48058f0dc95189763b69d1238d39fd19178c5a82ad77cf58

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'
require 'protobuf/socket'

shared_examples "a Protobuf Connector" do
  subject{ described_class.new({}) }

  context "API" do
    # Check the API
    specify{ subject.respond_to?(:send_request, true).should be_true }
    specify{ subject.respond_to?(:post_init, true).should be_true }
    specify{ subject.respond_to?(:close_connection, true).should be_true }
    specify{ subject.respond_to?(:error?, true).should be_true }
  end
end

describe Protobuf::Rpc::Connectors::Socket do
  subject{ described_class.new({}) }

  it_behaves_like "a Protobuf Connector"

  specify{ described_class.include?(Protobuf::Rpc::Connectors::Common).should be_true }

  context "#read_response" do
    let(:data){ "New data" }

    it "fills the buffer with data from the socket" do
      socket = StringIO.new("#{data.bytesize}-#{data}")
      subject.instance_variable_set(:@socket, socket)
      subject.instance_variable_set(:@stats, OpenStruct.new)
      subject.should_receive(:parse_response).and_return(true)

      subject.__send__(:read_response)
      subject.instance_variable_get(:@response_data).should eq(data)
    end
  end

  context "#check_async" do
    it "raises an error when trying to execute asynchronously" do
      conn = described_class.new(:async => true)
      expect{ conn.__send__(:check_async) }.to raise_error
    end

    it "allows execution when synchronous" do
      conn = described_class.new(:async => false)
      expect{ conn.__send__(:check_async) }.to_not raise_error
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
protobuf-2.0.0.rc3 spec/lib/protobuf/rpc/connectors/socket_spec.rb
protobuf-2.0.0.rc2 spec/lib/protobuf/rpc/connectors/socket_spec.rb
protobuf-2.0.0.rc1 spec/lib/protobuf/rpc/connectors/socket_spec.rb