Sha256: 4f846a0a085f1bcc559147d812034f0bd03482a145aa54c5586ac7458200fcad

Contents?: true

Size: 1.39 KB

Versions: 6792

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module InternalAffairs
      # Checks that cops are not tested using `described_class::MSG`.
      #
      # @example
      #
      #     # bad
      #     expect(cop.messages).to eq([described_class::MSG])
      #
      #     # good
      #     expect(cop.messages).to eq(['Do not write bad code like that.'])
      #
      class UselessMessageAssertion < Cop
        MSG = 'Do not specify cop behavior using `described_class::MSG`.'.freeze

        def_node_search :described_class_msg, <<-PATTERN
          (const (send nil? :described_class) :MSG)
        PATTERN

        def_node_matcher :rspec_expectation_on_msg?, <<-PATTERN
          (send (send nil? :expect #contains_described_class_msg?) :to ...)
        PATTERN

        def investigate(_processed_source)
          assertions_using_described_class_msg.each do |node|
            add_offense(node)
          end
        end

        private

        def contains_described_class_msg?(node)
          described_class_msg(node).any?
        end

        def assertions_using_described_class_msg
          described_class_msg(processed_source.ast).reject do |node|
            node.ancestors.any?(&method(:rspec_expectation_on_msg?))
          end
        end

        # Only process spec files
        def relevant_file?(file)
          file.end_with?('_spec.rb')
        end
      end
    end
  end
end

Version data entries

6,792 entries across 6,786 versions & 25 rubygems

Version Path
cybrid_api_organization_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_bank_ruby-0.123.123 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.123 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_organization_ruby-0.123.123 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_bank_ruby-0.123.122 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_organization_ruby-0.123.122 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.122 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_bank_ruby-0.123.121 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.121 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_organization_ruby-0.123.121 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_bank_ruby-0.123.120 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_organization_ruby-0.123.120 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.120 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_bank_ruby-0.123.119 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_organization_ruby-0.123.119 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.119 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_bank_ruby-0.123.118 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb
cybrid_api_id_ruby-0.123.118 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb