fakeredis 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ #require 'spec_helper'
2
+
3
+ #module FakeRedis
4
+ #describe "SortedSetsMethods" do
5
+ #before(:each) do
6
+ #@client = FakeRedis::Redis.new
7
+ #end
8
+
9
+ #it "should add a member to a sorted set, or update its score if it already exists" do
10
+ #@client.zadd("key", 1, "val")
11
+
12
+ #@client.zcard("key").should == 1
13
+ #end
14
+
15
+ #it "should get the number of members in a sorted set" do
16
+ #@client.zadd("key", 1, "val2")
17
+ #@client.zadd("key", 2, "val1")
18
+ #@client.zadd("key", 5, "val3")
19
+
20
+ #@client.zcard("key").should == 3
21
+ #end
22
+
23
+ #it "should count the members in a sorted set with scores within the given values" do
24
+ #@client.zadd("key", 1, "val1")
25
+ #@client.zadd("key", 2, "val2")
26
+ #@client.zadd("key", 3, "val3")
27
+
28
+ #@client.zcount("key", 2, 3).should == 2
29
+ #end
30
+
31
+ #it "should increment the score of a member in a sorted set" do
32
+ #@client.zadd("key", 1, "val1")
33
+ #@client.zincrby("key", 2, "val1")
34
+
35
+ #@client.zscore("key", "val1").should == 3
36
+ #end
37
+
38
+ #it "should intersect multiple sorted sets and store the resulting sorted set in a new key"
39
+
40
+ #it "should return a range of members in a sorted set, by index" do
41
+ #@client.zadd("key", 1, "one")
42
+ #@client.zadd("key", 2, "two")
43
+ #@client.zadd("key", 3, "three")
44
+
45
+ #@client.zrange("key", 0, -1).should == ["one", "two", "three"]
46
+
47
+ #end
48
+
49
+ #it "should return a range of members in a sorted set, by score" do
50
+ #@client.zadd("key", 1, "one")
51
+ #@client.zadd("key", 2, "two")
52
+ #@client.zadd("key", 3, "three")
53
+
54
+ #@client.zrangescore("key", 0, -1).should == ["three", "two", "one"]
55
+ #end
56
+
57
+ #it "should determine the index of a member in a sorted set" do
58
+ #@client.zadd("key", 1, "one")
59
+ #@client.zadd("key", 2, "two")
60
+ #@client.zadd("key", 3, "three")
61
+
62
+ #@client.zrank("key", "three").should == 2
63
+ #end
64
+
65
+ #it "should remove a member from a sorted set"
66
+
67
+ #it "should remove all members in a sorted set within the given indexes"
68
+
69
+ #it "should remove all members in a sorted set within the given scores"
70
+
71
+ #it "should return a range of members in a sorted set, by index, with scores ordered from high to low"
72
+
73
+ #it "should return a range of members in a sorted set, by score, with scores ordered from high to low"
74
+
75
+ #it "should determine the index of a member in a sorted set, with scores ordered from high to low"
76
+
77
+ #it "should get the score associated with the given member in a sorted set"
78
+
79
+ #it "should add multiple sorted sets and store the resulting sorted set in a new key"
80
+ #end
81
+ #end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'fakeredis'
5
+
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "StringsMethods" do
5
+
6
+ before(:each) do
7
+ @client = FakeRedis::Redis.new
8
+ end
9
+
10
+ it "should append a value to key" do
11
+ @client.set("key1", "Hello")
12
+ @client.append("key1", " World")
13
+
14
+ @client.get("key1").should == "Hello World"
15
+ end
16
+
17
+ it "should decrement the integer value of a key by one" do
18
+ @client.set("counter", "1")
19
+ @client.decr("counter")
20
+
21
+ @client.get("counter").should == "0"
22
+ end
23
+
24
+ it "should decrement the integer value of a key by the given number" do
25
+ @client.set("counter", "10")
26
+ @client.decrby("counter", "5")
27
+
28
+ @client.get("counter").should == "5"
29
+ end
30
+
31
+ it "should get the value of a key" do
32
+ @client.get("key2").should == nil
33
+ end
34
+
35
+ it "should returns the bit value at offset in the string value stored at key" do
36
+ @client.set("key1", "a")
37
+
38
+ @client.getbit("key1", 1).should == "1"
39
+ @client.getbit("key1", 2).should == "1"
40
+ @client.getbit("key1", 3).should == "0"
41
+ @client.getbit("key1", 4).should == "0"
42
+ @client.getbit("key1", 5).should == "0"
43
+ @client.getbit("key1", 6).should == "0"
44
+ @client.getbit("key1", 7).should == "1"
45
+ end
46
+
47
+ it "should get a substring of the string stored at a key" do
48
+ @client.set("key1", "This a message")
49
+
50
+ @client.getrange("key1", 0, 3).should == "This"
51
+ end
52
+
53
+ it "should set the string value of a key and return its old value" do
54
+ @client.set("key1","value1")
55
+
56
+ @client.getset("key1", "value2").should == "value1"
57
+ @client.get("key1").should == "value2"
58
+ end
59
+
60
+ it "should increment the integer value of a key by one" do
61
+ @client.set("counter", "1")
62
+ @client.incr("counter")
63
+
64
+ @client.get("counter").should == "2"
65
+ end
66
+
67
+ it "should increment the integer value of a key by the given number" do
68
+ @client.set("counter", "10")
69
+ @client.incrby("counter", "5")
70
+
71
+ @client.get("counter").should == "15"
72
+ end
73
+
74
+ it "should get the values of all the given keys" do
75
+ @client.set("key1", "value1")
76
+ @client.set("key2", "value2")
77
+ @client.set("key3", "value3")
78
+
79
+ @client.mget("key1", "key2", "key3").should == ["value1", "value2", "value3"]
80
+ end
81
+
82
+ it "should set multiple keys to multiple values" do
83
+ @client.mset(:key1, "value1", :key2, "value2")
84
+
85
+ @client.get("key1").should == "value1"
86
+ @client.get("key2").should == "value2"
87
+ end
88
+
89
+ it "should set multiple keys to multiple values, only if none of the keys exist" do
90
+ @client.msetnx(:key1, "value1", :key2, "value2")
91
+ @client.msetnx(:key1, "value3", :key2, "value4")
92
+
93
+ @client.get("key1").should == "value1"
94
+ @client.get("key2").should == "value2"
95
+ end
96
+
97
+ it "should set the string value of a key" do
98
+ @client.set("key1", "1")
99
+
100
+ @client.get("key1").should == "1"
101
+ end
102
+
103
+ it "should sets or clears the bit at offset in the string value stored at key" do
104
+ @client.set("key1", "abc")
105
+ @client.setbit("key1", 11, 1)
106
+
107
+ @client.get("key1").should == "arc"
108
+ end
109
+
110
+ it "should set the value and expiration of a key" do
111
+ @client.setex("key1", 30, "value1")
112
+
113
+ @client.get("key1").should == "value1"
114
+ @client.ttl("key1").should == 30
115
+ end
116
+
117
+ it "should set the value of a key, only if the key does not exist" do
118
+ @client.set("key1", "test value")
119
+ @client.setnx("key1", "new value")
120
+ @client.setnx("key2", "another value")
121
+
122
+ @client.get("key1").should == "test value"
123
+ @client.get("key2").should == "another value"
124
+ end
125
+
126
+ it "should overwrite part of a string at key starting at the specified offset" do
127
+ @client.set("key1", "Hello World")
128
+ @client.setrange("key1", 6, "Redis")
129
+
130
+ @client.get("key1").should == "Hello Redis"
131
+ end
132
+
133
+ it "should get the length of the value stored in a key" do
134
+ @client.set("key1", "abc")
135
+
136
+ @client.strlen("key1").should == 3
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "TransactionsMethods" do
5
+ before(:each) do
6
+ @client = FakeRedis::Redis.new
7
+ end
8
+
9
+ it "should mark the start of a transaction block" do
10
+ transaction = @client.multi do
11
+ @client.set("key1", "1")
12
+ @client.set("key2", "2")
13
+ @client.mget("key1", "key2")
14
+ end
15
+
16
+ transaction.should == ["1", "2"]
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fakeredis
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - fakeredis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-16 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: Fake implementation of redis-rb for machines without Redis or test environments
27
+ email:
28
+ - guilleiguaran@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - .rspec
38
+ - .travis.yml
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - fakeredis.gemspec
44
+ - lib/fakeredis.rb
45
+ - lib/fakeredis/connection.rb
46
+ - lib/fakeredis/hashes.rb
47
+ - lib/fakeredis/keys.rb
48
+ - lib/fakeredis/lists.rb
49
+ - lib/fakeredis/server.rb
50
+ - lib/fakeredis/sets.rb
51
+ - lib/fakeredis/sorted_sets.rb
52
+ - lib/fakeredis/strings.rb
53
+ - lib/fakeredis/transactions.rb
54
+ - lib/fakeredis/version.rb
55
+ - spec/connection_spec.rb
56
+ - spec/hashes_spec.rb
57
+ - spec/keys_spec.rb
58
+ - spec/lists_spec.rb
59
+ - spec/server_spec.rb
60
+ - spec/sets_spec.rb
61
+ - spec/sorted_sets_spec.rb
62
+ - spec/spec_helper.rb
63
+ - spec/strings_spec.rb
64
+ - spec/transactions_spec.rb
65
+ homepage: http://github.com/guilleiguaran/fakeredis
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project: fakeredis
88
+ rubygems_version: 1.7.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Fake redis-rb for your tests
92
+ test_files:
93
+ - spec/connection_spec.rb
94
+ - spec/hashes_spec.rb
95
+ - spec/keys_spec.rb
96
+ - spec/lists_spec.rb
97
+ - spec/server_spec.rb
98
+ - spec/sets_spec.rb
99
+ - spec/sorted_sets_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/strings_spec.rb
102
+ - spec/transactions_spec.rb