debian-mirror-gitlab/spec/lib/gitlab/loop_helpers_spec.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2019-03-02 22:35:43 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::LoopHelpers do
2019-03-02 22:35:43 +05:30
let(:class_instance) { (Class.new { include ::Gitlab::LoopHelpers }).new }
describe '#loop_until' do
subject do
class_instance.loop_until(**params) { true }
end
context 'when limit is not given' do
let(:params) { { limit: nil } }
it 'raises an error' do
expect { subject }.to raise_error(ArgumentError)
end
end
context 'when timeout is specified' do
let(:params) { { timeout: 1.second } }
it "returns false after it's expired" do
is_expected.to be_falsy
end
it 'executes the block at least once' do
expect { |b| class_instance.loop_until(**params, &b) }
.to yield_control.at_least(1)
end
end
context 'when iteration limit is specified' do
let(:params) { { limit: 1 } }
it "returns false after it's expired" do
is_expected.to be_falsy
end
it 'executes the block once' do
expect { |b| class_instance.loop_until(**params, &b) }
.to yield_control.once
end
end
end
end