Sha256: b6f20ab5b58fb43a1a94ea6966f0467a203220e94b103f73883516c8009c7a68

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'
require 'grocer/ssl_server'

describe Grocer::SSLServer do
  subject { described_class.new(options) }
  let(:options) { { port: 12345 } }
  let(:mock_server) { stub_everything }
  let(:mock_ssl_server) { stub_everything }
  let(:mock_client) { stub_everything }

  before do
    TCPServer.stubs(:new).returns(mock_server)
    OpenSSL::SSL::SSLServer.stubs(:new).returns(mock_ssl_server)

    mock_ssl_server.stubs(:accept).returns(mock_client).then.returns(nil)
  end

  it "is constructed with a port option" do
    subject.port.should == 12345
  end


  describe "#accept" do
    it "accepts client connections, yielding the client socket" do
      clients = []
      subject.accept { |c| clients << c }

      clients.should == [mock_client]
    end
  end

  describe "#close" do
    it "shutdowns the SSL socket" do
      mock_ssl_server.expects(:shutdown)

      # Emulate opening the socket
      subject.accept
      mock_ssl_server.stubs(:closed? => false)

      subject.close
    end

    it "ignores Errno::ENOTCONN errors that might be raised when shutting down the socket" do
      mock_ssl_server.stubs(:shutdown).raises(Errno::ENOTCONN)

      # Emulate opening the socket
      subject.accept
      mock_ssl_server.stubs(:closed? => false)

      subject.close
    end

    it "closes the SSL socket" do
      mock_ssl_server.expects(:close)

      # Emulate opening the socket
      subject.accept
      mock_ssl_server.stubs(:closed? => false)

      subject.close
    end

    it "is a no-op if the server has not been started" do
      mock_server.expects(:close).never
      mock_ssl_server.expects(:close).never

      subject.close
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grocer-0.2.0 spec/grocer/ssl_server_spec.rb
grocer-0.1.1 spec/grocer/ssl_server_spec.rb
grocer-0.1.0 spec/grocer/ssl_server_spec.rb
grocer-0.0.13 spec/grocer/ssl_server_spec.rb