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

Commit

Permalink
FC007: Exclude recipes w/ embedded expr, refs #44.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Crump committed Jun 7, 2012
1 parent 9ddd384 commit 2c1f170
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
9 changes: 7 additions & 2 deletions features/007_check_for_undeclared_recipe_dependencies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ Feature: Check for undeclared recipe dependencies
When I check the cookbook
Then the undeclared dependency warning 007 should not be displayed

Scenario: Cookbook includes recipe via expression (embedded)
Given a cookbook recipe that includes a recipe name from an embedded expression
Scenario Outline: Cookbook includes recipe via expression (embedded)
Given a cookbook recipe that includes a recipe name from an embedded expression <recipe_expression>
When I check the cookbook
Then the undeclared dependency warning 007 should not be displayed
Examples:
| recipe_expression |
| foo::#{node['foo']['fighter']} |
| #{cookbook_name}::other |
| #{cbk}_other::other |

Scenario: Cookbook includes declared recipe dependency
Given a cookbook recipe that includes a declared recipe dependency
Expand Down
7 changes: 3 additions & 4 deletions features/step_definitions/cookbook_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@
}
end

Given /^a cookbook recipe that includes a recipe name from an( embedded)? expression$/ do |embedded|
Given /^a cookbook recipe that includes a recipe name from an( embedded)? expression(.*)$/ do |embedded, expr|
if embedded
# deliberately not evaluated
write_recipe %q{
include_recipe "foo::#{node['foo']['fighter']}"
write_recipe %Q{
include_recipe "#{expr.strip}"
}
else
write_recipe %q{
Expand Down
4 changes: 2 additions & 2 deletions lib/foodcritic/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def included_recipes(ast)
raise_unless_xpath!(ast)
# we only support literal strings, ignoring sub-expressions
included = ast.xpath(%q{//command[ident/@value = 'include_recipe'][count(
descendant::args_add) = 1][descendant::args_add/string_literal]/
descendant::tstring_content})
descendant::args_add) = 1][count(descendant::string_embexpr) = 0]
[descendant::args_add/string_literal]/descendant::tstring_content})
included.inject(Hash.new([])){|h, i| h[i['value']] += [i]; h}
end

Expand Down

0 comments on commit 2c1f170

Please sign in to comment.