Sha256: 618757c392c206a572601fe8faaa6e74614e6c93717b2109ed4d2e330e60668b

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 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 2 3 4 5 6 7 8]
  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 "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

6 entries across 6 versions & 1 rubygems

Version Path
mock_redis-0.2.0 spec/commands/sunionstore_spec.rb
mock_redis-0.1.2 spec/commands/sunionstore_spec.rb
mock_redis-0.1.1 spec/commands/sunionstore_spec.rb
mock_redis-0.1.0 spec/commands/sunionstore_spec.rb
mock_redis-0.0.2 spec/commands/sunionstore_spec.rb
mock_redis-0.0.1 spec/commands/sunionstore_spec.rb