Sha256: e918e6be026e9c1f0f8f26067466ffab60f4046bc5fd9608a756b53e7ad744ec

Contents?: true

Size: 1004 Bytes

Versions: 27

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks that spec file paths suffix are consistent and well-formed.
      #
      # @example
      #   # bad
      #   my_class/foo_specorb.rb   # describe MyClass
      #   spec/models/user.rb       # describe User
      #   spec/models/user_specxrb  # describe User
      #
      #   # good
      #   my_class_spec.rb          # describe MyClass
      #
      #   # good - shared examples are allowed
      #   spec/models/user.rb       # shared_examples_for 'foo'
      #
      class SpecFilePathSuffix < Base
        include TopLevelGroup
        include FileHelp

        MSG = 'Spec path should end with `_spec.rb`.'

        def on_top_level_example_group(node)
          example_group?(node) do
            add_global_offense(MSG) unless correct_path?
          end
        end

        private

        def correct_path?
          expanded_file_path.end_with?('_spec.rb')
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 5 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/spec_file_path_suffix.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/spec_file_path_suffix.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/spec_file_path_suffix.rb