Sha256: 4d6cb5b991f9fb53363e6bd1dc8f9301c5e41daae857ade7d2d43238f8366a97
Contents?: true
Size: 1.52 KB
Versions: 17
Compression:
Stored size: 1.52 KB
Contents
require 'spec_helper' describe '#srandmember(key)' do before do @key = 'mock-redis-test:srandmember' @redises.sadd(@key, 'value') end it 'returns a member of the set' do @redises.srandmember(@key).should == 'value' end it 'does not modify the set' do @redises.srandmember(@key) @redises.smembers(@key).should == ['value'] end it 'returns nil if the set is empty' do @redises.spop(@key) @redises.srandmember(@key).should be_nil end context 'when count argument is specified' do before do @redises.sadd(@key, 'value2') @redises.sadd(@key, 'value3') end # NOTE: We disable result checking since MockRedis and Redis will likely # return a different random set (since the selection is, well, random) it 'returns the whole set if count is greater than the set size' do @redises.send_without_checking(:srandmember, @key, 5).should =~ %w[value value2 value3] end it 'returns random members up to count from the set when count is smaller than the set size' do @redises.send_without_checking(:srandmember, @key, 2).size.should == 2 end it 'returns random members up to count from the set when count is negative even if count.abs is greater than the set size' do # rubocop:disable Metrics/LineLength @redises.send_without_checking(:srandmember, @key, -5).size.should == 5 end it 'returns nil if the set is empty' do @redises.srem(@key, %w[value value2 value3]) @redises.srandmember(@key, 2).should be_empty end end end
Version data entries
17 entries across 17 versions & 1 rubygems