utest 0.0.1
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.
- data/.gitignore +12 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +58 -0
- data/Rakefile +5 -0
- data/autotest/discover.rb +1 -0
- data/lib/utest.rb +5 -0
- data/lib/utest/ci.rake +56 -0
- data/lib/utest/inmemory_redis.rb +163 -0
- data/lib/utest/version.rb +3 -0
- data/spec/inmemory_redis_spec.rb +440 -0
- data/spec/spec_helper.rb +12 -0
- data/utest.gemspec +26 -0
- metadata +136 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
utest (0.0.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: http://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ZenTest (4.7.0)
|
|
10
|
+
autotest-fsevent (0.2.8)
|
|
11
|
+
sys-uname
|
|
12
|
+
builder (3.0.0)
|
|
13
|
+
diff-lcs (1.1.3)
|
|
14
|
+
ffi (1.0.11)
|
|
15
|
+
geminabox (0.6.1)
|
|
16
|
+
builder
|
|
17
|
+
httpclient
|
|
18
|
+
sinatra
|
|
19
|
+
guard (1.0.1)
|
|
20
|
+
ffi (>= 0.5.0)
|
|
21
|
+
thor (~> 0.14.6)
|
|
22
|
+
guard-rspec (0.7.0)
|
|
23
|
+
guard (>= 0.10.0)
|
|
24
|
+
httpclient (2.2.4)
|
|
25
|
+
rack (1.4.1)
|
|
26
|
+
rack-protection (1.2.0)
|
|
27
|
+
rack
|
|
28
|
+
rake (0.9.2.2)
|
|
29
|
+
rb-fsevent (0.9.1)
|
|
30
|
+
rspec (2.9.0)
|
|
31
|
+
rspec-core (~> 2.9.0)
|
|
32
|
+
rspec-expectations (~> 2.9.0)
|
|
33
|
+
rspec-mocks (~> 2.9.0)
|
|
34
|
+
rspec-core (2.9.0)
|
|
35
|
+
rspec-expectations (2.9.1)
|
|
36
|
+
diff-lcs (~> 1.1.3)
|
|
37
|
+
rspec-mocks (2.9.0)
|
|
38
|
+
sinatra (1.3.2)
|
|
39
|
+
rack (~> 1.3, >= 1.3.6)
|
|
40
|
+
rack-protection (~> 1.2)
|
|
41
|
+
tilt (~> 1.3, >= 1.3.3)
|
|
42
|
+
sys-uname (0.9.0)
|
|
43
|
+
ffi (>= 1.0.0)
|
|
44
|
+
thor (0.14.6)
|
|
45
|
+
tilt (1.3.3)
|
|
46
|
+
|
|
47
|
+
PLATFORMS
|
|
48
|
+
ruby
|
|
49
|
+
|
|
50
|
+
DEPENDENCIES
|
|
51
|
+
ZenTest
|
|
52
|
+
autotest-fsevent
|
|
53
|
+
geminabox
|
|
54
|
+
guard-rspec
|
|
55
|
+
rake
|
|
56
|
+
rb-fsevent
|
|
57
|
+
rspec
|
|
58
|
+
utest!
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/lib/utest.rb
ADDED
data/lib/utest/ci.rake
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
|
|
2
|
+
namespace :ci do
|
|
3
|
+
desc "Perform a build on the CI server"
|
|
4
|
+
task :build do
|
|
5
|
+
begin
|
|
6
|
+
Rake::Task['ci:qa'].invoke
|
|
7
|
+
Rake::Task['ci:success'].invoke
|
|
8
|
+
rescue Exception => e
|
|
9
|
+
Rake::Task['ci:failure'].invoke
|
|
10
|
+
raise e
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc "Update your code base (will erase local changes!!!)"
|
|
15
|
+
task :rebase do
|
|
16
|
+
system('git checkout .')
|
|
17
|
+
system('git pull --rebase')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
desc "Run QA"
|
|
21
|
+
task :qa do
|
|
22
|
+
Rake::Task['ci:rspec'].invoke
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Run Rspec"
|
|
26
|
+
task :rspec do
|
|
27
|
+
system "mkdir -p ../public" unless File.exists?("../public")
|
|
28
|
+
Rake::Task['ci:rspec_run'].invoke
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
RSpec::Core::RakeTask.new(:rspec_run) do |t|
|
|
32
|
+
t.pattern = "./spec/**/*spec.rb"
|
|
33
|
+
t.rspec_opts = ["--format", "html", "--out", "../public/rspec.html"]
|
|
34
|
+
t.fail_on_error = true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
desc "The Build Succeeded, so tell our monitoring service"
|
|
38
|
+
task :success do
|
|
39
|
+
if File.exists?("/home/deployer/monitor/log")
|
|
40
|
+
system 'echo "Utest succeeded, http://cc.cenx.localnet" > /home/deployer/monitor/log/Utest.cc'
|
|
41
|
+
else
|
|
42
|
+
print "BUILD SUCCEEDED, but log directory (/home/deployer/monitor/log) does not exist"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc "The Build failed, so tell our monitoring service"
|
|
47
|
+
task :failure do
|
|
48
|
+
if File.exists?("/home/deployer/monitor/log")
|
|
49
|
+
system "curl http://cc.cenx.localnet/utest > /home/deployer/monitor/log/Utest.cc"
|
|
50
|
+
else
|
|
51
|
+
raise "BUILD FAILED, but log directory (/home/deployer/monitor/log) does not exist"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
module Utest
|
|
2
|
+
class InmemoryRedis
|
|
3
|
+
|
|
4
|
+
def initialize(data = {})
|
|
5
|
+
@values = {}
|
|
6
|
+
@sets = {}
|
|
7
|
+
@lists = {}
|
|
8
|
+
@hashes = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def del(key)
|
|
12
|
+
count = 0
|
|
13
|
+
|
|
14
|
+
count = del_if_set(key,@values,count)
|
|
15
|
+
count = del_if_set(key,@sets,count)
|
|
16
|
+
count = del_if_set(key,@lists,count)
|
|
17
|
+
count = del_if_set(key,@hashes,count)
|
|
18
|
+
count
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def hget(key,field)
|
|
22
|
+
return nil unless @hashes.key?(key)
|
|
23
|
+
@hashes[key][field]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def hset(key,field,val)
|
|
27
|
+
@hashes[key] ||= {}
|
|
28
|
+
@hashes[key][field] = val
|
|
29
|
+
true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def incr(key)
|
|
33
|
+
incrby(key,1)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def incrby(key,incr)
|
|
37
|
+
new_value = (get(key) || 0).to_i + incr.to_i
|
|
38
|
+
set(key,"#{new_value}")
|
|
39
|
+
new_value
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def hincrby(key,field,incr)
|
|
43
|
+
new_value = (hget(key,field) || 0).to_i + incr.to_i
|
|
44
|
+
hset(key,field,"#{new_value}")
|
|
45
|
+
new_value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def hgetall(key)
|
|
49
|
+
@hashes[key] || {}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def set(key,val)
|
|
53
|
+
@values[key] = val
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def get(key)
|
|
58
|
+
@values[key]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def scard(key)
|
|
62
|
+
return 0 if @sets[key].nil?
|
|
63
|
+
@sets[key].size
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def sadd(key,member)
|
|
67
|
+
@sets[key] = [] if @sets[key].nil?
|
|
68
|
+
return 0 if @sets[key].include?(member)
|
|
69
|
+
@sets[key] << member
|
|
70
|
+
1
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def srem(key,member)
|
|
74
|
+
return 0 if @sets[key].nil?
|
|
75
|
+
return 0 unless @sets[key].include?(member)
|
|
76
|
+
@sets[key].delete(member)
|
|
77
|
+
1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def smembers(key)
|
|
81
|
+
@sets[key] = [] if @sets[key].nil?
|
|
82
|
+
@sets[key]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def llen(key)
|
|
86
|
+
return 0 if @lists[key].nil?
|
|
87
|
+
@lists[key].size
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def lindex(key,index)
|
|
91
|
+
return nil if @lists[key].nil?
|
|
92
|
+
@lists[key][index]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def lrem(key,count,value)
|
|
96
|
+
return 0 if @lists[key].nil?
|
|
97
|
+
|
|
98
|
+
my_list = @lists[key]
|
|
99
|
+
old_size = my_list.size
|
|
100
|
+
|
|
101
|
+
if count == 0
|
|
102
|
+
my_list.delete(value)
|
|
103
|
+
else
|
|
104
|
+
my_list.reverse! if count < 0
|
|
105
|
+
num_found = 0
|
|
106
|
+
my_list.reject! do |x|
|
|
107
|
+
num_found += 1 if x == value
|
|
108
|
+
num_found > count.abs ? false : x == value
|
|
109
|
+
end
|
|
110
|
+
my_list.reverse! if count < 0
|
|
111
|
+
end
|
|
112
|
+
new_size = my_list.size
|
|
113
|
+
old_size - new_size
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def lset(key,index,value)
|
|
117
|
+
raise "ERR no such key" if @lists[key].nil?
|
|
118
|
+
raise "ERR index out of range" if @lists[key][index].nil?
|
|
119
|
+
@lists[key][index] = value
|
|
120
|
+
true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def rpush(key,value)
|
|
124
|
+
@lists[key] = [] if @lists[key].nil?
|
|
125
|
+
@lists[key] << value
|
|
126
|
+
true
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def lrange(key,start,stop)
|
|
130
|
+
return [] if @lists[key].nil?
|
|
131
|
+
start = 0 if start < 0
|
|
132
|
+
max_stop = llen(key) - 1
|
|
133
|
+
stop = max_stop if (stop == -1 || stop > max_stop)
|
|
134
|
+
return [] if start > stop
|
|
135
|
+
@lists[key][start..stop]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def lpop(key)
|
|
139
|
+
return nil if @lists[key].nil?
|
|
140
|
+
@lists[key].shift
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def rpop(key)
|
|
144
|
+
return nil if @lists[key].nil?
|
|
145
|
+
@lists[key].pop
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def multi
|
|
149
|
+
yield
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def del_if_set(key,hash,count)
|
|
155
|
+
if hash.has_key?(key)
|
|
156
|
+
hash.delete(key)
|
|
157
|
+
count =+ 1
|
|
158
|
+
end
|
|
159
|
+
count
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Utest
|
|
4
|
+
describe InmemoryRedis do
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@redis = InmemoryRedis.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "#hset" do
|
|
11
|
+
|
|
12
|
+
it "should set the value" do
|
|
13
|
+
@redis.hset("a","name","Andrew").should == true
|
|
14
|
+
@redis.hget("a","name").should == "Andrew"
|
|
15
|
+
@redis.hset("a","name","James").should == true
|
|
16
|
+
@redis.hget("a","name").should == "James"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "#incr" do
|
|
22
|
+
|
|
23
|
+
it "should assume zero for new values" do
|
|
24
|
+
@redis.incr("a").should == 1
|
|
25
|
+
@redis.get("a").should == "1"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should increment by 1" do
|
|
29
|
+
@redis.set("a","20")
|
|
30
|
+
@redis.incr("a").should == 21
|
|
31
|
+
@redis.get("a").should == "21"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#incrby" do
|
|
37
|
+
|
|
38
|
+
it "should assume zero for new values" do
|
|
39
|
+
@redis.incrby("a",4).should == 4
|
|
40
|
+
@redis.get("a").should == "4"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should increment by set value" do
|
|
44
|
+
@redis.set("a","20")
|
|
45
|
+
@redis.incrby("a",4).should == 24
|
|
46
|
+
@redis.get("a").should == "24"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "#hincrby" do
|
|
52
|
+
|
|
53
|
+
it "should assume zero for new values" do
|
|
54
|
+
@redis.hincrby("a","name",10).should == 10
|
|
55
|
+
@redis.hget("a","name").should == "10"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should increment by the set amount" do
|
|
59
|
+
@redis.hset("a","name","20")
|
|
60
|
+
@redis.hincrby("a","name",10).should == 30
|
|
61
|
+
@redis.hget("a","name").should == "30"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
describe "#hget" do
|
|
67
|
+
|
|
68
|
+
it "should return nil if unknown" do
|
|
69
|
+
@redis.hget("a","name").should == nil
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should return the value" do
|
|
73
|
+
@redis.hset("a","name","Andrew")
|
|
74
|
+
@redis.hget("a","name").should == "Andrew"
|
|
75
|
+
@redis.hget("a","last_name").should == nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "#hgetall" do
|
|
81
|
+
|
|
82
|
+
it "should return {} if unknown" do
|
|
83
|
+
@redis.hgetall("a").should == {}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should return the value" do
|
|
87
|
+
@redis.hset("a","name","Andrew")
|
|
88
|
+
@redis.hset("a","last_name","Forward")
|
|
89
|
+
@redis.hgetall("a").should == { "name" => "Andrew", "last_name" => "Forward" }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
describe "#set" do
|
|
98
|
+
|
|
99
|
+
it "should set the value" do
|
|
100
|
+
@redis.set("a","1").should == true
|
|
101
|
+
@redis.get("a").should == "1"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should overwrite the existing value" do
|
|
105
|
+
@redis.set("a","1").should == true
|
|
106
|
+
@redis.get("a").should == "1"
|
|
107
|
+
@redis.set("a","2").should == true
|
|
108
|
+
@redis.get("a").should == "2"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "#get" do
|
|
114
|
+
|
|
115
|
+
it "should get nil the value" do
|
|
116
|
+
@redis.get("a").should == nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should get the latest value" do
|
|
120
|
+
@redis.set("a","1").should == true
|
|
121
|
+
@redis.get("a").should == "1"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe "#sadd" do
|
|
127
|
+
|
|
128
|
+
it "should add to the set" do
|
|
129
|
+
@redis.sadd("benchmarks", "one").should == 1
|
|
130
|
+
@redis.scard("benchmarks").should == 1
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "should not allow duplicate" do
|
|
134
|
+
@redis.sadd("benchmarks", "one").should == 1
|
|
135
|
+
@redis.scard("benchmarks").should == 1
|
|
136
|
+
@redis.sadd("benchmarks", "one").should == 0
|
|
137
|
+
@redis.scard("benchmarks").should == 1
|
|
138
|
+
@redis.sadd("benchmarks", "two").should == 1
|
|
139
|
+
@redis.scard("benchmarks").should == 2
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
describe "#srem" do
|
|
145
|
+
|
|
146
|
+
it "remove the entry" do
|
|
147
|
+
@redis.sadd("benchmarks", "one").should == 1
|
|
148
|
+
@redis.srem("benchmarks", "one").should == 1
|
|
149
|
+
@redis.scard("benchmarks").should == 0
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should not remove if doesn't exist" do
|
|
153
|
+
@redis.sadd("benchmarks", "one").should == 1
|
|
154
|
+
@redis.sadd("benchmarks", "two").should == 1
|
|
155
|
+
|
|
156
|
+
@redis.srem("benchmarks", "two").should == 1
|
|
157
|
+
@redis.srem("benchmarks", "two").should == 0
|
|
158
|
+
@redis.scard("benchmarks").should == 1
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
describe "#smembers" do
|
|
165
|
+
|
|
166
|
+
it "should return empty set for nil" do
|
|
167
|
+
@redis.smembers("benchmarks").should == []
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should return the set" do
|
|
171
|
+
@redis.sadd("benchmarks", "one").should == 1
|
|
172
|
+
@redis.sadd("benchmarks", "one").should == 0
|
|
173
|
+
@redis.sadd("benchmarks", "two").should == 1
|
|
174
|
+
@redis.smembers("benchmarks").should == ["one","two"]
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
describe "#scard" do
|
|
181
|
+
|
|
182
|
+
it "should handle nil" do
|
|
183
|
+
@redis.scard(nil).should == 0
|
|
184
|
+
@redis.scard("").should == 0
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "should handle unknown" do
|
|
188
|
+
@redis.scard("blah").should == 0
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should count" do
|
|
192
|
+
@redis.scard("benchmarks").should == 0
|
|
193
|
+
@redis.sadd "benchmarks", "one"
|
|
194
|
+
@redis.scard("benchmarks").should == 1
|
|
195
|
+
@redis.sadd "benchmarks", "two"
|
|
196
|
+
@redis.scard("benchmarks").should == 2
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
describe "#lrem" do
|
|
203
|
+
|
|
204
|
+
before(:each) do
|
|
205
|
+
@redis.rpush("x", "one").should == true
|
|
206
|
+
@redis.rpush("x", "two").should == true
|
|
207
|
+
@redis.rpush("x", "three").should == true
|
|
208
|
+
@redis.rpush("x", "one").should == true
|
|
209
|
+
@redis.rpush("x", "four").should == true
|
|
210
|
+
@redis.rpush("x", "one").should == true
|
|
211
|
+
@redis.rpush("x", "one").should == true
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "should remove all if count 0" do
|
|
215
|
+
@redis.lrem("x",0,"one").should == 4
|
|
216
|
+
@redis.lrange("x",0,-1).should == ["two","three","four"]
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
it "should remove from start if > 0" do
|
|
220
|
+
@redis.lrem("x",1,"one").should == 1
|
|
221
|
+
@redis.lrange("x",0,-1).should == ["two","three","one","four","one","one"]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "should remove from end if < 0" do
|
|
225
|
+
@redis.lrem("x",-2,"one").should == 2
|
|
226
|
+
@redis.lrange("x",0,-1).should == ["one", "two","three","one","four"]
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
describe "#rpush" do
|
|
233
|
+
|
|
234
|
+
it "should add the entry" do
|
|
235
|
+
@redis.llen("x").should == 0
|
|
236
|
+
@redis.rpush("x", "one").should == true
|
|
237
|
+
@redis.llen("x").should == 1
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "should allow duplicates" do
|
|
241
|
+
@redis.llen("x").should == 0
|
|
242
|
+
@redis.rpush("x", "one").should == true
|
|
243
|
+
@redis.rpush("x", "one").should == true
|
|
244
|
+
@redis.llen("x").should == 2
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
describe "#lset" do
|
|
250
|
+
|
|
251
|
+
it "should update the entry" do
|
|
252
|
+
@redis.rpush("x","one")
|
|
253
|
+
@redis.rpush("x","two")
|
|
254
|
+
@redis.lset("x", 0, "111").should == true
|
|
255
|
+
@redis.lset("x", 1, "222").should == true
|
|
256
|
+
@redis.lrange("x",0,-1).should == [ "111", "222" ]
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "should raise error for unknown key" do
|
|
260
|
+
lambda { @redis.lset("a",0,"one") }.should raise_error
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "should raise error for out-of-bound index (+ index)" do
|
|
264
|
+
@redis.rpush("a","one")
|
|
265
|
+
@redis.rpush("a","two")
|
|
266
|
+
@redis.lset("a",0,"111")
|
|
267
|
+
@redis.lset("a",1,"222")
|
|
268
|
+
@redis.lrange("a",0,-1).should == [ "111", "222" ]
|
|
269
|
+
lambda { @redis.lset("a",2,"one") }.should raise_error
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it "should raise error for out-of-bound index (+ index)" do
|
|
273
|
+
@redis.rpush("a","one")
|
|
274
|
+
@redis.rpush("a","two")
|
|
275
|
+
@redis.lset("a",-2,"111")
|
|
276
|
+
@redis.lset("a",-1,"222")
|
|
277
|
+
@redis.lrange("a",0,-1).should == [ "111", "222" ]
|
|
278
|
+
lambda { @redis.lset("a",-3,"one") }.should raise_error
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
describe "#lindex" do
|
|
285
|
+
|
|
286
|
+
before(:each) do
|
|
287
|
+
@redis.rpush("x", "one").should == true
|
|
288
|
+
@redis.rpush("x", "two").should == true
|
|
289
|
+
@redis.rpush("x", "three").should == true
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it "should handle unknown index" do
|
|
293
|
+
@redis.lindex("y", 0).should == nil
|
|
294
|
+
@redis.lindex("x", 10).should == nil
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "should look up the index" do
|
|
298
|
+
@redis.lindex("x", 0).should == "one"
|
|
299
|
+
@redis.lindex("x", 1).should == "two"
|
|
300
|
+
@redis.lindex("x", 2).should == "three"
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it "should look up the index (negative)" do
|
|
304
|
+
@redis.lindex("x", -3).should == "one"
|
|
305
|
+
@redis.lindex("x", -2).should == "two"
|
|
306
|
+
@redis.lindex("x", -1).should == "three"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
describe "#lrange" do
|
|
313
|
+
|
|
314
|
+
before(:each) do
|
|
315
|
+
@redis.rpush("x", "one").should == true
|
|
316
|
+
@redis.rpush("x", "two").should == true
|
|
317
|
+
@redis.rpush("x", "three").should == true
|
|
318
|
+
@redis.rpush("x", "four").should == true
|
|
319
|
+
@redis.rpush("x", "five").should == true
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
it "should support subsets" do
|
|
323
|
+
@redis.lrange("x",1,2).should == ["two","three"]
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
it "should support full" do
|
|
327
|
+
@redis.lrange("x",0,-1).should == ["one","two","three","four","five"]
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
it "should invalid ranges" do
|
|
331
|
+
@redis.lrange("x",2,1).should == []
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
it "should out of bounds" do
|
|
335
|
+
@redis.lrange("x",-1,1).should == ["one","two"]
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
it "should support nil" do
|
|
339
|
+
@redis.lrange(nil,0,1).should == []
|
|
340
|
+
@redis.lrange("",0,1).should == []
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it "should support unknown" do
|
|
344
|
+
@redis.lrange("blah",0,1).should == []
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
describe "#lpop" do
|
|
350
|
+
|
|
351
|
+
it "should return nil if nothing there" do
|
|
352
|
+
@redis.lpop("a").should == nil
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it "should grab the first element" do
|
|
356
|
+
@redis.rpush("x", "one").should == true
|
|
357
|
+
@redis.rpush("x", "two").should == true
|
|
358
|
+
@redis.llen("x").should == 2
|
|
359
|
+
|
|
360
|
+
@redis.lpop("x").should == "one"
|
|
361
|
+
@redis.llen("x").should == 1
|
|
362
|
+
|
|
363
|
+
@redis.lpop("x").should == "two"
|
|
364
|
+
@redis.llen("x").should == 0
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
describe "#rpop" do
|
|
370
|
+
|
|
371
|
+
it "should return nil if nothing there" do
|
|
372
|
+
@redis.rpop("a").should == nil
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
it "should grab the first element" do
|
|
376
|
+
@redis.rpush("x", "one").should == true
|
|
377
|
+
@redis.rpush("x", "two").should == true
|
|
378
|
+
@redis.lrange("x",0,-1).should == [ "one","two" ]
|
|
379
|
+
|
|
380
|
+
@redis.rpop("x").should == "two"
|
|
381
|
+
@redis.lrange("x",0,-1).should == [ "one" ]
|
|
382
|
+
|
|
383
|
+
@redis.rpop("x").should == "one"
|
|
384
|
+
@redis.lrange("x",0,-1).should == [ ]
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
describe "#multi" do
|
|
390
|
+
|
|
391
|
+
it "should perform multiple tasks" do
|
|
392
|
+
@redis.multi do
|
|
393
|
+
@redis.rpush("x","one")
|
|
394
|
+
@redis.rpush("x","two")
|
|
395
|
+
end
|
|
396
|
+
@redis.llen("x").should == 2
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
describe "#del" do
|
|
402
|
+
|
|
403
|
+
it "should ignore unknown key" do
|
|
404
|
+
@redis.del("a").should == 0
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# @hashes = {}
|
|
408
|
+
|
|
409
|
+
it "should delete values" do
|
|
410
|
+
@redis.set("a","1")
|
|
411
|
+
@redis.del("a").should == 1
|
|
412
|
+
@redis.get("a").should == nil
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
it "should delete lists" do
|
|
416
|
+
@redis.rpush("a","1")
|
|
417
|
+
@redis.lrange("a",0,-1).should == ["1"]
|
|
418
|
+
@redis.del("a").should == 1
|
|
419
|
+
@redis.lrange("a",0,-1).should == []
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
it "should delete sets" do
|
|
423
|
+
@redis.sadd("a","1")
|
|
424
|
+
@redis.smembers("a").should == ["1"]
|
|
425
|
+
@redis.del("a").should == 1
|
|
426
|
+
@redis.smembers("a").should == []
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
it "should delete hashes" do
|
|
430
|
+
@redis.hset("a","b","1")
|
|
431
|
+
@redis.hget("a","b").should == "1"
|
|
432
|
+
@redis.del("a").should == 1
|
|
433
|
+
@redis.hget("a","b").should == nil
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
end
|
|
440
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'rspec'
|
|
4
|
+
require File.dirname(__FILE__) + '/../lib/utest'
|
|
5
|
+
|
|
6
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
7
|
+
# in spec/support/ and its subdirectories.
|
|
8
|
+
# Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.mock_with :rspec
|
|
12
|
+
end
|
data/utest.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "utest/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "utest"
|
|
7
|
+
s.version = Utest::VERSION
|
|
8
|
+
s.authors = ["Andrew Forward"]
|
|
9
|
+
s.email = ["aforward@gmail.com"]
|
|
10
|
+
s.homepage = "http://github.com/aforward/utest"
|
|
11
|
+
s.summary = %q{Testing and Mock Aids (e.g. Redis mock)}
|
|
12
|
+
s.description = %q{Testing and Mock Aids (e.g. Redis mock)}
|
|
13
|
+
|
|
14
|
+
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
|
|
19
|
+
s.add_development_dependency('rake')
|
|
20
|
+
s.add_development_dependency('rspec')
|
|
21
|
+
s.add_development_dependency('ZenTest')
|
|
22
|
+
s.add_development_dependency('guard-rspec')
|
|
23
|
+
s.add_development_dependency('autotest-fsevent') if RUBY_PLATFORM =~ /darwin/i
|
|
24
|
+
s.add_development_dependency('rb-fsevent') if RUBY_PLATFORM =~ /darwin/i
|
|
25
|
+
s.add_development_dependency('geminabox')
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: utest
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Andrew Forward
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-04-25 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rake
|
|
16
|
+
requirement: &70339032643940 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70339032643940
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: rspec
|
|
27
|
+
requirement: &70339032643520 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70339032643520
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: ZenTest
|
|
38
|
+
requirement: &70339032643100 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
type: :development
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *70339032643100
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: guard-rspec
|
|
49
|
+
requirement: &70339032628620 !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *70339032628620
|
|
58
|
+
- !ruby/object:Gem::Dependency
|
|
59
|
+
name: autotest-fsevent
|
|
60
|
+
requirement: &70339032628000 !ruby/object:Gem::Requirement
|
|
61
|
+
none: false
|
|
62
|
+
requirements:
|
|
63
|
+
- - ! '>='
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '0'
|
|
66
|
+
type: :development
|
|
67
|
+
prerelease: false
|
|
68
|
+
version_requirements: *70339032628000
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rb-fsevent
|
|
71
|
+
requirement: &70339032627580 !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
73
|
+
requirements:
|
|
74
|
+
- - ! '>='
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: *70339032627580
|
|
80
|
+
- !ruby/object:Gem::Dependency
|
|
81
|
+
name: geminabox
|
|
82
|
+
requirement: &70339032627080 !ruby/object:Gem::Requirement
|
|
83
|
+
none: false
|
|
84
|
+
requirements:
|
|
85
|
+
- - ! '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: *70339032627080
|
|
91
|
+
description: Testing and Mock Aids (e.g. Redis mock)
|
|
92
|
+
email:
|
|
93
|
+
- aforward@gmail.com
|
|
94
|
+
executables: []
|
|
95
|
+
extensions: []
|
|
96
|
+
extra_rdoc_files: []
|
|
97
|
+
files:
|
|
98
|
+
- .gitignore
|
|
99
|
+
- Gemfile
|
|
100
|
+
- Gemfile.lock
|
|
101
|
+
- Rakefile
|
|
102
|
+
- autotest/discover.rb
|
|
103
|
+
- lib/utest.rb
|
|
104
|
+
- lib/utest/ci.rake
|
|
105
|
+
- lib/utest/inmemory_redis.rb
|
|
106
|
+
- lib/utest/version.rb
|
|
107
|
+
- spec/inmemory_redis_spec.rb
|
|
108
|
+
- spec/spec_helper.rb
|
|
109
|
+
- utest.gemspec
|
|
110
|
+
homepage: http://github.com/aforward/utest
|
|
111
|
+
licenses: []
|
|
112
|
+
post_install_message:
|
|
113
|
+
rdoc_options: []
|
|
114
|
+
require_paths:
|
|
115
|
+
- lib
|
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
|
+
none: false
|
|
118
|
+
requirements:
|
|
119
|
+
- - ! '>='
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '0'
|
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
|
+
none: false
|
|
124
|
+
requirements:
|
|
125
|
+
- - ! '>='
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
requirements: []
|
|
129
|
+
rubyforge_project:
|
|
130
|
+
rubygems_version: 1.8.10
|
|
131
|
+
signing_key:
|
|
132
|
+
specification_version: 3
|
|
133
|
+
summary: Testing and Mock Aids (e.g. Redis mock)
|
|
134
|
+
test_files:
|
|
135
|
+
- spec/inmemory_redis_spec.rb
|
|
136
|
+
- spec/spec_helper.rb
|