Skip to content

Commit

Permalink
Add project specs for config/default.yml
Browse files Browse the repository at this point in the history
This PR imports several project specs from RuboCop core.
  • Loading branch information
renawatson68 committed Apr 12, 2020
1 parent f4711ef commit 19d7446
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/default.yml
Expand Up @@ -92,15 +92,15 @@ Performance/EndWith:
VersionChanged: '0.44'

Performance/FixedSize:
Description: 'Do not compute the size of statically sized objects except in constants'
Description: 'Do not compute the size of statically sized objects except in constants.'
Enabled: true
VersionAdded: '0.35'

Performance/FlatMap:
Description: >-
Use `Enumerable#flat_map`
instead of `Enumerable#map...Array#flatten(1)`
or `Enumberable#collect..Array#flatten(1)`
or `Enumberable#collect..Array#flatten(1)`.
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code'
Enabled: true
VersionAdded: '0.30'
Expand All @@ -111,7 +111,7 @@ Performance/FlatMap:
# `flatten` without any parameters can flatten multiple levels.

Performance/InefficientHashSearch:
Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`'
Description: 'Use `key?` or `value?` instead of `keys.include?` or `values.include?`.'
Reference: 'https://github.com/JuanitoFatas/fast-ruby#hashkey-instead-of-hashkeysinclude-code'
Enabled: true
VersionAdded: '0.56'
Expand Down
75 changes: 75 additions & 0 deletions spec/project_spec.rb
@@ -1,6 +1,81 @@
# frozen_string_literal: true

RSpec.describe 'RuboCop Performance Project', type: :feature do
describe 'default configuration file' do
subject(:config) { RuboCop::ConfigLoader.load_file('config/default.yml') }

let(:registry) { RuboCop::Cop::Cop.registry }
let(:cop_names) do
registry.with_department(:Performance).cops.map(&:cop_name)
end

let(:configuration_keys) { config.keys }

it 'has a nicely formatted description for all cops' do
cop_names.each do |name|
description = config[name]['Description']
expect(description.nil?).to be(false)
expect(description).not_to include("\n")
end
end

it 'requires a nicely formatted `VersionAdded` metadata for all cops' do
cop_names.each do |name|
version = config[name]['VersionAdded']
expect(version.nil?).to(be(false),
"VersionAdded is required for #{name}.")
expect(version).to(match(/\A\d+\.\d+\z/),
"#{version} should be format ('X.Y') for #{name}.")
end
end

it 'have a period at EOL of description' do
cop_names.each do |name|
description = config[name]['Description']

expect(description).to match(/\.\z/)
end
end

it 'sorts configuration keys alphabetically' do
expected = configuration_keys.sort
configuration_keys.each_with_index do |key, idx|
expect(key).to eq expected[idx]
end
end

it 'has a SupportedStyles for all EnforcedStyle ' \
'and EnforcedStyle is valid' do
errors = []
cop_names.each do |name|
enforced_styles = config[name]
.select { |key, _| key.start_with?('Enforced') }
enforced_styles.each do |style_name, style|
supported_key = RuboCop::Cop::Util.to_supported_styles(style_name)
valid = config[name][supported_key]
unless valid
errors.push("#{supported_key} is missing for #{name}")
next
end
next if valid.include?(style)

errors.push("invalid #{style_name} '#{style}' for #{name} found")
end
end

raise errors.join("\n") unless errors.empty?
end

it 'does not have nay duplication' do
fname = File.expand_path('../config/default.yml', __dir__)
content = File.read(fname)
RuboCop::YAMLDuplicationChecker.check(content, fname) do |key1, key2|
raise "#{fname} has duplication of #{key1.value} " \
"on line #{key1.start_line} and line #{key2.start_line}"
end
end
end

describe 'changelog' do
subject(:changelog) do
path = File.join(File.dirname(__FILE__), '..', 'CHANGELOG.md')
Expand Down

0 comments on commit 19d7446

Please sign in to comment.