Sha256: fe4ce5c12b092a9634ae3947f8de8bd66f109f38d6901472638af7b577730351
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Check that the first argument to the top level describe is a constant. # # @example # # bad # 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 MSG = 'The first argument to describe should be '\ 'the class or module being tested.' def_node_matcher :valid_describe?, <<-PATTERN { (send #{RSPEC} :describe const ...) (send #{RSPEC} :describe) } PATTERN def_node_matcher :describe_with_rails_metadata?, <<-PATTERN (send #{RSPEC} :describe !const ... (hash <#rails_metadata? ...>) ) PATTERN def_node_matcher :rails_metadata?, <<-PATTERN (pair (sym :type) (sym {:request :feature :system :routing :view}) ) PATTERN def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern 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(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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.40.0 | lib/rubocop/cop/rspec/describe_class.rb |
rubocop-rspec-1.39.0 | lib/rubocop/cop/rspec/describe_class.rb |