From 2c1f170d29f1bda74a49f5af1b388a2fed16119e Mon Sep 17 00:00:00 2001 From: Andrew Crump Date: Thu, 7 Jun 2012 23:15:29 +0100 Subject: [PATCH] FC007: Exclude recipes w/ embedded expr, refs #44. --- .../007_check_for_undeclared_recipe_dependencies.feature | 9 +++++++-- features/step_definitions/cookbook_steps.rb | 7 +++---- lib/foodcritic/api.rb | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/features/007_check_for_undeclared_recipe_dependencies.feature b/features/007_check_for_undeclared_recipe_dependencies.feature index 48d51d04..6892eda6 100644 --- a/features/007_check_for_undeclared_recipe_dependencies.feature +++ b/features/007_check_for_undeclared_recipe_dependencies.feature @@ -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 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 diff --git a/features/step_definitions/cookbook_steps.rb b/features/step_definitions/cookbook_steps.rb index 5b447bdd..a6b9a451 100644 --- a/features/step_definitions/cookbook_steps.rb +++ b/features/step_definitions/cookbook_steps.rb @@ -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{ diff --git a/lib/foodcritic/api.rb b/lib/foodcritic/api.rb index 68c5aa85..6dfdbdb9 100644 --- a/lib/foodcritic/api.rb +++ b/lib/foodcritic/api.rb @@ -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