Sha256: f0c5dc4b2d850a64be48bbef7ba5f51fc4542cb215ffcb9fe8387513340d3f84

Contents?: true

Size: 1.51 KB

Versions: 18

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Description should be descriptive.
      #
      # If example group or example contains only `execute string`, numbers
      # and regular expressions, the description is not clear.
      #
      # @example
      #   # bad
      #   describe `time` do
      #    # ...
      #   end
      #
      #   # bad
      #   context /when foo/ do
      #     # ...
      #   end
      #
      #   # bad
      #   it 10000 do
      #     # ...
      #   end
      #
      #   # good
      #   describe Foo do
      #     # ...
      #   end
      #
      #   # good
      #   describe '#foo' do
      #     # ...
      #   end
      #
      #   # good
      #   context "when #{foo} is bar" do
      #     # ...
      #   end
      #
      #   # good
      #   it 'does something' do
      #     # ...
      #   end
      #
      class UndescriptiveLiteralsDescription < Base
        MSG = 'Description should be descriptive.'

        # @!method example_groups_or_example?(node)
        def_node_matcher :example_groups_or_example?, <<~PATTERN
          (block (send #rspec? {#ExampleGroups.all #Examples.all} $_) ...)
        PATTERN

        def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
          example_groups_or_example?(node) do |arg|
            add_offense(arg) if offense?(arg)
          end
        end

        private

        def offense?(node)
          %i[xstr int regexp].include?(node.type)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 4 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/undescriptive_literals_description.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/undescriptive_literals_description.rb