lib/rubocop/cop/rspec/shared_context.rb in rubocop-rspec-1.41.0 vs lib/rubocop/cop/rspec/shared_context.rb in rubocop-rspec-1.42.0

- old
+ new

@@ -49,10 +49,12 @@ # something # end # end # class SharedContext < Cop + extend AutoCorrector + MSG_EXAMPLES = "Use `shared_examples` when you don't "\ 'define context.' MSG_CONTEXT = "Use `shared_context` when you don't "\ 'define examples.' @@ -66,27 +68,19 @@ def_node_matcher :shared_context, SharedGroups::CONTEXT.block_pattern def_node_matcher :shared_example, SharedGroups::EXAMPLES.block_pattern def on_block(node) context_with_only_examples(node) do - add_shared_item_offense(node.send_node, MSG_EXAMPLES) + add_offense(node.send_node, message: MSG_EXAMPLES) do |corrector| + corrector.replace(node.send_node.loc.selector, 'shared_examples') + end end examples_with_only_context(node) do - add_shared_item_offense(node.send_node, MSG_CONTEXT) - end - end - - def autocorrect(node) - lambda do |corrector| - context_with_only_examples(node.parent) do - corrector.replace(node.loc.selector, 'shared_examples') + add_offense(node.send_node, message: MSG_CONTEXT) do |corrector| + corrector.replace(node.send_node.loc.selector, 'shared_context') end - - examples_with_only_context(node.parent) do - corrector.replace(node.loc.selector, 'shared_context') - end end end private @@ -94,16 +88,9 @@ shared_context(node) { yield if examples?(node) && !context?(node) } end def examples_with_only_context(node) shared_example(node) { yield if context?(node) && !examples?(node) } - end - - def add_shared_item_offense(node, message) - add_offense( - node, - message: message - ) end end end end end