Skip to content

Commit

Permalink
Fix hmset exception and xadd spec errors (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Mar 2, 2021
1 parent 83f916a commit 1b3e9b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/mock_redis/hash_methods.rb
Expand Up @@ -94,7 +94,7 @@ def hmset(key, *kvpairs)
assert_has_args(kvpairs, 'hmset')

if kvpairs.length.odd?
raise Redis::CommandError, err_msg || 'ERR wrong number of arguments for HMSET'
raise Redis::CommandError, err_msg || 'ERR wrong number of arguments for \'hmset\' command'
end

kvpairs.each_slice(2) do |(k, v)|
Expand Down
12 changes: 6 additions & 6 deletions spec/commands/xadd_spec.rb
Expand Up @@ -14,20 +14,20 @@

it 'returns an id based on the timestamp' do
t = Time.now.to_i
id = @redises.xadd(@key, key: 'value')
expect(@redises.xadd(@key, key: 'value')).to match(/#{t}\d{3}-0/)
id = @redises.xadd(@key, { key: 'value' })
expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}\d{3}-0/)
end

it 'adds data with symbols' do
@redises.xadd(@key, symbol_key: :symbol_value)
@redises.xadd(@key, { symbol_key: :symbol_value })
expect(@redises.xrange(@key, '-', '+').last[1])
.to eq('symbol_key' => 'symbol_value')
end

it 'increments the sequence number with the same timestamp' do
Timecop.freeze do
@redises.xadd(@key, key: 'value')
expect(@redises.xadd(@key, key: 'value')).to match(/\d+-1/)
@redises.xadd(@key, { key: 'value' })
expect(@redises.xadd(@key, { key: 'value' })).to match(/\d+-1/)
end
end

Expand Down Expand Up @@ -67,7 +67,7 @@
it 'caters for the current time being before the last time' do
t = (Time.now.to_f * 1000).to_i + 2000
@redises.xadd(@key, { key: 'value' }, id: "#{t}-0")
expect(@redises.xadd(@key, key: 'value')).to match(/#{t}-1/)
expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}-1/)
end

it 'appends a sequence number if it is missing' do
Expand Down
4 changes: 2 additions & 2 deletions spec/commands/xlen_spec.rb
Expand Up @@ -14,9 +14,9 @@

it 'returns the number of items in the stream' do
expect(@redises.xlen(@key)).to eq 0
@redises.xadd(@key, key: 'value')
@redises.xadd(@key, { key: 'value' })
expect(@redises.xlen(@key)).to eq 1
3.times { @redises.xadd(@key, key: 'value') }
3.times { @redises.xadd(@key, { key: 'value' }) }
expect(@redises.xlen(@key)).to eq 4
end
end

0 comments on commit 1b3e9b1

Please sign in to comment.