Sha256: 57d42bc94fd07db51c6695cd5f8f053649a157031495567be6551c8d4caafe32
Contents?: true
Size: 1.31 KB
Versions: 2
Compression:
Stored size: 1.31 KB
Contents
# encoding: utf-8 # frozen_string_literal: true module RuboCop module Cop module RSpec # Check that the first argument to the top level describe is the tested # class or module. # # @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 REQUEST_PAIR = s(:pair, s(:sym, :type), s(:sym, :request)) FEATURE_PAIR = s(:pair, s(:sym, :type), s(:sym, :feature)) ROUTING_PAIR = s(:pair, s(:sym, :type), s(:sym, :routing)) VIEW_PAIR = s(:pair, s(:sym, :type), s(:sym, :view)) MESSAGE = 'The first argument to describe should be the class or ' \ 'module being tested.'.freeze def on_top_level_describe(_node, args) return if args[0] && args[0].type == :const return if args[1..-1].any? do |arg| next unless arg.hash_type? arg.children.any? do |n| [REQUEST_PAIR, FEATURE_PAIR, ROUTING_PAIR, VIEW_PAIR].include?(n) end end add_offense(args[0], :expression, MESSAGE) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.5.1 | lib/rubocop/cop/rspec/describe_class.rb |
rubocop-rspec-1.5.0 | lib/rubocop/cop/rspec/describe_class.rb |