Sha256: 37c410dd77687817cf183ade00059851f877e195bf4d5a587e60b35cad2a4448

Contents?: true

Size: 1014 Bytes

Versions: 4

Compression:

Stored size: 1014 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'whois/server/socket_handler'

describe Whois::Server::SocketHandler do
  describe "#call" do
    [Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE, SocketError].each do |error|
      it "re-raises #{error} as Whois::ConnectionError" do
        expect(subject).to receive(:execute).and_raise(error)
        expect {
          subject.call("example.test", "whois.test", 43)
        }.to raise_error(Whois::ConnectionError, "#{error}: #{error.new.message}")
      end

      it "executes a socket connection for given args" do
        socket = instance_double(TCPSocket)
        expect(socket).to receive(:write).with("example.test\r\n")
        expect(socket).to receive(:read)
        expect(socket).to receive(:close)

        expect(TCPSocket).to receive(:new)
          .with("whois.test", 43)
          .and_return(socket)
        subject.call("example.test", "whois.test", 43)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
whois-6.0.0 spec/whois/server/socket_handler_spec.rb
whois-5.1.1 spec/whois/server/socket_handler_spec.rb
whois-5.1.0 spec/whois/server/socket_handler_spec.rb
whois-5.0.2 spec/whois/server/socket_handler_spec.rb