diff --git a/lib/mock_redis.rb b/lib/mock_redis.rb index 0d9c10d..d747d9b 100644 --- a/lib/mock_redis.rb +++ b/lib/mock_redis.rb @@ -49,10 +49,6 @@ def id end alias location id - def call(command, &_block) - send(*command) - end - def host options[:host] end diff --git a/lib/mock_redis/database.rb b/lib/mock_redis/database.rb index 4691313..fd65bdc 100644 --- a/lib/mock_redis/database.rb +++ b/lib/mock_redis/database.rb @@ -43,6 +43,10 @@ def initialize_copy(_source) # Redis commands go below this line and above 'private' + def call(command, &_block) + public_send(*command) + end + def auth(_) 'OK' end diff --git a/spec/commands/pipelined_spec.rb b/spec/commands/pipelined_spec.rb index 1e0e2cb..224d136 100644 --- a/spec/commands/pipelined_spec.rb +++ b/spec/commands/pipelined_spec.rb @@ -111,4 +111,26 @@ expect(results).to eq([value1, value2]) end end + + context 'with `call` method' do + let(:key1) { 'hello' } + let(:key2) { 'world' } + let(:value1) { 'foo' } + let(:value2) { 'bar' } + + before do + @redises.set key1, value1 + @redises.set key2, value2 + end + + it 'returns results of pipelined operations' do + results = @redises.pipelined do |redis| + redis.call(['get', key1]) + redis.call(['set', key2, 'foobar']) + redis.call(['get', key2]) + end + + expect(results).to eq([value1, 'OK', 'foobar']) + end + end end