Sha256: e46de4a4c3306c7a7e35b97c0b8d1be5d8eb993663aa5a4ce8e216f1878b7b1f
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 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 # 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_metadata, <<-PATTERN (send #{RSPEC} :describe !const ... (hash $...)) 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, args) return if shared_group?(root_node) return if valid_describe?(node) describe_with_metadata(node) do |pairs| return if pairs.any?(&method(:rails_metadata?)) end add_offense(args.first) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.35.0 | lib/rubocop/cop/rspec/describe_class.rb |
rubocop-rspec-1.34.1 | lib/rubocop/cop/rspec/describe_class.rb |
rubocop-rspec-1.34.0 | lib/rubocop/cop/rspec/describe_class.rb |