lib/rubocop/cop/rspec/named_subject.rb in rubocop-rspec-1.6.0 vs lib/rubocop/cop/rspec/named_subject.rb in rubocop-rspec-1.7.0

- old
+ new

@@ -1,12 +1,19 @@ # frozen_string_literal: true module RuboCop module Cop module RSpec - # Give `subject` a descriptive name if you reference it directly + # Checks for explicitly referenced test subjects. # + # RSpec lets you declare an "implicit subject" using `subject { ... }` + # which allows for tests like `it { should be_valid }`. If you need to + # reference your test subject you should explicitly name it using + # `subject(:your_subject_name) { ... }`. Your test subjects should be + # the most important object in your tests so they deserve a descriptive + # name. + # # @example # # bad # RSpec.describe User do # subject { described_class.new } # @@ -29,9 +36,11 @@ # subject(:user) { described_class.new } # # it { should be_valid } # end class NamedSubject < Cop + include RuboCop::RSpec::SpecOnly + MSG = 'Name your test subject if '\ 'you need to reference it explicitly.'.freeze def_node_matcher :rspec_block?, <<-PATTERN (block