lib/rubocop/cop/rspec/leading_subject.rb in rubocop-rspec-1.38.1 vs lib/rubocop/cop/rspec/leading_subject.rb in rubocop-rspec-1.39.0

- old
+ new

@@ -30,12 +30,10 @@ # subject { described_class.new(params) } # it { expect_something } # it { expect_something_else } # class LeadingSubject < Cop - include RangeHelp - MSG = 'Declare `subject` above any other `%<offending>s` declarations.' def on_block(node) return unless subject?(node) && !in_spec_block?(node) @@ -56,14 +54,13 @@ end def autocorrect(node) lambda do |corrector| first_node = find_first_offending_node(node) - first_node_position = first_node.loc.expression - indent = "\n" + ' ' * first_node.loc.column - corrector.insert_before(first_node_position, node.source + indent) - corrector.remove(node_range(node)) + RuboCop::RSpec::Corrector::MoveNode.new( + node, corrector, processed_source + ).move_before(first_node) end end private @@ -71,13 +68,9 @@ let?(node) || hook?(node) || example?(node) end def find_first_offending_node(node) node.parent.children.find { |sibling| offending?(sibling) } - end - - def node_range(node) - range_by_whole_lines(node.source_range, include_final_newline: true) end def in_spec_block?(node) node.each_ancestor(:block).any? do |ancestor| example?(ancestor)