Skip to content

Commit 7da5f65

Browse files
committed
Don't rely on TestCase#skip since it's not available on 1.8.7.
1 parent 06ba706 commit 7da5f65

16 files changed

+408
-404
lines changed

test/commands_on_strings_test.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ def test_msetnx_mapped
8282
end
8383

8484
def test_bitop
85-
target_version "2.5.10"
86-
87-
r.set("foo", "a")
88-
r.set("bar", "b")
89-
90-
r.bitop(:and, "foo&bar", "foo", "bar")
91-
assert_equal "\x60", r.get("foo&bar")
92-
r.bitop(:or, "foo|bar", "foo", "bar")
93-
assert_equal "\x63", r.get("foo|bar")
94-
r.bitop(:xor, "foo^bar", "foo", "bar")
95-
assert_equal "\x03", r.get("foo^bar")
96-
r.bitop(:not, "~foo", "foo")
97-
assert_equal "\x9E", r.get("~foo")
85+
target_version "2.5.10" do
86+
r.set("foo", "a")
87+
r.set("bar", "b")
88+
89+
r.bitop(:and, "foo&bar", "foo", "bar")
90+
assert_equal "\x60", r.get("foo&bar")
91+
r.bitop(:or, "foo|bar", "foo", "bar")
92+
assert_equal "\x63", r.get("foo|bar")
93+
r.bitop(:xor, "foo^bar", "foo", "bar")
94+
assert_equal "\x03", r.get("foo^bar")
95+
r.bitop(:not, "~foo", "foo")
96+
assert_equal "\x9E", r.get("~foo")
97+
end
9898
end
9999
end

test/distributed_commands_on_strings_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def test_msetnx_mapped
4747
end
4848

4949
def test_bitop
50-
target_version "2.5.10"
50+
target_version "2.5.10" do
51+
assert_raise Redis::Distributed::CannotDistribute do
52+
r.set("foo", "a")
53+
r.set("bar", "b")
5154

52-
assert_raise Redis::Distributed::CannotDistribute do
53-
r.set("foo", "a")
54-
r.set("bar", "b")
55-
56-
r.bitop(:and, "foo&bar", "foo", "bar")
55+
r.bitop(:and, "foo&bar", "foo", "bar")
56+
end
5757
end
5858
end
5959
end

test/distributed_commands_requiring_clustering_test.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,18 @@ def test_sort_with_store
147147
end
148148

149149
def test_bitop
150-
target_version "2.5.10"
151-
152-
r.set("{qux}foo", "a")
153-
r.set("{qux}bar", "b")
154-
155-
r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
156-
assert_equal "\x60", r.get("{qux}foo&bar")
157-
r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
158-
assert_equal "\x63", r.get("{qux}foo|bar")
159-
r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
160-
assert_equal "\x03", r.get("{qux}foo^bar")
161-
r.bitop(:not, "{qux}~foo", "{qux}foo")
162-
assert_equal "\x9E", r.get("{qux}~foo")
150+
target_version "2.5.10" do
151+
r.set("{qux}foo", "a")
152+
r.set("{qux}bar", "b")
153+
154+
r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
155+
assert_equal "\x60", r.get("{qux}foo&bar")
156+
r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
157+
assert_equal "\x63", r.get("{qux}foo|bar")
158+
r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
159+
assert_equal "\x03", r.get("{qux}foo^bar")
160+
r.bitop(:not, "{qux}~foo", "{qux}foo")
161+
assert_equal "\x9E", r.get("{qux}~foo")
162+
end
163163
end
164164
end

test/distributed_remote_server_control_commands_test.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def test_info
2828
end
2929

3030
def test_info_commandstats
31-
target_version "2.5.7"
31+
target_version "2.5.7" do
32+
r.nodes.each { |n| n.config(:resetstat) }
33+
r.ping # Executed on every node
3234

33-
r.nodes.each { |n| n.config(:resetstat) }
34-
r.ping # Executed on every node
35-
36-
r.info(:commandstats).each do |info|
37-
assert_equal "1", info["ping"]["calls"]
35+
r.info(:commandstats).each do |info|
36+
assert_equal "1", info["ping"]["calls"]
37+
end
3838
end
3939
end
4040

@@ -52,15 +52,15 @@ def test_echo
5252
end
5353

5454
def test_time
55-
target_version "2.5.4"
55+
target_version "2.5.4" do
56+
# Test that the difference between the time that Ruby reports and the time
57+
# that Redis reports is minimal (prevents the test from being racy).
58+
r.time.each do |rv|
59+
redis_usec = rv[0] * 1_000_000 + rv[1]
60+
ruby_usec = Integer(Time.now.to_f * 1_000_000)
5661

57-
# Test that the difference between the time that Ruby reports and the time
58-
# that Redis reports is minimal (prevents the test from being racy).
59-
r.time.each do |rv|
60-
redis_usec = rv[0] * 1_000_000 + rv[1]
61-
ruby_usec = Integer(Time.now.to_f * 1_000_000)
62-
63-
assert 500_000 > (ruby_usec - redis_usec).abs
62+
assert 500_000 > (ruby_usec - redis_usec).abs
63+
end
6464
end
6565
end
6666
end

test/distributed_scripting_test.rb

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,92 +11,92 @@ def to_sha(script)
1111
end
1212

1313
def test_script_exists
14-
target_version "2.5.9" # 2.6-rc1
15-
16-
a = to_sha("return 1")
17-
b = a.succ
18-
19-
assert_equal [true], r.script(:exists, a)
20-
assert_equal [false], r.script(:exists, b)
21-
assert_equal [[true]], r.script(:exists, [a])
22-
assert_equal [[false]], r.script(:exists, [b])
23-
assert_equal [[true, false]], r.script(:exists, [a, b])
14+
target_version "2.5.9" do # 2.6-rc1
15+
a = to_sha("return 1")
16+
b = a.succ
17+
18+
assert_equal [true], r.script(:exists, a)
19+
assert_equal [false], r.script(:exists, b)
20+
assert_equal [[true]], r.script(:exists, [a])
21+
assert_equal [[false]], r.script(:exists, [b])
22+
assert_equal [[true, false]], r.script(:exists, [a, b])
23+
end
2424
end
2525

2626
def test_script_flush
27-
target_version "2.5.9" # 2.6-rc1
28-
29-
sha = to_sha("return 1")
30-
assert r.script(:exists, sha).first
31-
assert_equal ["OK"], r.script(:flush)
32-
assert !r.script(:exists, sha).first
27+
target_version "2.5.9" do # 2.6-rc1
28+
sha = to_sha("return 1")
29+
assert r.script(:exists, sha).first
30+
assert_equal ["OK"], r.script(:flush)
31+
assert !r.script(:exists, sha).first
32+
end
3333
end
3434

3535
def test_script_kill
36-
target_version "2.5.9" # 2.6-rc1
37-
38-
redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
39-
assert_equal ["KILL"], redis.script(:kill)
36+
target_version "2.5.9" do # 2.6-rc1
37+
redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
38+
assert_equal ["KILL"], redis.script(:kill)
39+
end
4040
end
4141
end
4242

4343
def test_eval
44-
target_version "2.5.9" # 2.6-rc1
44+
target_version "2.5.9" do # 2.6-rc1
45+
assert_raises(Redis::Distributed::CannotDistribute) do
46+
r.eval("return #KEYS")
47+
end
4548

46-
assert_raises(Redis::Distributed::CannotDistribute) do
47-
r.eval("return #KEYS")
48-
end
49+
assert_raises(Redis::Distributed::CannotDistribute) do
50+
r.eval("return KEYS", ["k1", "k2"])
51+
end
4952

50-
assert_raises(Redis::Distributed::CannotDistribute) do
51-
r.eval("return KEYS", ["k1", "k2"])
53+
assert_equal ["k1"], r.eval("return KEYS", ["k1"])
54+
assert_equal ["a1", "a2"], r.eval("return ARGV", ["k1"], ["a1", "a2"])
5255
end
53-
54-
assert_equal ["k1"], r.eval("return KEYS", ["k1"])
55-
assert_equal ["a1", "a2"], r.eval("return ARGV", ["k1"], ["a1", "a2"])
5656
end
5757

5858
def test_eval_with_options_hash
59-
target_version "2.5.9" # 2.6-rc1
59+
target_version "2.5.9" do # 2.6-rc1
60+
assert_raises(Redis::Distributed::CannotDistribute) do
61+
r.eval("return #KEYS", {})
62+
end
6063

61-
assert_raises(Redis::Distributed::CannotDistribute) do
62-
r.eval("return #KEYS", {})
63-
end
64+
assert_raises(Redis::Distributed::CannotDistribute) do
65+
r.eval("return KEYS", { :keys => ["k1", "k2"] })
66+
end
6467

65-
assert_raises(Redis::Distributed::CannotDistribute) do
66-
r.eval("return KEYS", { :keys => ["k1", "k2"] })
68+
assert_equal ["k1"], r.eval("return KEYS", { :keys => ["k1"] })
69+
assert_equal ["a1", "a2"], r.eval("return ARGV", { :keys => ["k1"], :argv => ["a1", "a2"] })
6770
end
68-
69-
assert_equal ["k1"], r.eval("return KEYS", { :keys => ["k1"] })
70-
assert_equal ["a1", "a2"], r.eval("return ARGV", { :keys => ["k1"], :argv => ["a1", "a2"] })
7171
end
7272

7373
def test_evalsha
74-
target_version "2.5.9" # 2.6-rc1
74+
target_version "2.5.9" do # 2.6-rc1
75+
assert_raises(Redis::Distributed::CannotDistribute) do
76+
r.evalsha(to_sha("return #KEYS"))
77+
end
7578

76-
assert_raises(Redis::Distributed::CannotDistribute) do
77-
r.evalsha(to_sha("return #KEYS"))
78-
end
79+
assert_raises(Redis::Distributed::CannotDistribute) do
80+
r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
81+
end
7982

80-
assert_raises(Redis::Distributed::CannotDistribute) do
81-
r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
83+
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), ["k1"])
84+
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), ["k1"], ["a1", "a2"])
8285
end
83-
84-
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), ["k1"])
85-
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), ["k1"], ["a1", "a2"])
8686
end
8787

8888
def test_evalsha_with_options_hash
89-
target_version "2.5.9" # 2.6-rc1
89+
target_version "2.5.9" do # 2.6-rc1
90+
assert_raises(Redis::Distributed::CannotDistribute) do
91+
r.evalsha(to_sha("return #KEYS"), {})
92+
end
9093

91-
assert_raises(Redis::Distributed::CannotDistribute) do
92-
r.evalsha(to_sha("return #KEYS"), {})
93-
end
94+
assert_raises(Redis::Distributed::CannotDistribute) do
95+
r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
96+
end
9497

95-
assert_raises(Redis::Distributed::CannotDistribute) do
96-
r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
98+
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1"] })
99+
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :keys => ["k1"], :argv => ["a1", "a2"] })
97100
end
98-
99-
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1"] })
100-
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :keys => ["k1"], :argv => ["a1", "a2"] })
101101
end
102102
end

test/helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ def assert_in_range(range, value)
156156
end
157157

158158
def target_version(target)
159-
skip("Requires Redis > #{target}") if version < target
159+
if version < target
160+
skip("Requires Redis > #{target}") if respond_to?(:skip)
161+
else
162+
yield
163+
end
160164
end
161165
end
162166

test/internals_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ def test_tcp_keepalive
128128
end
129129

130130
def test_time
131-
target_version "2.5.4"
131+
target_version "2.5.4" do
132+
# Test that the difference between the time that Ruby reports and the time
133+
# that Redis reports is minimal (prevents the test from being racy).
134+
rv = r.time
132135

133-
# Test that the difference between the time that Ruby reports and the time
134-
# that Redis reports is minimal (prevents the test from being racy).
135-
rv = r.time
136+
redis_usec = rv[0] * 1_000_000 + rv[1]
137+
ruby_usec = Integer(Time.now.to_f * 1_000_000)
136138

137-
redis_usec = rv[0] * 1_000_000 + rv[1]
138-
ruby_usec = Integer(Time.now.to_f * 1_000_000)
139-
140-
assert 500_000 > (ruby_usec - redis_usec).abs
139+
assert 500_000 > (ruby_usec - redis_usec).abs
140+
end
141141
end
142142

143143
def test_connection_timeout

test/lint/hashes.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ def test_hdel
3131
end
3232

3333
def test_variadic_hdel
34-
target_version "2.3.9"
34+
target_version "2.3.9" do
35+
r.hset("foo", "f1", "s1")
36+
r.hset("foo", "f2", "s2")
3537

36-
r.hset("foo", "f1", "s1")
37-
r.hset("foo", "f2", "s2")
38-
39-
assert_equal "s1", r.hget("foo", "f1")
40-
assert_equal "s2", r.hget("foo", "f2")
38+
assert_equal "s1", r.hget("foo", "f1")
39+
assert_equal "s2", r.hget("foo", "f2")
4140

42-
assert_equal 2, r.hdel("foo", ["f1", "f2"])
41+
assert_equal 2, r.hdel("foo", ["f1", "f2"])
4342

44-
assert_equal nil, r.hget("foo", "f1")
45-
assert_equal nil, r.hget("foo", "f2")
43+
assert_equal nil, r.hget("foo", "f1")
44+
assert_equal nil, r.hget("foo", "f2")
45+
end
4646
end
4747

4848
def test_hexists
@@ -144,19 +144,19 @@ def test_hincrby
144144
end
145145

146146
def test_hincrbyfloat
147-
target_version "2.5.4"
147+
target_version "2.5.4" do
148+
r.hincrbyfloat("foo", "f1", 1.23)
148149

149-
r.hincrbyfloat("foo", "f1", 1.23)
150+
assert_equal "1.23", r.hget("foo", "f1")
150151

151-
assert_equal "1.23", r.hget("foo", "f1")
152+
r.hincrbyfloat("foo", "f1", 0.77)
152153

153-
r.hincrbyfloat("foo", "f1", 0.77)
154+
assert_equal "2", r.hget("foo", "f1")
154155

155-
assert_equal "2", r.hget("foo", "f1")
156+
r.hincrbyfloat("foo", "f1", -0.1)
156157

157-
r.hincrbyfloat("foo", "f1", -0.1)
158-
159-
assert_equal "1.9", r.hget("foo", "f1")
158+
assert_equal "1.9", r.hget("foo", "f1")
159+
end
160160
end
161161
end
162162
end

0 commit comments

Comments
 (0)