Sha256: 9c5939350d5219fd2b659c8479626af8b94642e6ca2ab772ad7c2479ce12b0e0

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

RSpec.describe PageMagic::WaitMethods do
  include described_class

  describe '#wait_until' do
    let(:default_options) { { timeout_after: 0.1, retry_every: 0.05 } }
    let!(:start_time) { Time.now }

    it 'waits until the prescribed thing has happened' do
      expect { wait_until(**default_options) { true } }.not_to raise_exception
    end

    it 'keeps trying for a specified period' do
      wait_until(**default_options) { false }
    rescue PageMagic::TimeoutException
      expect(Time.now - default_options[:timeout_after]).to be > start_time
    end

    context 'when `timeout_after` specified' do
      it 'throws an exception if when the prescribed action does not happen in time' do
        expect { wait_until(**default_options) { false } }.to raise_error PageMagic::TimeoutException
      end
    end

    context 'when retry time specified' do
      it 'retries at the given interval' do
        count = 0
        expect { wait_until(timeout_after: 0.2, retry_every: 0.1) { count += 1 } }
          .to raise_exception(PageMagic::TimeoutException)
          .and change { count }.by(2)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
page_magic-2.0.6 spec/page_magic/wait_methods_spec.rb
page_magic-2.0.5 spec/page_magic/wait_methods_spec.rb
page_magic-2.0.4 spec/page_magic/wait_methods_spec.rb
page_magic-2.0.3 spec/page_magic/wait_methods_spec.rb
page_magic-2.0.2 spec/page_magic/wait_methods_spec.rb
page_magic-2.0.1 spec/page_magic/wait_methods_spec.rb
page_magic-2.0.0 spec/page_magic/wait_methods_spec.rb