lib/rubocop/cop/rspec/repeated_description.rb in rubocop-rspec-2.14.2 vs lib/rubocop/cop/rspec/repeated_description.rb in rubocop-rspec-2.15.0

- old
+ new

@@ -43,32 +43,55 @@ MSG = "Don't repeat descriptions within an example group." def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return unless example_group?(node) - repeated_descriptions(node).each do |repeated_description| - add_offense(repeated_description) + repeated_descriptions(node).each do |description| + add_offense(description) end + + repeated_its(node).each do |its| + add_offense(its) + end end private # Select examples in the current scope with repeated description strings def repeated_descriptions(node) grouped_examples = RuboCop::RSpec::ExampleGroup.new(node) .examples + .reject { |n| n.definition.method?(:its) } .group_by { |example| example_signature(example) } grouped_examples .select { |signatures, group| signatures.any? && group.size > 1 } .values .flatten .map(&:definition) end + def repeated_its(node) + grouped_its = + RuboCop::RSpec::ExampleGroup.new(node) + .examples + .select { |n| n.definition.method?(:its) } + .group_by { |example| its_signature(example) } + + grouped_its + .select { |signatures, group| signatures.any? && group.size > 1 } + .values + .flatten + .map(&:to_node) + end + def example_signature(example) [example.metadata, example.doc_string] + end + + def its_signature(example) + [example.doc_string, example] end end end end end