From 9ddd3849094d561c2e133c64be5327ef1db00b3d Mon Sep 17 00:00:00 2001 From: Andrew Crump Date: Wed, 6 Jun 2012 23:44:55 +0100 Subject: [PATCH] FC032: Invalid notification timing. --- ...ck_for_invalid_notification_timing.feature | 22 +++++++++++++++++++ features/step_definitions/cookbook_steps.rb | 8 +++++++ features/support/command_helpers.rb | 1 + lib/foodcritic/rules.rb | 11 ++++++++++ 4 files changed, 42 insertions(+) create mode 100644 features/032_check_for_invalid_notification_timing.feature diff --git a/features/032_check_for_invalid_notification_timing.feature b/features/032_check_for_invalid_notification_timing.feature new file mode 100644 index 00000000..6158cd57 --- /dev/null +++ b/features/032_check_for_invalid_notification_timing.feature @@ -0,0 +1,22 @@ +Feature: Check for invalid notification timings + + In order to flag invalid notifications more quickly + As a developer + I want to identify notifications that have an invalid timing type + + Scenario Outline: Notification timings + Given a cookbook recipe with a resource that + When I check the cookbook + Then the invalid notification timing warning 032 be displayed + Examples: + | type | notification_timing | display | + | notifies | | should not | + | notifies | immediately | should not | + | notifies | immediate | should not | + | notifies | delayed | should not | + | notifies | imediately | should | + | subscribes | | should not | + | subscribes | immediately | should not | + | subscribes | immediate | should not | + | subscribes | delayed | should not | + | subscribes | imediately | should | diff --git a/features/step_definitions/cookbook_steps.rb b/features/step_definitions/cookbook_steps.rb index 7d51446b..5b447bdd 100644 --- a/features/step_definitions/cookbook_steps.rb +++ b/features/step_definitions/cookbook_steps.rb @@ -355,6 +355,14 @@ }.strip end +Given /^a cookbook recipe with a resource that ([^ ]+) (.*)$/ do |type,notification_timing| + write_recipe %Q{ + template "/etc/foo.conf" do + #{type} :restart, "service[foo]"#{", :#{notification_timing}" if notification_timing} + end + } +end + Given /^a cookbook recipe with a '([^']+)' condition for flavours (.*)$/ do |type,flavours| platforms = %Q{"#{flavours.split(',').join('","')}"} if type == 'case' diff --git a/features/support/command_helpers.rb b/features/support/command_helpers.rb index 6b49b170..9b90dd98 100644 --- a/features/support/command_helpers.rb +++ b/features/support/command_helpers.rb @@ -38,6 +38,7 @@ module CommandHelpers 'FC029' => 'No leading cookbook name in recipe metadata', 'FC030' => 'Cookbook contains debugger breakpoints', 'FC031' => 'Cookbook without metadata file', + 'FC032' => 'Invalid notification timing', 'FCTEST001' => 'Test Rule' } diff --git a/lib/foodcritic/rules.rb b/lib/foodcritic/rules.rb index f67856c4..7dc24037 100644 --- a/lib/foodcritic/rules.rb +++ b/lib/foodcritic/rules.rb @@ -443,3 +443,14 @@ end end end + +rule "FC032", "Invalid notification timing" do + tags %w{correctness notifications} + recipe do |ast| + find_resources(ast).select do |resource| + notifications(resource).any? do |notification| + ! [:delayed, :immediate].include? notification[:timing] + end + end + end +end