Sha256: 8fadcc90d2659e0422ee658e2c6000e19400ffb6f5011f3ad2106650cd24996e

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

require 'lite_spec_helper'

describe Mongo::Timeout do
  describe '#timeout' do
    let(:default_error_message) { 'execution expired' }
    let(:custom_error_class) { Mongo::Error::SocketTimeoutError }
    let(:custom_error_message) { 'socket timed out' }

    context 'with time argument' do
      it 'raises StandardError' do
        expect do
          Mongo::Timeout.timeout(0.1) do
            sleep 1
          end
        end.to raise_error(::Timeout::Error, default_error_message)
      end
    end

    context 'with time and class arguments' do
      it 'raises the specified error class' do
        expect do
          Mongo::Timeout.timeout(0.1, custom_error_class) do
            sleep 1
          end
        end.to raise_error(custom_error_class, default_error_message)
      end
    end

    context 'with time, class, and message arguments' do
      it 'raises the specified error class with message' do
        expect do
          Mongo::Timeout.timeout(0.1, custom_error_class, custom_error_message) do
            sleep 1
          end
        end.to raise_error(custom_error_class, custom_error_message)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongo-2.13.3 spec/mongo/timeout_spec.rb
mongo-2.14.1 spec/mongo/timeout_spec.rb
mongo-2.15.0.alpha spec/mongo/timeout_spec.rb
mongo-2.13.2 spec/mongo/timeout_spec.rb
mongo-2.14.0 spec/mongo/timeout_spec.rb
mongo-2.14.0.rc1 spec/mongo/timeout_spec.rb
mongo-2.13.1 spec/mongo/timeout_spec.rb
mongo-2.13.0 spec/mongo/timeout_spec.rb
mongo-2.13.0.rc1 spec/mongo/timeout_spec.rb
mongo-2.13.0.beta1 spec/mongo/timeout_spec.rb