-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`rpop` accepts an optional `count` argument to indicate how many elements should be removed and returned from the list See https://github.com/redis/redis-rb/blob/9938411bd44383b795e05df900abce4df66daaef/lib/redis/commands/lists.rb#L114 Also had to change the shared examples a little bit to be able to pass the arguments they use and make a more accurate expectation on the error. I think the `args_for_method` is making an assumption when the `arity < 0` and always using `[1, 2]` (+ the key), but that doesn't work in all cases. In particular, `rpop` now has `arity` `-2` (because it has 1 required arg + 1 optional) so calling `rpop(key, 1, 2)` was causing an argument error instead of `Redis::CommandError` (which we expect because of the redis value not being a list). At first I tried to change `args_for_method` but it made other tests fail. And i suspect it won't be possible to have a generic args generator only based on arity (because some methods for example accept `*args` but the logic requires 1 or 2 args) That's why i thought it might be a good idea for each test that includes the shared example to indicate what the correct args to make a valid call should be, but let me know what you think!
- Loading branch information
1 parent
3cd9501
commit 9df4b4f
Showing
4 changed files
with
58 additions
and
17 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
14 changes: 8 additions & 6 deletions
14
spec/support/shared_examples/does_not_cleanup_empty_strings.rb
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
RSpec.shared_examples_for 'does not remove empty strings on error' do | ||
it 'does not remove empty strings on error' do |example| | ||
key = 'mock-redis-test:not-a-string' | ||
let(:method) { |example| method_from_description(example) } | ||
let(:args) { args_for_method(method) } | ||
let(:error) { defined?(default_error) ? default_error : RuntimeError } | ||
|
||
method = method_from_description(example) | ||
args = args_for_method(method).unshift(key) | ||
it 'does not remove empty strings on error' do | ||
key = 'mock-redis-test:not-a-string' | ||
key_and_args = args.unshift(key) | ||
|
||
@redises.set(key, '') | ||
expect do | ||
@redises.send(method, *args) | ||
end.to raise_error(defined?(default_error) ? default_error : RuntimeError) | ||
@redises.send(method, *key_and_args) | ||
end.to raise_error(*error) | ||
expect(@redises.get(key)).to eq('') | ||
end | ||
end |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
RSpec.shared_examples_for 'a list-only command' do | ||
it 'raises an error for non-list values' do |example| | ||
key = 'mock-redis-test:list-only' | ||
let(:method) { |example| method_from_description(example) } | ||
let(:args) { args_for_method(method) } | ||
let(:error) { defined?(default_error) ? default_error : RuntimeError } | ||
|
||
method = method_from_description(example) | ||
args = args_for_method(method).unshift(key) | ||
it 'raises an error for non-list values' do | ||
key = 'mock-redis-test:list-only' | ||
key_and_args = args.unshift(key) | ||
|
||
@redises.set(key, 1) | ||
|
||
expect do | ||
@redises.send(method, *args) | ||
end.to raise_error(defined?(default_error) ? default_error : RuntimeError) | ||
@redises.send(method, *key_and_args) | ||
end.to raise_error(*error) | ||
end | ||
|
||
it_should_behave_like 'does not remove empty strings on error' | ||
include_examples 'does not remove empty strings on error' | ||
end |