Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
FC054, check for mismatched cookbook names
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Sawicki committed Apr 13, 2015
1 parent fcb8aae commit df3c890
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
@@ -0,0 +1,15 @@
Feature: Name should match cookbook dir name in metadata

In order to avoid complications where a cookbook repository name differs from the cookbook name
As a developer
I want to set the cookbook name within the metadata

Scenario: Name mismatched in metadata
Given a cookbook with metadata that includes a mismatched cookbook name
When I check the cookbook
Then the name should match cookbook dir name warning 054 should be displayed against the metadata file

Scenario: Name mismatched in metadata
Given a cookbook with metadata that includes a matched cookbook name
When I check the cookbook
Then the name should match cookbook dir name warning 054 should not be displayed against the metadata file
9 changes: 9 additions & 0 deletions features/step_definitions/cookbook_steps.rb
Expand Up @@ -1321,6 +1321,15 @@ def in_tier?(*tier)
}
end

Given /^a cookbook with metadata that includes a (matched|mismatched) cookbook name$/ do |match|
write_metadata %Q{
name 'example'
} if match == 'matched'
write_metadata %Q{
name 'bogart'
} if match == 'mismatched'
end

Given /^a directory that contains a role file ([^ ]+) in (json|ruby) that defines role name (.*)$/ do |file_name, format, role_name|
role(:role_name => %Q{"#{role_name}"}, :file_name => file_name, :format => format.to_sym)
end
Expand Down
1 change: 1 addition & 0 deletions features/support/command_helpers.rb
Expand Up @@ -64,6 +64,7 @@ def assertions
'FC051' => 'Template partials loop indefinitely',
'FC052' => 'Metadata uses the unimplemented "suggests" keyword',
'FC053' => 'Metadata uses the unimplemented "recommends" keyword',
'FC054' => 'Name should match cookbook dir name in metadata',
'FCTEST001' => 'Test Rule'
}

Expand Down
10 changes: 10 additions & 0 deletions lib/foodcritic/rules.rb
Expand Up @@ -769,3 +769,13 @@ def invalid_name(ast)
ast.xpath(%Q(//command[ident/@value='recommends']))
end
end

rule 'FC054', 'Name should match cookbook dir name in metadata' do
tags %w(annoyances metadata)
applies_to { |version| version >= gem_version('12.0.0') }
metadata do |ast, filename|
unless cookbook_name(filename) == filename.split(File::SEPARATOR)[-2]
[file_match(filename)]
end
end
end

0 comments on commit df3c890

Please sign in to comment.