Sha256: 3376caa20977d3dc05e646d95abe3b7a396db30d0e57cbcaaac910a86213deb5

Contents?: true

Size: 1.8 KB

Versions: 27

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe '#sunionstore(destination, key [, key, ...])' do
  before do
    @evens       = 'mock-redis-test:sunionstore:evens'
    @primes      = 'mock-redis-test:sunionstore:primes'
    @destination = 'mock-redis-test:sunionstore:destination'

    [2, 4, 6, 8, 10].each {|i| @redises.sadd(@evens, i) }
    [2, 3, 5, 7].each {|i| @redises.sadd(@primes, i) }
  end

  it "returns the number of elements in the resulting set" do
    @redises.sunionstore(@destination, @primes, @evens).should == 8
  end

  it "stores the resulting set" do
    @redises.sunionstore(@destination, @primes, @evens)
    @redises.smembers(@destination).should == %w[10 8 6 4 7 5 3 2]
  end

  it "does not store empty sets" do
    @redises.sunionstore(@destination,
      'mock-redis-test:nonesuch',
      'mock-redis-test:nonesuch2').should == 0
    @redises.get(@destination).should be_nil
  end

  it "removes existing elements in destination" do
    @redises.sadd(@destination, 42)

    @redises.sunionstore(@destination, @primes)
    @redises.smembers(@destination).should == %w[7 5 3 2]
  end

  it "correctly unions and stores when the destination is empty and is one of the arguments" do
    @redises.sunionstore(@destination, @destination, @primes)

    @redises.smembers(@destination).should == %w[7 5 3 2]
  end

  it "raises an error if given 0 sets" do
    lambda do
      @redises.sunionstore(@destination)
    end.should raise_error(RuntimeError)
  end

  it "raises an error if any argument is not a a set" do
    @redises.set('mock-redis-test:notset', 1)

    lambda do
      @redises.sunionstore(@destination, @primes, 'mock-redis-test:notset')
    end.should raise_error(RuntimeError)

    lambda do
      @redises.sunionstore(@destination, 'mock-redis-test:notset', @primes)
    end.should raise_error(RuntimeError)
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
mock_redis-0.14.1 spec/commands/sunionstore_spec.rb
mock_redis-0.14.0 spec/commands/sunionstore_spec.rb
mock_redis-0.13.2 spec/commands/sunionstore_spec.rb
mock_redis-0.13.1 spec/commands/sunionstore_spec.rb
mock_redis-0.13.0 spec/commands/sunionstore_spec.rb
mock_redis-0.12.1 spec/commands/sunionstore_spec.rb
mock_redis-0.12.0 spec/commands/sunionstore_spec.rb
mock_redis-0.11.0 spec/commands/sunionstore_spec.rb
mock_redis-0.10.0 spec/commands/sunionstore_spec.rb
mock_redis-0.9.0 spec/commands/sunionstore_spec.rb
mock_redis-0.8.2 spec/commands/sunionstore_spec.rb
mock_redis-0.8.1 spec/commands/sunionstore_spec.rb
mock_redis-0.8.0 spec/commands/sunionstore_spec.rb
mock_redis-0.7.0 spec/commands/sunionstore_spec.rb
mock_redis-0.6.6 spec/commands/sunionstore_spec.rb
mock_redis-0.6.5 spec/commands/sunionstore_spec.rb
mock_redis-0.6.4 spec/commands/sunionstore_spec.rb
mock_redis-0.6.3 spec/commands/sunionstore_spec.rb
mock_redis-0.6.2 spec/commands/sunionstore_spec.rb
mock_redis-0.6.1 spec/commands/sunionstore_spec.rb