Skip to content

Commit 173aecc

Browse files
committed
Style/EachForSimpleLoop: Use Integer#times for a simple loop which iterates a fixed number of times.
1 parent 6bc083a commit 173aecc

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

test/redis_client/test_cluster.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_inspect
2929
def test_call
3030
assert_raises(ArgumentError) { @client.call }
3131

32-
(0..9).each do |i|
32+
10.times do |i|
3333
assert_equal('OK', @client.call('SET', "key#{i}", i), "Case: SET: key#{i}")
3434
wait_for_replication
3535
assert_equal(i.to_s, @client.call('GET', "key#{i}"), "Case: GET: key#{i}")
@@ -44,7 +44,7 @@ def test_call
4444
def test_call_once
4545
assert_raises(ArgumentError) { @client.call_once }
4646

47-
(0..9).each do |i|
47+
10.times do |i|
4848
assert_equal('OK', @client.call_once('SET', "key#{i}", i), "Case: SET: key#{i}")
4949
wait_for_replication
5050
assert_equal(i.to_s, @client.call_once('GET', "key#{i}"), "Case: GET: key#{i}")
@@ -72,7 +72,7 @@ def test_blocking_call
7272
def test_scan
7373
assert_raises(ArgumentError) { @client.scan }
7474

75-
(0..9).each { |i| @client.call('SET', "key#{i}", i) }
75+
10.times { |i| @client.call('SET', "key#{i}", i) }
7676
wait_for_replication
7777
want = (0..9).map { |i| "key#{i}" }
7878
got = []
@@ -81,8 +81,8 @@ def test_scan
8181
end
8282

8383
def test_sscan
84-
(0..9).each do |i|
85-
(0..9).each { |j| @client.call('SADD', "key#{i}", "member#{j}") }
84+
10.times do |i|
85+
10.times { |j| @client.call('SADD', "key#{i}", "member#{j}") }
8686
wait_for_replication
8787
want = (0..9).map { |j| "member#{j}" }
8888
got = []
@@ -92,8 +92,8 @@ def test_sscan
9292
end
9393

9494
def test_hscan
95-
(0..9).each do |i|
96-
(0..9).each { |j| @client.call('HSET', "key#{i}", "field#{j}", j) }
95+
10.times do |i|
96+
10.times { |j| @client.call('HSET', "key#{i}", "field#{j}", j) }
9797
wait_for_replication
9898
want = (0..9).map { |j| "field#{j}" }
9999
got = []
@@ -103,8 +103,8 @@ def test_hscan
103103
end
104104

105105
def test_zscan
106-
(0..9).each do |i|
107-
(0..9).each { |j| @client.call('ZADD', "key#{i}", j, "member#{j}") }
106+
10.times do |i|
107+
10.times { |j| @client.call('ZADD', "key#{i}", j, "member#{j}") }
108108
wait_for_replication
109109
want = (0..9).map { |j| "member#{j}" }
110110
got = []
@@ -118,18 +118,18 @@ def test_pipelined
118118

119119
want = (0..9).map { 'OK' } + (1..3).to_a + %w[PONG] + (0..9).map(&:to_s) + [%w[list 2]]
120120
got = @client.pipelined do |pipeline|
121-
(0..9).each { |i| pipeline.call('SET', "string#{i}", i) }
122-
(0..2).each { |i| pipeline.call('RPUSH', 'list', i) }
121+
10.times { |i| pipeline.call('SET', "string#{i}", i) }
122+
3.times { |i| pipeline.call('RPUSH', 'list', i) }
123123
pipeline.call_once('PING')
124-
(0..9).each { |i| pipeline.call('GET', "string#{i}") }
124+
10.times { |i| pipeline.call('GET', "string#{i}") }
125125
pipeline.blocking_call(0.2, 'BRPOP', 'list', '0.1')
126126
end
127127

128128
assert_equal(want, got)
129129
end
130130

131131
def test_pubsub
132-
(0..9).each do |i|
132+
10.times do |i|
133133
pubsub = @client.pubsub
134134
pubsub.call('SUBSCRIBE', "channel#{i}")
135135
assert_equal(['subscribe', "channel#{i}", 1], pubsub.next_event(0.1))
@@ -154,7 +154,7 @@ def test_close
154154
end
155155

156156
def test_dedicated_commands
157-
(0..9).each { |i| @client.call('SET', "key#{i}", i) }
157+
10.times { |i| @client.call('SET', "key#{i}", i) }
158158
wait_for_replication
159159
[
160160
{ command: %w[ACL HELP], is_a: Array },

0 commit comments

Comments
 (0)