Sha256: 92769658275a29d0339bc54f7c9031fe99f9b0279aec27eb3c7094018350cfbc

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

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

    (1..10).each { |i| @redises.sadd(@numbers, i) }
    [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 first set minus the second set' do
    @redises.sdiff(@numbers, @evens).should == %w[1 3 5 7 9]
  end

  it 'returns the first set minus all the other sets' do
    @redises.sdiff(@numbers, @evens, @primes).should == %w[1 9]
  end

  it 'treats missing keys as empty sets' do
    @redises.sdiff(@evens, 'mock-redis-test:nonesuch').should == %w[2 4 6 8 10]
  end

  it 'returns the first set when called with a single argument' do
    @redises.sdiff(@primes).should == %w[2 3 5 7]
  end

  it 'raises an error if given 0 arguments' do
    lambda do
      @redises.sdiff
    end.should raise_error(RuntimeError)
  end

  it 'raises an error if any argument is not a a set' do
    @redises.set('foo', 1)

    lambda do
      @redises.sdiff(@numbers, 'foo')
    end.should raise_error(RuntimeError)

    lambda do
      @redises.sdiff('foo', @numbers)
    end.should raise_error(RuntimeError)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mock_redis-0.15.0 spec/commands/sdiff_spec.rb