Sha256: 76c5de0164f98dd482f904ef4833b517302379eb5ab36a80f1928b1478afa2b7

Contents?: true

Size: 1.18 KB

Versions: 33

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

describe '#sadd(key, member)' do
  before { @key = 'mock-redis-test:sadd' }

  it 'returns true if the set did not already contain member' do
    @redises.sadd(@key, 1).should == true
  end

  it 'returns false if the set did already contain member' do
    @redises.sadd(@key, 1)
    @redises.sadd(@key, 1).should == false
  end

  it 'adds member to the set' do
    @redises.sadd(@key, 1)
    @redises.sadd(@key, 2)
    @redises.smembers(@key).should == %w[2 1]
  end

  describe 'adding multiple members at once' do
    it 'returns the amount of added members' do
      @redises.sadd(@key, [1, 2, 3]).should == 3
      @redises.sadd(@key, [1, 2, 3, 4]).should == 1
    end

    it 'returns 0 if the set did already contain all members' do
      @redises.sadd(@key, [1, 2, 3])
      @redises.sadd(@key, [1, 2, 3]).should == 0
    end

    it 'adds the members to the set' do
      @redises.sadd(@key, [1, 2, 3])
      @redises.smembers(@key).should == %w[1 2 3]
    end

    it 'raises an error if an empty array is given' do
      lambda do
        @redises.sadd(@key, [])
      end.should raise_error(Redis::CommandError)
    end
  end

  it_should_behave_like 'a set-only command'
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/sadd_spec.rb
mock_redis-0.35.0 spec/commands/sadd_spec.rb
mock_redis-0.34.0 spec/commands/sadd_spec.rb
mock_redis-0.33.0 spec/commands/sadd_spec.rb
mock_redis-0.32.0 spec/commands/sadd_spec.rb
mock_redis-0.31.0 spec/commands/sadd_spec.rb
mock_redis-0.30.0 spec/commands/sadd_spec.rb
mock_redis-0.29.0 spec/commands/sadd_spec.rb
mock_redis-0.28.0 spec/commands/sadd_spec.rb
mock_redis-0.27.3 spec/commands/sadd_spec.rb
mock_redis-0.27.2 spec/commands/sadd_spec.rb
mock_redis-0.27.1 spec/commands/sadd_spec.rb
mock_redis-0.27.0 spec/commands/sadd_spec.rb
mock_redis-0.26.0 spec/commands/sadd_spec.rb
mock_redis-0.25.0 spec/commands/sadd_spec.rb
mock_redis-0.24.0 spec/commands/sadd_spec.rb
mock_redis-0.23.0 spec/commands/sadd_spec.rb
mock_redis-0.22.0 spec/commands/sadd_spec.rb
mock_redis-0.21.0 spec/commands/sadd_spec.rb
mock_redis-0.20.0 spec/commands/sadd_spec.rb