2019-02-11 04:04:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-09-24 23:09:30 -04:00
|
|
|
RSpec.describe QA::Support::Waiter do
|
2019-02-11 04:04:59 -05:00
|
|
|
before do
|
|
|
|
logger = ::Logger.new $stdout
|
|
|
|
logger.level = ::Logger::DEBUG
|
|
|
|
QA::Runtime::Logger.logger = logger
|
|
|
|
end
|
|
|
|
|
2020-01-09 04:07:51 -05:00
|
|
|
describe '.wait_until' do
|
2019-02-11 04:04:59 -05:00
|
|
|
context 'when the condition is true' do
|
|
|
|
it 'logs the start' do
|
2020-01-09 04:07:51 -05:00
|
|
|
expect { subject.wait_until(max_duration: 0, raise_on_failure: false) { true } }
|
|
|
|
.to output(/with wait_until: max_duration: 0; reload_page: ; sleep_interval: 0.1/).to_stdout_from_any_process
|
2019-02-11 04:04:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs the end' do
|
2020-01-09 04:07:51 -05:00
|
|
|
expect { subject.wait_until(max_duration: 0, raise_on_failure: false) { true } }
|
|
|
|
.to output(/ended wait_until$/).to_stdout_from_any_process
|
2019-02-11 04:04:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the condition is false' do
|
|
|
|
it 'logs the start' do
|
2020-01-09 04:07:51 -05:00
|
|
|
expect { subject.wait_until(max_duration: 0, raise_on_failure: false) { false } }
|
|
|
|
.to output(/with wait_until: max_duration: 0; reload_page: ; sleep_interval: 0.1/).to_stdout_from_any_process
|
2019-02-11 04:04:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs the end' do
|
2020-01-09 04:07:51 -05:00
|
|
|
expect { subject.wait_until(max_duration: 0, raise_on_failure: false) { false } }
|
|
|
|
.to output(/ended wait_until$/).to_stdout_from_any_process
|
2019-02-11 04:04:59 -05:00
|
|
|
end
|
|
|
|
end
|
2020-01-09 04:07:51 -05:00
|
|
|
|
2020-02-14 13:08:45 -05:00
|
|
|
it 'allows logs to be silenced' do
|
|
|
|
expect { subject.wait_until(max_duration: 0, raise_on_failure: false, log: false) { false } }
|
|
|
|
.not_to output.to_stdout_from_any_process
|
|
|
|
end
|
|
|
|
|
2020-01-09 04:07:51 -05:00
|
|
|
it 'sets max_duration to 60 by default' do
|
|
|
|
expect(subject).to receive(:repeat_until).with(hash_including(max_duration: 60))
|
|
|
|
|
|
|
|
subject.wait_until
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets sleep_interval to 0.1 by default' do
|
|
|
|
expect(subject).to receive(:repeat_until).with(hash_including(sleep_interval: 0.1))
|
|
|
|
|
|
|
|
subject.wait_until
|
|
|
|
end
|
|
|
|
|
2020-01-24 16:09:09 -05:00
|
|
|
it 'sets raise_on_failure to true by default' do
|
|
|
|
expect(subject).to receive(:repeat_until).with(hash_including(raise_on_failure: true))
|
2020-01-09 04:07:51 -05:00
|
|
|
|
|
|
|
subject.wait_until
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets retry_on_exception to false by default' do
|
|
|
|
expect(subject).to receive(:repeat_until).with(hash_including(retry_on_exception: false))
|
|
|
|
|
|
|
|
subject.wait_until
|
|
|
|
end
|
2019-02-11 04:04:59 -05:00
|
|
|
end
|
|
|
|
end
|