Skip to content

Commit bab0c09

Browse files
committed
style(rubocop): Minitest safe autocorrections
1 parent 8ea5350 commit bab0c09

13 files changed

+118
-47
lines changed

.rubocop.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require:
44
- standard-custom
55
- standard-performance
66
- rubocop-performance
7+
- rubocop-minitest
78

89
inherit_gem:
910
standard: config/base.yml
@@ -13,3 +14,72 @@ inherit_gem:
1314
AllCops:
1415
SuggestExtensions: false
1516
TargetRubyVersion: 3.0
17+
18+
Minitest/AssertInDelta: # new in 0.10
19+
Enabled: true
20+
Minitest/AssertKindOf: # new in 0.10
21+
Enabled: true
22+
Minitest/AssertOperator: # new in 0.32
23+
Enabled: true
24+
Minitest/AssertOutput: # new in 0.10
25+
Enabled: true
26+
Minitest/AssertPathExists: # new in 0.10
27+
Enabled: true
28+
Minitest/AssertPredicate: # new in 0.18
29+
Enabled: true
30+
Minitest/AssertRaisesCompoundBody: # new in 0.21
31+
Enabled: true
32+
Minitest/AssertRaisesWithRegexpArgument: # new in 0.22
33+
Enabled: true
34+
Minitest/AssertSame: # new in 0.26
35+
Enabled: true
36+
Minitest/AssertSilent: # new in 0.10
37+
Enabled: true
38+
Minitest/AssertWithExpectedArgument: # new in 0.11
39+
Enabled: true
40+
Minitest/AssertionInLifecycleHook: # new in 0.10
41+
Enabled: true
42+
Minitest/DuplicateTestRun: # new in 0.19
43+
Enabled: true
44+
Minitest/EmptyLineBeforeAssertionMethods: # new in 0.23
45+
Enabled: false
46+
Minitest/LifecycleHooksOrder: # new in 0.28
47+
Enabled: true
48+
Minitest/LiteralAsActualArgument: # new in 0.10
49+
Enabled: true
50+
Minitest/MultipleAssertions: # new in 0.10
51+
Enabled: true
52+
Minitest/NonExecutableTestMethod: # new in 0.34
53+
Enabled: true
54+
Minitest/NonPublicTestMethod: # new in 0.27
55+
Enabled: true
56+
Minitest/RedundantMessageArgument: # new in 0.34
57+
Enabled: true
58+
Minitest/RefuteInDelta: # new in 0.10
59+
Enabled: true
60+
Minitest/RefuteKindOf: # new in 0.10
61+
Enabled: true
62+
Minitest/RefuteOperator: # new in 0.32
63+
Enabled: true
64+
Minitest/RefutePathExists: # new in 0.10
65+
Enabled: true
66+
Minitest/RefutePredicate: # new in 0.18
67+
Enabled: true
68+
Minitest/RefuteSame: # new in 0.26
69+
Enabled: true
70+
Minitest/ReturnInTestMethod: # new in 0.31
71+
Enabled: true
72+
Minitest/SkipEnsure: # new in 0.20
73+
Enabled: true
74+
Minitest/SkipWithoutReason: # new in 0.24
75+
Enabled: true
76+
Minitest/TestFileName: # new in 0.26
77+
Enabled: true
78+
Minitest/TestMethodName: # new in 0.10
79+
Enabled: true
80+
Minitest/UnreachableAssertion: # new in 0.14
81+
Enabled: true
82+
Minitest/UnspecifiedException: # new in 0.10
83+
Enabled: true
84+
Minitest/UselessAssertion: # new in 0.26
85+
Enabled: true

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ group :development do
1414

1515
gem "rubocop", require: false
1616
gem "standardrb", require: false
17+
gem "rubocop-minitest", require: false
1718
end

test/test_database.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,16 @@ def test_execute_batch2
150150
INSERT INTO items (name) VALUES ("bar");
151151
SELECT * FROM items;
152152
EOSQL
153-
assert_equal return_value, [{"id" => "1", "name" => "foo"}, {"id" => "2", "name" => "bar"}]
153+
assert_equal [{"id" => "1", "name" => "foo"}, {"id" => "2", "name" => "bar"}], return_value
154154

155155
return_value = @db.execute_batch2("SELECT * FROM items;") do |result|
156156
result["id"] = result["id"].to_i
157157
result
158158
end
159-
assert_equal return_value, [{"id" => 1, "name" => "foo"}, {"id" => 2, "name" => "bar"}]
159+
assert_equal [{"id" => 1, "name" => "foo"}, {"id" => 2, "name" => "bar"}], return_value
160160

161161
return_value = @db.execute_batch2('INSERT INTO items (name) VALUES ("oof")')
162-
assert_equal return_value, []
162+
assert_empty return_value
163163

164164
return_value = @db.execute_batch2(
165165
'CREATE TABLE employees (id integer PRIMARY KEY AUTOINCREMENT, name string, age integer(3));
@@ -171,10 +171,10 @@ def test_execute_batch2
171171
result["age"] = result["age"].to_i
172172
result
173173
end
174-
assert_equal return_value, [{"age" => 30}, {"age" => 40}, {"age" => 20}]
174+
assert_equal [{"age" => 30}, {"age" => 40}, {"age" => 20}], return_value
175175

176176
return_value = @db.execute_batch2("SELECT name FROM employees")
177-
assert_equal return_value, [{"name" => nil}, {"name" => nil}, {"name" => nil}]
177+
assert_equal [{"name" => nil}, {"name" => nil}, {"name" => nil}], return_value
178178

179179
@db.results_as_hash = false
180180
return_value = @db.execute_batch2(
@@ -188,7 +188,7 @@ def test_execute_batch2
188188
end
189189
result
190190
end
191-
assert_equal return_value, [[1, 50], [2, 60]]
191+
assert_equal [[1, 50], [2, 60]], return_value
192192

193193
assert_raises(RuntimeError) do
194194
# "names" is not a valid column
@@ -246,7 +246,7 @@ def test_new_with_options
246246
def test_close
247247
db = SQLite3::Database.new(":memory:")
248248
db.close
249-
assert db.closed?
249+
assert_predicate db, :closed?
250250
end
251251

252252
def test_block_closes_self
@@ -255,7 +255,7 @@ def test_block_closes_self
255255
thing = db
256256
assert !thing.closed?
257257
end
258-
assert thing.closed?
258+
assert_predicate thing, :closed?
259259
end
260260

261261
def test_open_with_block_closes_self
@@ -264,7 +264,7 @@ def test_open_with_block_closes_self
264264
thing = db
265265
assert !thing.closed?
266266
end
267-
assert thing.closed?
267+
assert_predicate thing, :closed?
268268
end
269269

270270
def test_block_closes_self_even_raised
@@ -276,7 +276,7 @@ def test_block_closes_self_even_raised
276276
end
277277
rescue
278278
end
279-
assert thing.closed?
279+
assert_predicate thing, :closed?
280280
end
281281

282282
def test_open_with_block_closes_self_even_raised
@@ -288,7 +288,7 @@ def test_open_with_block_closes_self_even_raised
288288
end
289289
rescue
290290
end
291-
assert thing.closed?
291+
assert_predicate thing, :closed?
292292
end
293293

294294
def test_prepare

test/test_database_flags.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_open_database_flags_constants
2828
if SQLite3::SQLITE_VERSION_NUMBER > 3007013
2929
defined_to_date += [:MEMORY]
3030
end
31-
assert defined_to_date.sort == SQLite3::Constants::Open.constants.sort
31+
assert_equal defined_to_date.sort, SQLite3::Constants::Open.constants.sort
3232
end
3333

3434
def test_open_database_flags_conflicts_with_readonly
@@ -45,7 +45,7 @@ def test_open_database_flags_conflicts_with_readwrite
4545

4646
def test_open_database_readonly_flags
4747
@db = SQLite3::Database.new("test-flags.db", flags: SQLite3::Constants::Open::READONLY)
48-
assert @db.readonly?
48+
assert_predicate @db, :readonly?
4949
end
5050

5151
def test_open_database_readwrite_flags
@@ -81,15 +81,15 @@ def test_open_database_create_flags
8181
db.execute("CREATE TABLE foos (id integer)")
8282
db.execute("INSERT INTO foos (id) VALUES (12)")
8383
end
84-
assert File.exist?("test-flags.db")
84+
assert_path_exists "test-flags.db"
8585
end
8686

8787
def test_open_database_exotic_flags
8888
flags = SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE
8989
exotic_flags = SQLite3::Constants::Open::NOMUTEX | SQLite3::Constants::Open::TEMP_DB
9090
@db = SQLite3::Database.new("test-flags.db", flags: flags | exotic_flags)
9191
@db.execute("INSERT INTO foos (id) VALUES (12)")
92-
assert @db.changes == 1
92+
assert_equal 1, @db.changes
9393
end
9494
end
9595
end

test/test_database_readonly.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def teardown
1616

1717
def test_open_readonly_database
1818
@db = SQLite3::Database.new("test-readonly.db", readonly: true)
19-
assert @db.readonly?
19+
assert_predicate @db, :readonly?
2020
end
2121

2222
def test_open_readonly_not_exists_database

test/test_database_readwrite.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_open_readwrite_not_exists_database
3535
def test_insert_readwrite_database
3636
@db = SQLite3::Database.new("test-readwrite.db", readwrite: true)
3737
@db.execute("INSERT INTO foos (id) VALUES (12)")
38-
assert @db.changes == 1
38+
assert_equal 1, @db.changes
3939
end
4040
end
4141
end

test/test_integration.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_authorizer_error
9898
def test_authorizer_silent
9999
@db.authorizer { |type, a, b, c, d| 2 }
100100
rows = @db.execute "select * from foo"
101-
assert rows.empty?
101+
assert_empty rows
102102
end
103103

104104
def test_prepare_invalid_syntax
@@ -121,22 +121,22 @@ def test_prepare_invalid_table
121121

122122
def test_prepare_no_block
123123
stmt = @db.prepare "select * from foo"
124-
assert stmt.respond_to?(:execute)
124+
assert_respond_to stmt, :execute
125125
stmt.close
126126
end
127127

128128
def test_prepare_with_block
129129
called = false
130130
@db.prepare "select * from foo" do |stmt|
131131
called = true
132-
assert stmt.respond_to?(:execute)
132+
assert_respond_to stmt, :execute
133133
end
134134
assert called
135135
end
136136

137137
def test_execute_no_block_no_bind_no_match
138138
rows = @db.execute("select * from foo where a > 100")
139-
assert rows.empty?
139+
assert_empty rows
140140
end
141141

142142
def test_execute_with_block_no_bind_no_match
@@ -149,7 +149,7 @@ def test_execute_with_block_no_bind_no_match
149149

150150
def test_execute_no_block_with_bind_no_match
151151
rows = @db.execute("select * from foo where a > ?", 100)
152-
assert rows.empty?
152+
assert_empty rows
153153
end
154154

155155
def test_execute_with_block_with_bind_no_match
@@ -188,7 +188,7 @@ def test_execute_with_block_with_bind_with_match
188188

189189
def test_execute2_no_block_no_bind_no_match
190190
columns, *rows = @db.execute2("select * from foo where a > 100")
191-
assert rows.empty?
191+
assert_empty rows
192192
assert_equal ["a", "b"], columns
193193
end
194194

@@ -203,7 +203,7 @@ def test_execute2_with_block_no_bind_no_match
203203

204204
def test_execute2_no_block_with_bind_no_match
205205
columns, *rows = @db.execute2("select * from foo where a > ?", 100)
206-
assert rows.empty?
206+
assert_empty rows
207207
assert_equal ["a", "b"], columns
208208
end
209209

@@ -285,7 +285,7 @@ def test_query_with_block_no_bind_no_match
285285
assert_nil result.next
286286
r = result
287287
end
288-
assert r.closed?
288+
assert_predicate r, :closed?
289289
end
290290

291291
def test_query_no_block_with_bind_no_match
@@ -300,7 +300,7 @@ def test_query_with_block_with_bind_no_match
300300
assert_nil result.next
301301
r = result
302302
end
303-
assert r.closed?
303+
assert_predicate r, :closed?
304304
end
305305

306306
def test_query_no_block_no_bind_with_match
@@ -317,7 +317,7 @@ def test_query_with_block_no_bind_with_match
317317
assert_nil result.next
318318
r = result
319319
end
320-
assert r.closed?
320+
assert_predicate r, :closed?
321321
end
322322

323323
def test_query_no_block_with_bind_with_match
@@ -334,7 +334,7 @@ def test_query_with_block_with_bind_with_match
334334
assert_nil result.next
335335
r = result
336336
end
337-
assert r.closed?
337+
assert_predicate r, :closed?
338338
end
339339

340340
def test_get_first_row_no_bind_no_match
@@ -464,7 +464,7 @@ def test_transaction_commit_in_block
464464
def test_transaction_active
465465
assert !@db.transaction_active?
466466
@db.transaction
467-
assert @db.transaction_active?
467+
assert_predicate @db, :transaction_active?
468468
@db.commit
469469
assert !@db.transaction_active?
470470
end
@@ -473,7 +473,7 @@ def test_transaction_implicit_rollback
473473
assert !@db.transaction_active?
474474
@db.transaction
475475
@db.execute("create table bar (x CHECK(1 = 0))")
476-
assert @db.transaction_active?
476+
assert_predicate @db, :transaction_active?
477477
assert_raises(SQLite3::ConstraintException) do
478478
@db.execute("insert or rollback into bar (x) VALUES ('x')")
479479
end

test/test_integration_open_close.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class IntegrationOpenCloseTestCase < SQLite3::TestCase
44
def test_create_close
55
db = SQLite3::Database.new("test-create.db")
6-
assert File.exist?("test-create.db")
6+
assert_path_exists "test-create.db"
77
assert_nothing_raised { db.close }
88
ensure
99
begin
@@ -15,7 +15,7 @@ def test_create_close
1515

1616
def test_open_close
1717
File.open("test-open.db", "w") { |f| }
18-
assert File.exist?("test-open.db")
18+
assert_path_exists "test-open.db"
1919
db = SQLite3::Database.new("test-open.db")
2020
assert_nothing_raised { db.close }
2121
ensure

test/test_integration_pending.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ def test_busy_timeout
7272
busy.unlock
7373
t.join
7474

75-
assert time.real * 1000 >= 1000
75+
assert_operator time.real * 1000, :>=, 1000
7676
end
7777
end

0 commit comments

Comments
 (0)