spec/unit/wait_spec.rb in watir-7.2.0 vs spec/unit/wait_spec.rb in watir-7.2.1
- old
+ new
@@ -1,95 +1,99 @@
# frozen_string_literal: true
require_relative 'unit_helper'
-describe Watir::Wait do
- describe '#until' do
- it 'waits until the block returns true' do
- Watir::Wait.until(timeout: 0.5) { @result = true }
- expect(@result).to be true
- end
+module Watir
+ describe Wait do
+ describe '#until' do
+ it 'waits until the block returns true' do
+ described_class.until(timeout: 0.5) { @result = true }
+ expect(@result).to be true
+ end
- it 'executes block if timeout is zero' do
- Watir::Wait.until(timeout: 0) { @result = true }
- expect(@result).to be true
- end
+ it 'executes block if timeout is zero' do
+ described_class.until(timeout: 0) { @result = true }
+ expect(@result).to be true
+ end
- it 'times out' do
- expect { Watir::Wait.until(timeout: 0.5) { false } }.to raise_error(Watir::Wait::TimeoutError)
- end
+ it 'times out' do
+ expect { described_class.until(timeout: 0.5) { false } }.to raise_error(Watir::Wait::TimeoutError)
+ end
- it 'times out with a custom message' do
- expect {
- Watir::Wait.until(timeout: 0.5, message: 'oops') { false }
- }.to raise_error(Watir::Wait::TimeoutError, 'timed out after 0.5 seconds, oops')
- end
+ it 'times out with a custom message' do
+ expect {
+ described_class.until(timeout: 0.5, message: 'oops') { false }
+ }.to raise_error(Watir::Wait::TimeoutError, 'timed out after 0.5 seconds, oops')
+ end
- it 'uses provided interval' do
- expect {
- Watir::Wait.until(timeout: 0.4, interval: 0.2) do
- @result = @result.nil? ? 1 : @result + 1
- false
- end
- }.to raise_timeout_exception
- expect(@result).to eq 2
- end
+ it 'uses provided interval' do
+ expect {
+ described_class.until(timeout: 0.4, interval: 0.2) do
+ @result = @result.nil? ? 1 : @result + 1
+ false
+ end
+ }.to raise_timeout_exception
+ expect(@result).to eq 2
+ end
- it 'uses timer for waiting' do
- timer = Watir::Wait.timer
- expect(timer).to receive(:wait).with(0.5).and_call_original
- Watir::Wait.until(timeout: 0.5) { true }
+ it 'uses timer for waiting' do
+ timer = described_class.timer
+ allow(timer).to receive(:wait).and_call_original
+ described_class.until(timeout: 0.5) { true }
+ expect(timer).to have_received(:wait).with(0.5)
+ end
end
- end
- describe '#while' do
- it 'waits while the block returns true' do
- expect(Watir::Wait.while(timeout: 0.5) { false }).to be_nil
- end
+ describe '#while' do
+ it 'waits while the block returns true' do
+ expect(described_class.while(timeout: 0.5) { false }).to be_nil
+ end
- it 'executes block if timeout is zero' do
- expect(Watir::Wait.while(timeout: 0) { false }).to be_nil
- end
+ it 'executes block if timeout is zero' do
+ expect(described_class.while(timeout: 0) { false }).to be_nil
+ end
- it 'times out' do
- expect { Watir::Wait.while(timeout: 0.5) { true } }.to raise_error(Watir::Wait::TimeoutError)
- end
+ it 'times out' do
+ expect { described_class.while(timeout: 0.5) { true } }.to raise_error(Watir::Wait::TimeoutError)
+ end
- it 'times out with a custom message' do
- expect {
- Watir::Wait.while(timeout: 0.5, message: 'oops') { true }
- }.to raise_error(Watir::Wait::TimeoutError, 'timed out after 0.5 seconds, oops')
- end
+ it 'times out with a custom message' do
+ expect {
+ described_class.while(timeout: 0.5, message: 'oops') { true }
+ }.to raise_error(Watir::Wait::TimeoutError, 'timed out after 0.5 seconds, oops')
+ end
- it 'uses provided interval' do
- expect {
- Watir::Wait.while(timeout: 0.4, interval: 0.2) do
- @result = @result.nil? ? 1 : @result + 1
- true
- end
- }.to raise_timeout_exception
- expect(@result).to eq 2
- end
+ it 'uses provided interval' do
+ expect {
+ described_class.while(timeout: 0.4, interval: 0.2) do
+ @result = @result.nil? ? 1 : @result + 1
+ true
+ end
+ }.to raise_timeout_exception
+ expect(@result).to eq 2
+ end
- it 'uses timer for waiting' do
- timer = Watir::Wait.timer
- expect(timer).to receive(:wait).with(0.5).and_call_original
- Watir::Wait.while(timeout: 0.5) { false }
+ it 'uses timer for waiting' do
+ timer = described_class.timer
+ allow(timer).to receive(:wait).and_call_original
+ described_class.while(timeout: 0.5) { false }
+ expect(timer).to have_received(:wait).with(0.5)
+ end
end
- end
- describe '#timer' do
- it 'returns default timer' do
- expect(Watir::Wait.timer).to be_a(Watir::Wait::Timer)
+ describe '#timer' do
+ it 'returns default timer' do
+ expect(described_class.timer).to be_a(Watir::Wait::Timer)
+ end
end
- end
- describe '#timer=' do
- after { Watir::Wait.timer = nil }
+ describe '#timer=' do
+ after { described_class.timer = nil }
- it 'changes default timer' do
- timer = Class.new
- Watir::Wait.timer = timer
- expect(Watir::Wait.timer).to eq(timer)
+ it 'changes default timer' do
+ timer = Class.new
+ described_class.timer = timer
+ expect(described_class.timer).to eq(timer)
+ end
end
end
end