lib/rubocop/cop/rspec/predicate_matcher.rb in rubocop-rspec-2.18.1 vs lib/rubocop/cop/rspec/predicate_matcher.rb in rubocop-rspec-2.19.0

- old
+ new

@@ -82,26 +82,26 @@ end # rubocop:enable Metrics/MethodLength def remove_predicate(corrector, predicate) range = predicate.loc.dot.with( - end_pos: predicate.loc.expression.end_pos + end_pos: predicate.source_range.end_pos ) corrector.remove(range) - block_range = block_loc(predicate) + block_range = LocationHelp.block_with_whitespace(predicate) corrector.remove(block_range) if block_range end def rewrite_matcher(corrector, predicate, matcher) - args = args_loc(predicate).source - block_loc = block_loc(predicate) + args = LocationHelp.arguments_with_whitespace(predicate).source + block_loc = LocationHelp.block_with_whitespace(predicate) block = block_loc ? block_loc.source : '' corrector.replace( - matcher.loc.expression, + matcher.source_range, to_predicate_matcher(predicate.method_name) + args + block ) end def true?(to_symbol, matcher) @@ -212,23 +212,23 @@ matcher_name: matcher.method_name) end def corrector_explicit(corrector, to_node, actual, matcher, block_child) replacement_matcher = replacement_matcher(to_node) - corrector.replace(matcher.loc.expression, replacement_matcher) + corrector.replace(matcher.source_range, replacement_matcher) move_predicate(corrector, actual, matcher, block_child) corrector.replace(to_node.loc.selector, 'to') end def move_predicate(corrector, actual, matcher, block_child) predicate = to_predicate_method(matcher.method_name) - args = args_loc(matcher).source - block_loc = block_loc(block_child) + args = LocationHelp.arguments_with_whitespace(matcher).source + block_loc = LocationHelp.block_with_whitespace(block_child) block = block_loc ? block_loc.source : '' corrector.remove(block_loc) if block_loc - corrector.insert_after(actual.loc.expression, + corrector.insert_after(actual.source_range, ".#{predicate}" + args + block) end # rubocop:disable Metrics/MethodLength def to_predicate_method(matcher) @@ -329,34 +329,9 @@ end end def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler check_explicit(node) if style == :explicit - end - - private - - # returns args location with whitespace - # @example - # foo 1, 2 - # ^^^^^ - def args_loc(send_node) - send_node.loc.selector.end.with( - end_pos: send_node.loc.expression.end_pos - ) - end - - # returns block location with whitespace - # @example - # foo { bar } - # ^^^^^^^^ - def block_loc(send_node) - parent = send_node.parent - return unless parent.block_type? - - send_node.loc.expression.end.with( - end_pos: parent.loc.expression.end_pos - ) end end end end end