Method: RuboCop::Cop::RSpec::RepeatedSubjectCall#subject?

Defined in:
lib/rubocop/cop/rspec/repeated_subject_call.rb

#subject?(node) {|Symbol| ... } ⇒ Object

Find a named or unnamed subject definition

Examples:

anonymous subject

subject?(parse('subject { foo }').ast) do |name|
  name # => :subject
end

named subject

subject?(parse('subject(:thing) { foo }').ast) do |name|
  name # => :thing
end

Parameters:

  • node (RuboCop::AST::Node)

Yields:

  • (Symbol)

    subject name

[View source]

53
54
55
56
57
58
# File 'lib/rubocop/cop/rspec/repeated_subject_call.rb', line 53

def_node_matcher :subject?, <<-PATTERN
  (block
    (send nil?
      { #Subjects.all (sym $_) | $#Subjects.all }
    ) args ...)
PATTERN