lib/rubocop/cop/rspec/scattered_setup.rb in rubocop-rspec-3.0.1 vs lib/rubocop/cop/rspec/scattered_setup.rb in rubocop-rspec-3.0.2
- old
+ new
@@ -21,10 +21,11 @@
# setup2
# end
# end
#
class ScatteredSetup < Base
+ include FinalEndLocation
include RangeHelp
extend AutoCorrector
MSG = 'Do not define multiple `%<hook_name>s` hooks in the same ' \
'example group (also defined on %<lines>s).'
@@ -73,11 +74,16 @@
end
def autocorrect(corrector, first_occurrence, occurrence)
return if first_occurrence == occurrence || !first_occurrence.body
+ # Take heredocs into account
+ body = occurrence.body&.source_range&.with(
+ end_pos: final_end_location(occurrence).begin_pos
+ )
+
corrector.insert_after(first_occurrence.body,
- "\n#{occurrence.body&.source}")
+ "\n#{body&.source}")
corrector.remove(range_by_whole_lines(occurrence.source_range,
include_final_newline: true))
end
end
end