lib/rubocop/cop/mixin/minitest_cop_rule.rb in rubocop-minitest-0.21.1 vs lib/rubocop/cop/mixin/minitest_cop_rule.rb in rubocop-minitest-0.22.0

- old
+ new

@@ -17,11 +17,13 @@ # @param target_method [Symbol] Method name offensed by assertion method arguments. # @param preferred_method [Symbol] An optional param. Custom method name replaced by # autocorrection. The preferred method name that connects # `assertion_method` and `target_method` with `_` is # the default name. - # @param inverse [Boolean] An optional param. Order of arguments replaced by autocorrection. + # @param inverse [Boolean, String] An optional param. Order of arguments replaced by autocorrection. + # If string is passed, it becomes a predicate method for the first argument node. + # @api private # def define_rule(assertion_method, target_method:, preferred_method: nil, inverse: false) preferred_method = "#{assertion_method}_#{target_method.to_s.delete('?')}" if preferred_method.nil? class_eval(<<~RUBY, __FILE__, __LINE__ + 1) @@ -75,13 +77,18 @@ ) end def new_arguments(arguments) receiver = correct_receiver(arguments.first.receiver) - method_argument = arguments.first.arguments.first&.source + method_argument = arguments.first.arguments.first - new_arguments = [receiver, method_argument].compact - new_arguments.reverse! if #{inverse} + new_arguments = [receiver, method_argument&.source].compact + inverse_condition = if %w[true false].include?('#{inverse}') + #{inverse} + else + method_argument.#{inverse} + end + new_arguments.reverse! if inverse_condition new_arguments end def enclosed_in_redundant_parentheses?(node) node.arguments.first.begin_type?