lib/rubocop/cop/rspec/multiple_subjects.rb in rubocop-rspec-2.12.1 vs lib/rubocop/cop/rspec/multiple_subjects.rb in rubocop-rspec-2.13.0
- old
+ new
@@ -4,11 +4,10 @@
module Cop
module RSpec
# Checks if an example group defines `subject` multiple times.
#
# @example
- #
# # bad
# describe Foo do
# subject(:user) { User.new }
# subject(:post) { Post.new }
# end
@@ -17,10 +16,25 @@
# describe Foo do
# let(:user) { User.new }
# subject(:post) { Post.new }
# end
#
+ # # bad (does not support autocorrection)
+ # describe Foo do
+ # subject!(:user) { User.new }
+ # subject!(:post) { Post.new }
+ # end
+ #
+ # # good
+ # describe Foo do
+ # before do
+ # User.new
+ # Post.new
+ # end
+ # end
+ #
+ # This cop does not support autocorrection in some cases.
# The autocorrect behavior for this cop depends on the type of
# duplication:
#
# - If multiple named subjects are defined then this probably indicates
# that the overwritten subjects (all subjects except the last
@@ -31,16 +45,17 @@
# be dead code and we remove the overwritten subject definitions.
#
# - If subjects are defined with `subject!` then we don't autocorrect.
# This is enough of an edge case that people can just move this to
# a `before` hook on their own
+ #
class MultipleSubjects < Base
extend AutoCorrector
include RangeHelp
MSG = 'Do not set more than one subject per example group'
- def on_block(node)
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
return unless example_group?(node)
subjects = RuboCop::RSpec::ExampleGroup.new(node).subjects
subjects[0...-1].each do |subject|