From 087e0ccb72e7a1491701dd1d1d49746f745d9d68 Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Tue, 17 Apr 2018 08:37:35 -0400 Subject: Add RuboCop for `assert_not` over `assert !` We added `assert_not` in f75addd "to replace warty 'assert !foo'". fa8d35b agrees that it is warty, and so do I. This custom Rubocop rule turns the wart into a violation. As with my last custom cop, https://github.com/rails/rails/pull/32441, I want to make sure this looks right on code climate before pushing another commit to autocorrect everything. @toshimaru I just noticed https://github.com/toshimaru/rubocop-rails/pull/26 Is there a better way to add these custom cops, or were you saying we shouldn't have custom cops at all? --- ci/custom_cops/test/support/cop_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ci/custom_cops/test/support') diff --git a/ci/custom_cops/test/support/cop_helper.rb b/ci/custom_cops/test/support/cop_helper.rb index d259154df5..c2c6b969dd 100644 --- a/ci/custom_cops/test/support/cop_helper.rb +++ b/ci/custom_cops/test/support/cop_helper.rb @@ -16,6 +16,18 @@ module CopHelper rewrite(cop, processed_source) end + def assert_offense(cop, expected_message) + assert_not_empty( + cop.offenses, + "Expected offense with message \"#{expected_message}\", but got no offense" + ) + + offense = cop.offenses.first + carets = "^" * offense.column_length + + assert_equal expected_message, "#{carets} #{offense.message}" + end + private TARGET_RUBY_VERSION = 2.4 -- cgit v1.2.3