Sha256: 42a42591a7fcb54380112ad5b3d560be09b08db78bb00e35c26890e96ffaac45

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

require 'timeout'
require 'cucumber/wire_support/wire_protocol'

module Cucumber
  module WireSupport
    class Connection
      include WireProtocol
      
      def initialize(config)
        @host, @port = config['host'], config['port']
      end
      
      def call_remote(response_handler, message, params)
        timeout = 3
        packet = WirePacket.new(message, params)

        begin
          send_data_to_socket(packet.to_json, timeout)
          response = fetch_data_from_socket(timeout)
          response.handle_with(response_handler)
        rescue Timeout::Error
          raise "Timed out calling server with message #{message}"
        end
      end

      private
      
      def send_data_to_socket(data, timeout)
        Timeout.timeout(timeout) { socket.puts(data) }
      end

      def fetch_data_from_socket(timeout)
        raw_response = Timeout.timeout(timeout) { socket.gets }
        WirePacket.parse(raw_response)
      end

      def socket
        @socket ||= TCPSocket.new(@host, @port)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
cucumber-0.4.5.rc2 lib/cucumber/wire_support/connection.rb
kbaum-cucumber-0.4.5.pre lib/cucumber/wire_support/connection.rb
cucumber-0.4.5.rc1 lib/cucumber/wire_support/connection.rb
middleman-0.10.17 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/wire_support/connection.rb
middleman-0.10.16 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/wire_support/connection.rb
middleman-0.10.15 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/wire_support/connection.rb
rackjour-0.1.8 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/wire_support/connection.rb
middleman-0.10.14 vendor/gems/gems/cucumber-0.4.4/lib/cucumber/wire_support/connection.rb
cucumber-0.4.4 lib/cucumber/wire_support/connection.rb
cucumber-0.4.3 lib/cucumber/wire_support/connection.rb