1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
require 'spec_helper'
module FakeRedis
describe "#sort" do
before(:each) do
@client = Redis.new
@client.set('fake-redis-test:values_1', 'a')
@client.set('fake-redis-test:values_2', 'b')
@client.set('fake-redis-test:weight_1', '2')
@client.set('fake-redis-test:weight_2', '1')
@client.hset('fake-redis-test:hash_1', 'key', 'x')
@client.hset('fake-redis-test:hash_2', 'key', 'y')
end
context "WRONGTYPE Operation" do
it "should not allow #sort on Strings" do
@client.set("key1", "Hello")
expect {
@client.sort("key1")
}.to raise_error(Redis::CommandError)
end
it "should not allow #sort on Hashes" do
@client.hset("key1", "k1", "val1")
@client.hset("key1", "k2", "val2")
expect {
@client.sort("key1")
}.to raise_error(Redis::CommandError)
end
end
context "none" do
it "should return empty array" do
expect(@client.sort("key")).to eq []
end
end
context "list" do
before do
@key = "fake-redis-test:list_sort"
@client.rpush(@key, '1')
@client.rpush(@key, '2')
end
it_should_behave_like "a sortable"
end
context "set" do
before do
@key = "fake-redis-test:set_sort"
@client.sadd(@key, '1')
@client.sadd(@key, '2')
end
it_should_behave_like "a sortable"
end
context "zset" do
before do
@key = "fake-redis-test:zset_sort"
@client.zadd(@key, 100, '1')
@client.zadd(@key, 99, '2')
end
it_should_behave_like "a sortable"
end
end
end
|