]> git.saurik.com Git - redis.git/blob - client-libraries/scala/src/test/scala/com/redis/operations/KeySpaceOperationsSpec.scala
ced34fefa8262c746d95e77ff813c76f60c765de
[redis.git] / client-libraries / scala / src / test / scala / com / redis / operations / KeySpaceOperationsSpec.scala
1 import org.specs._
2 import com.redis._
3
4 import org.specs.mock.Mockito
5 import org.mockito.Mock._
6 import org.mockito.Mockito._
7 import org.mockito.Mockito.doNothing
8
9 object KeySpaceOperationsSpec extends Specification with Mockito {
10
11 "Redis Client Key Operations" should {
12 var client: RedisTestClient = null
13 var connection: Connection = null
14
15 doBefore{
16 connection = mock[Connection]
17 client = new RedisTestClient(connection)
18 }
19
20 "return all keys matching" in {
21 connection.readResponse returns "akey anotherkey adiffkey"
22 client.keys("a*")
23 connection.write("KEYS a*\r\n") was called
24 }
25
26 "return a random key" in {
27 connection.readResponse returns "+somerandonkey"
28 client.randomKey mustEqual "somerandonkey"
29 connection.write("RANDOMKEY\r\n") was called
30 }
31
32 "remame a key" in {
33 connection.readBoolean returns true
34 client.rename("a", "b") must beTrue
35 connection.write("RENAME a b\r\n") was called
36 }
37
38 "rename a key only if destintation doesn't exist" in {
39 connection.readBoolean returns false
40 client.renamenx("a", "b") must beFalse
41 connection.write("RENAMENX a b\r\n") was called
42 }
43
44 "tell the size of the db, # of keys" in {
45 connection.readInt returns 4
46 client.dbSize mustEqual 4
47 connection.write("DBSIZE\r\n") was called
48 }
49 }
50 }