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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'fast_spec_helper'
2018-12-05 23:21:45 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::NullRequestStore do
2018-12-05 23:21:45 +05:30
let(:null_store) { described_class.new }
describe '#store' do
it 'returns an empty hash' do
expect(null_store.store).to eq({})
end
end
describe '#active?' do
it 'returns falsey' do
expect(null_store.active?).to be_falsey
end
end
describe '#read' do
it 'returns nil' do
expect(null_store.read('foo')).to be nil
end
end
describe '#[]' do
it 'returns nil' do
expect(null_store['foo']).to be nil
end
end
describe '#write' do
it 'returns the same value' do
expect(null_store.write('key', 'value')).to eq('value')
end
end
describe '#[]=' do
it 'returns the same value' do
expect(null_store['key'] = 'value').to eq('value')
end
end
describe '#exist?' do
it 'returns falsey' do
expect(null_store.exist?('foo')).to be_falsey
end
end
describe '#fetch' do
it 'returns the block result' do
2022-05-07 20:08:51 +05:30
expect(null_store.fetch('key') { 'block result' }).to eq('block result') # rubocop:disable Style/RedundantFetchBlock
2018-12-05 23:21:45 +05:30
end
end
describe '#delete' do
context 'when a block is given' do
it 'yields the key to the block' do
expect do |b|
null_store.delete('foo', &b)
end.to yield_with_args('foo')
end
it 'returns the block result' do
expect(null_store.delete('foo') { |key| 'block result' }).to eq('block result')
end
end
context 'when a block is not given' do
it 'returns nil' do
expect(null_store.delete('foo')).to be nil
end
end
end
end