lib/rubocop/cop/rspec/repeated_description.rb in rubocop-rspec-1.37.1 vs lib/rubocop/cop/rspec/repeated_description.rb in rubocop-rspec-1.38.0
- old
+ new
@@ -27,10 +27,21 @@
# it 'is valid when last name only is present' do
# # ...
# end
# end
#
+ # # good
+ # RSpec.describe User do
+ # it 'is valid' do
+ # # ...
+ # end
+ #
+ # it 'is valid', :flag do
+ # # ...
+ # end
+ # end
+ #
class RepeatedDescription < Cop
MSG = "Don't repeat descriptions within an example group."
def on_block(node)
return unless example_group?(node)
@@ -45,16 +56,20 @@
# Select examples in the current scope with repeated description strings
def repeated_descriptions(node)
grouped_examples =
RuboCop::RSpec::ExampleGroup.new(node)
.examples
- .group_by(&:doc_string)
+ .group_by { |example| example_signature(example) }
grouped_examples
- .select { |description, group| description && group.size > 1 }
+ .select { |signatures, group| signatures.any? && group.size > 1 }
.values
.flatten
.map(&:definition)
+ end
+
+ def example_signature(example)
+ [example.metadata, example.doc_string]
end
end
end
end
end