diff --git a/.rubocop.yml b/.rubocop.yml index 227652f9..ca4bbe00 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ plugins: - rubocop-sorbet + - rubocop-minitest inherit_gem: rubocop-shopify: rubocop.yml diff --git a/Gemfile b/Gemfile index ce828ab9..b96492ac 100644 --- a/Gemfile +++ b/Gemfile @@ -12,5 +12,6 @@ group :development do gem "debug" gem "rubocop-shopify", require: false gem "rubocop-sorbet", require: false + gem "rubocop-minitest", require: false gem "tapioca", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 86604ed2..70d8ea2a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,10 @@ GEM rubocop-ast (1.49.0) parser (>= 3.3.7.2) prism (~> 1.7) + rubocop-minitest (0.38.1) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) rubocop-shopify (2.18.0) rubocop (~> 1.62) rubocop-sorbet (0.12.0) @@ -137,6 +141,7 @@ DEPENDENCIES minitest-mock minitest-reporters rake (~> 13.4.2) + rubocop-minitest rubocop-shopify rubocop-sorbet spoom! diff --git a/test/.rubocop.yml b/test/.rubocop.yml new file mode 100644 index 00000000..46a3e0c5 --- /dev/null +++ b/test/.rubocop.yml @@ -0,0 +1,7 @@ +inherit_from: ../.rubocop.yml + +Minitest/AssertPredicate: + Enabled: true + +Minitest/LiteralAsActualArgument: + Enabled: true diff --git a/test/spoom/context/git_test.rb b/test/spoom/context/git_test.rb index 9b49d87e..96359748 100644 --- a/test/spoom/context/git_test.rb +++ b/test/spoom/context/git_test.rb @@ -105,7 +105,7 @@ def test_context_git_commit! res = context.git_commit! assert(res.status) - assert(context.git_workdir_clean?) + assert_predicate(context, :git_workdir_clean?) assert(context.file?("b")) context.destroy! @@ -176,7 +176,7 @@ def test_context_git_last_commit assert(sha.size < 40) sha = T.must(context.git_last_commit(short_sha: false)).sha - assert(sha.size == 40) + assert_equal(40, sha.size) last_commit = context.git_last_commit assert_equal(time.to_i, last_commit&.timestamp) @@ -242,7 +242,7 @@ def test_context_clean_workdir_on_clean_repo context.write!("file") context.git_commit! - assert(context.git_workdir_clean?) + assert_predicate(context, :git_workdir_clean?) context.destroy! end diff --git a/test/spoom/context/sorbet_test.rb b/test/spoom/context/sorbet_test.rb index 6c9cf89f..bea96bbb 100644 --- a/test/spoom/context/sorbet_test.rb +++ b/test/spoom/context/sorbet_test.rb @@ -177,7 +177,7 @@ def test_context_has_sorbet_config refute(context.has_sorbet_config?) context.write_sorbet_config!(".") - assert(context.has_sorbet_config?) + assert_predicate(context, :has_sorbet_config?) context.destroy! end diff --git a/test/spoom/context_test.rb b/test/spoom/context_test.rb index 0920ac2b..50916c1d 100644 --- a/test/spoom/context_test.rb +++ b/test/spoom/context_test.rb @@ -8,7 +8,7 @@ module Sorbet class ContextTest < Minitest::Test def test_context_mktmp! context = Context.mktmp! - assert(context.exist?) + assert_predicate(context, :exist?) context.destroy! end @@ -16,7 +16,7 @@ def test_context_make! context = Context.new("/tmp/spoom-context-test") refute(context.exist?) context.mkdir! - assert(context.exist?) + assert_predicate(context, :exist?) context.destroy! refute(context.exist?) end diff --git a/test/spoom/deadcode/index_references_test.rb b/test/spoom/deadcode/index_references_test.rb index c7342b7d..29c2b213 100644 --- a/test/spoom/deadcode/index_references_test.rb +++ b/test/spoom/deadcode/index_references_test.rb @@ -170,7 +170,7 @@ def foo(&block) when "[]", "!" next else - assert(ref.name =~ /^m(\d+)(=)?$/) + assert_match(/^m(\d+)(=)?$/, ref.name) end end end diff --git a/test/spoom/location_test.rb b/test/spoom/location_test.rb index d022c48e..6127bd63 100644 --- a/test/spoom/location_test.rb +++ b/test/spoom/location_test.rb @@ -71,39 +71,39 @@ def test_raises_if_initialize_has_missing_attributes def test_include location1 = Location.new("foo.rb", start_line: 1, start_column: 2, end_line: 3, end_column: 4) location2 = Location.new("foo.rb", start_line: 1, start_column: 2, end_line: 3, end_column: 4) - assert(location1.include?(location2)) + assert_includes(location1, location2) location3 = Location.new("foo.rb", start_line: 1, start_column: 2, end_line: 3, end_column: 5) - refute(location1.include?(location3)) - assert(location3.include?(location1)) + refute_includes(location1, location3) + assert_includes(location3, location1) location4 = Location.new("foo.rb", start_line: 1, start_column: 2, end_line: 4, end_column: 4) - refute(location1.include?(location4)) - assert(location4.include?(location1)) + refute_includes(location1, location4) + assert_includes(location4, location1) location5 = Location.new("foo.rb", start_line: 1, start_column: 3, end_line: 3, end_column: 4) - assert(location1.include?(location5)) - refute(location5.include?(location1)) + assert_includes(location1, location5) + refute_includes(location5, location1) location6 = Location.new("foo.rb", start_line: 2, start_column: 2, end_line: 3, end_column: 4) - assert(location1.include?(location6)) - refute(location6.include?(location1)) + assert_includes(location1, location6) + refute_includes(location6, location1) location7 = Location.new("bar.rb", start_line: 1, start_column: 2, end_line: 3, end_column: 4) - refute(location1.include?(location7)) - refute(location7.include?(location1)) + refute_includes(location1, location7) + refute_includes(location7, location1) location8 = Location.new("foo.rb") location9 = Location.new("foo.rb") - assert(location8.include?(location9)) - assert(location9.include?(location8)) + assert_includes(location8, location9) + assert_includes(location9, location8) - assert(location8.include?(location1)) - refute(location1.include?(location8)) + assert_includes(location8, location1) + refute_includes(location1, location8) location10 = Location.new("foo.rb", start_line: 1, end_line: 3) - assert(location10.include?(location1)) - refute(location1.include?(location10)) + assert_includes(location10, location1) + refute_includes(location1, location10) end def test_comparison diff --git a/test/spoom/model/references_visitor_test.rb b/test/spoom/model/references_visitor_test.rb index 5090d61c..afaa06b0 100644 --- a/test/spoom/model/references_visitor_test.rb +++ b/test/spoom/model/references_visitor_test.rb @@ -167,7 +167,7 @@ def foo(&block) assert_equal(51, refs.size) # 49 + 2 (including `[]` and `!`) refs.each do |ref| - assert(ref =~ /^(m(\d+)(=)?)|\[\]|!$/) + assert_match(/^(m(\d+)(=)?)|\[\]|!$/, ref) end end diff --git a/test/spoom/sorbet/sigils_test.rb b/test/spoom/sorbet/sigils_test.rb index f076ea24..1972526f 100644 --- a/test/spoom/sorbet/sigils_test.rb +++ b/test/spoom/sorbet/sigils_test.rb @@ -120,7 +120,7 @@ class A; end new_content = Sigils.update_sigil(content, "true") - assert(/^# typed: ignore$/.match?(new_content)) + assert_match(/^# typed: ignore$/, new_content) strictness = Sigils.strictness_in_content(new_content)