Sha256: f3dda9a2705345880382bf35d3d2d0b6b440223f98aa31e204e2b2937b032400

Contents?: true

Size: 998 Bytes

Versions: 9

Compression:

Stored size: 998 Bytes

Contents

RSpec.shared_examples 'an operation that retries on exception' do |operation, exception_class|

  context 'less than three times' do

    it 'traps the exception' do
      tries = 0
      expect do
        subject.send(operation) do
          (tries += 1) < 3 ? (raise exception_class.new 'blah') : nil
        end
      end.to_not raise_error
    end
  end

  context 'three or more times' do

    it 'raises the exception' do
      tries = 0
      expect do
        subject.send(operation) do
          tries += 1
          raise exception_class.new 'blah'
        end
      end.to raise_error exception_class
      expect(tries).to eq 3
    end
  end
end

RSpec.shared_examples 'an operation that does not retry on exception' do |operation, exception_class|

  it 'does not retry when the error is received' do
      tries = 0
      expect do
        subject.send(operation) do
          (tries += 1) < 3 ? (raise exception_class.new 'blah') : nil
        end
      end.to raise_error
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rabbit_feed-2.1.5 spec/support/shared_examples_for_connections.rb
rabbit_feed-2.1.2 spec/support/shared_examples_for_connections.rb
rabbit_feed-2.1.1 spec/support/shared_examples_for_connections.rb
rabbit_feed-2.1.0 spec/support/shared_examples_for_connections.rb
rabbit_feed-2.0.0 spec/support/shared_examples_for_connections.rb
rabbit_feed-1.0.2 spec/support/shared_examples_for_connections.rb
rabbit_feed-1.0.1 spec/support/shared_examples_for_connections.rb
rabbit_feed-1.0.0 spec/support/shared_examples_for_connections.rb
rabbit_feed-0.3.1 spec/support/shared_examples_for_connections.rb