-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69484fe
commit 7a2677f
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe '#lmpop(*keys)', redis: 7.0 do | ||
before do | ||
@list1 = 'mock-redis-test:lmpop-list' | ||
@list2 = 'mock-redis-test:lmpop-list2' | ||
|
||
@redises.lpush(@list1, 'c') | ||
@redises.lpush(@list1, 'b') | ||
@redises.lpush(@list1, 'a') | ||
|
||
@redises.lpush(@list2, 'z') | ||
@redises.lpush(@list2, 'y') | ||
@redises.lpush(@list2, 'x') | ||
end | ||
|
||
it 'returns and removes the first element of the first non-empty list' do | ||
expect(@redises.lmpop('empty', @list1, @list2)).to eq([@list1, ['a']]) | ||
|
||
expect(@redises.lrange(@list1, 0, -1)).to eq(%w[b c]) | ||
expect(@redises.lrange(@list2, 0, -1)).to eq(%w[x y z]) | ||
end | ||
|
||
it 'returns and removes the first element of the first non-empty list when modifier is LEFT' do | ||
expect(@redises.lmpop('empty', @list1, @list2, modifier: 'LEFT')).to eq([@list1, ['a']]) | ||
|
||
expect(@redises.lrange(@list1, 0, -1)).to eq(%w[b c]) | ||
expect(@redises.lrange(@list2, 0, -1)).to eq(%w[x y z]) | ||
end | ||
|
||
it 'returns and removes the last element of the first non-empty list when modifier is RIGHT' do | ||
expect(@redises.lmpop('empty', @list1, @list2, modifier: 'RIGHT')).to eq([@list1, ['c']]) | ||
|
||
expect(@redises.lrange(@list1, 0, -1)).to eq(%w[a b]) | ||
expect(@redises.lrange(@list2, 0, -1)).to eq(%w[x y z]) | ||
end | ||
|
||
it 'returns and removes multiple elements from the front when count is given' do | ||
expect(@redises.lmpop('empty', @list1, @list2, count: 2)).to eq([@list1, %w[a b]]) | ||
|
||
expect(@redises.lrange(@list1, 0, -1)).to eq(%w[c]) | ||
expect(@redises.lrange(@list2, 0, -1)).to eq(%w[x y z]) | ||
end | ||
|
||
it 'returns and removes multiple elements from the back when count given and modifier is RIGHT' do | ||
expect(@redises.lmpop('empty', @list1, @list2, count: 2, modifier: 'RIGHT')).to( | ||
eq([@list1, %w[c b]]) | ||
) | ||
|
||
expect(@redises.lrange(@list1, 0, -1)).to eq(%w[a]) | ||
expect(@redises.lrange(@list2, 0, -1)).to eq(%w[x y z]) | ||
end | ||
|
||
it 'returns falsed if all lists are empty' do | ||
expect(@redises.lmpop('empty')).to be_nil | ||
|
||
expect(@redises.lrange(@list1, 0, -1)).to eq(%w[a b c]) | ||
expect(@redises.lrange(@list2, 0, -1)).to eq(%w[x y z]) | ||
end | ||
|
||
it 'removes empty lists' do | ||
(@redises.llen(@list1) + @redises.llen(@list2)).times { @redises.lmpop(@list1, @list2) } | ||
expect(@redises.get(@list1)).to be_nil | ||
end | ||
|
||
it 'raises an error for non-list source value' do | ||
@redises.set(@list1, 'string value') | ||
|
||
expect do | ||
@redises.lmpop(@list1, @list2) | ||
end.to raise_error(Redis::CommandError) | ||
end | ||
|
||
it_should_behave_like 'a list-only command' | ||
end |