Sha256: 125a226567960b937a0281eacc6e5e2fcd4ef139320adc0b4be1f3f85221850b

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
require 'cucumber/wire_support/wire_language'

module Cucumber
  module WireSupport
    describe Connection do
      class TestConnection < Connection
        attr_accessor :socket
      end

      class TestConfiguration
        attr_reader :custom_timeout

        def initialize
          @custom_timeout = {}
        end

        def timeout(message = nil)
          return :default_timeout if message.nil?
          @custom_timeout[message] || Configuration::DEFAULT_TIMEOUTS.fetch(message)
        end

        def host
          'localhost'
        end

        def port
          '3902'
        end
      end

      before(:each) do
        @config = TestConfiguration.new
        @connection = TestConnection.new(@config)
        @connection.socket = @socket = mock('socket').as_null_object
        @response = %q{["response"]}
      end

      it "re-raises a timeout error" do
        Timeout.stub!(:timeout).and_raise(Timeout::Error.new(''))
        lambda { @connection.call_remote(nil, :foo, []) }.should raise_error(Timeout::Error)
      end

      it "ignores timeout errors when configured to do so" do
        @config.custom_timeout[:foo] = :never
        @socket.stub(:gets => @response)
        handler = mock(:handle_response => :response)
        @connection.call_remote(handler, :foo, []).should == :response
      end

      it "raises an exception on remote connection closed" do
        @config.custom_timeout[:foo] = :never
        @socket.stub(:gets => nil)
        lambda { 
          @connection.call_remote(nil, :foo, []) 
        }.should raise_error(WireException, 'Remote Socket with localhost:3902 closed.')
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cucumber-1.3.2 spec/cucumber/wire_support/connection_spec.rb
cucumber-1.3.1 spec/cucumber/wire_support/connection_spec.rb
cucumber-1.3.0 spec/cucumber/wire_support/connection_spec.rb
cucumber-1.2.5 spec/cucumber/wire_support/connection_spec.rb
cucumber-1.2.3 spec/cucumber/wire_support/connection_spec.rb
cucumber-1.2.2 spec/cucumber/wire_support/connection_spec.rb