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

Commit

Permalink
FC032: Invalid notification timing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Crump committed Jun 6, 2012
1 parent 9219a5f commit 9ddd384
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions features/032_check_for_invalid_notification_timing.feature
Original file line number Diff line number Diff line change
@@ -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 <type> <notification_timing>
When I check the cookbook
Then the invalid notification timing warning 032 <display> 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 |
8 changes: 8 additions & 0 deletions features/step_definitions/cookbook_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions features/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
11 changes: 11 additions & 0 deletions lib/foodcritic/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9ddd384

Please sign in to comment.