Sha256: 638a8faf8f6c4b32bb76caa2bbf7843bba5cd8c001df5e215b45cd7cc4d58dcc
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Ensure that subject is defined using subject helper. # # @example # # bad # let(:subject) { foo } # let!(:subject) { foo } # subject(:subject) { foo } # subject!(:subject) { foo } # # # bad # block = -> {} # let(:subject, &block) # # # good # subject(:test_subject) { foo } # class SubjectDeclaration < Base MSG_LET = 'Use subject explicitly rather than using let' MSG_REDUNDANT = 'Ambiguous declaration of subject' # @!method offensive_subject_declaration?(node) def_node_matcher :offensive_subject_declaration?, <<~PATTERN (send nil? ${#Subjects.all #Helpers.all} {(sym :subject) (str "subject")} ...) PATTERN def on_send(node) offense = offensive_subject_declaration?(node) return unless offense add_offense(node, message: message_for(offense)) end private def message_for(offense) Helpers.all(offense) ? MSG_LET : MSG_REDUNDANT end end end end end
Version data entries
5 entries across 5 versions & 2 rubygems