diff --git a/lib/mock_redis/string_methods.rb b/lib/mock_redis/string_methods.rb index f6fb5a4..bb43f7f 100644 --- a/lib/mock_redis/string_methods.rb +++ b/lib/mock_redis/string_methods.rb @@ -212,8 +212,8 @@ def mapped_msetnx(hash) # Parameter list required to ensure the ArgumentError is returned correctly # rubocop:disable Metrics/ParameterLists - def set(key, value, ex: nil, px: nil, exat: nil, pxat: nil, nx: nil, xx: nil, keepttl: nil, - get: nil) + def set(key, value, _hash = nil, ex: nil, px: nil, exat: nil, pxat: nil, nx: nil, xx: nil, + keepttl: nil, get: nil) key = key.to_s retval = self.get(key) if get diff --git a/spec/commands/set_spec.rb b/spec/commands/set_spec.rb index b14000a..7196689 100644 --- a/spec/commands/set_spec.rb +++ b/spec/commands/set_spec.rb @@ -1,12 +1,26 @@ require 'spec_helper' -RSpec.describe '#set(key, value)' do +RSpec.describe '#set(key, value, _hash)' do let(:key) { 'mock-redis-test' } it "responds with 'OK'" do expect(@redises.set('mock-redis-test', 1)).to eq('OK') end + context 'when the positional argument _hash exists' do + it "responds with 'OK'" do + # Testing MockRedis.new.set instead of @redises.set + # because the latter doesn't align with Redis's set method. + # In mock_redis, set accepts a third positional argument, _hash, + # to accommodate the difference with redis-store's set method, + # which takes three positional arguments, unlike the standard Redis set. + # Reference: + # Redis: https://github.com/redis/redis-rb/blob/09acb9026ab2deaca4c851e0bcdb0ef9318b1ee0/lib/redis/commands/strings.rb#L83 + # Redis-store: https://github.com/redis-store/redis-store/blob/5c3fee1b8fba672eb2bd5bfaedb973b68d12b773/lib/redis/store/ttl.rb#L4 + expect(MockRedis.new.set('mock-redis-test', 1, { key: 'value' })).to eq('OK') + end + end + context 'options' do it 'raises an error for EX seconds = 0' do expect do