lib/rubocop/cop/rspec/describe_class.rb in rubocop-rspec-1.38.1 vs lib/rubocop/cop/rspec/describe_class.rb in rubocop-rspec-1.39.0
- old
+ new
@@ -10,12 +10,17 @@
# describe 'Do something' do
# end
#
# # good
# describe TestedClass do
+ # subject { described_class }
# end
#
+ # describe 'TestedClass::VERSION' do
+ # subject { Object.const_get(self.class.description) }
+ # end
+ #
# describe "A feature example", type: :feature do
# end
class DescribeClass < Cop
include RuboCop::RSpec::TopLevelDescribe
@@ -42,15 +47,23 @@
)
PATTERN
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern
- def on_top_level_describe(node, args)
+ def on_top_level_describe(node, (described_value, _))
return if shared_group?(root_node)
return if valid_describe?(node)
return if describe_with_rails_metadata?(node)
+ return if string_constant_describe?(described_value)
- add_offense(args.first)
+ add_offense(described_value)
+ end
+
+ private
+
+ def string_constant_describe?(described_value)
+ described_value.str_type? &&
+ described_value.value =~ /^((::)?[A-Z]\w*)+$/
end
end
end
end
end