Skip to content

Commit

Permalink
Use navigation instead of manual deconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Jan 10, 2019
1 parent 995f13a commit 2f5f125
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/rubocop/cop/rspec/aggregate_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,16 @@ def drop_example(corrector, example)
# it needs to be converted to `expect(subject.something).to ...`
# Additionally indents the example code properly.
def transform_body(node, base_indent)
method, _args, body = *node
_receiver, method_name, arguments = *method
new_body = if method_name == :its
transform_its(body, arguments)
new_body = if node.method_name == :its
transform_its(node.body, node.send_node.arguments)
else
body.source
node.body.source
end
"#{base_indent} #{new_body}"
end

def transform_its(body, arguments)
property = arguments.children.first
property = arguments.first.value
body.source.gsub(/is_expected|are_expected/,
"expect(subject.#{property})")
end
Expand Down

0 comments on commit 2f5f125

Please sign in to comment.