foodcritic 15.0.0 → 15.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +4 -4
  2. data/chef_dsl_metadata/{chef_14.7.17.json → chef_14.8.12.json} +61 -1
  3. data/foodcritic.gemspec +1 -3
  4. data/lib/foodcritic/linter.rb +1 -1
  5. data/lib/foodcritic/version.rb +1 -1
  6. metadata +5 -232
  7. data/Rakefile +0 -73
  8. data/features/002_check_string_interpolation.feature +0 -50
  9. data/features/005_check_for_resource_repetition.feature +0 -64
  10. data/features/006_check_file_mode.feature +0 -36
  11. data/features/009_check_for_unrecognised_resource_attributes.feature +0 -55
  12. data/features/014_check_for_long_ruby_blocks.feature +0 -30
  13. data/features/018_check_for_old_lwrp_notification_syntax.feature +0 -25
  14. data/features/019_check_for_consistent_node_access.feature +0 -108
  15. data/features/021_check_for_dodgy_lwrp_conditions.feature +0 -28
  16. data/features/022_check_for_dodgy_conditions_within_loop.feature +0 -43
  17. data/features/024_check_for_missing_platforms.feature +0 -43
  18. data/features/027_check_for_internal_attribute_use.feature +0 -22
  19. data/features/030_check_for_debugger_breakpoints.feature +0 -25
  20. data/features/032_check_for_invalid_notification_timing.feature +0 -24
  21. data/features/033_check_for_missing_template.feature +0 -39
  22. data/features/034_check_for_unused_template_variables.feature +0 -80
  23. data/features/037_check_for_invalid_notification_action.feature +0 -34
  24. data/features/038_check_for_invalid_action.feature +0 -39
  25. data/features/039_check_for_key_access_to_node_methods.feature +0 -33
  26. data/features/044_check_for_bare_attribute_keys.feature +0 -53
  27. data/features/046_check_for_assign_unless_nil_attributes.feature +0 -21
  28. data/features/047_check_for_attribute_assignment_without_precedence.feature +0 -49
  29. data/features/051_check_for_template_partial_loops.feature +0 -40
  30. data/features/build_framework_support.feature +0 -109
  31. data/features/checking_all_types_of_file.feature +0 -40
  32. data/features/choose_rules_to_apply.feature +0 -47
  33. data/features/command_line_help.feature +0 -58
  34. data/features/continuous_integration_support.feature +0 -33
  35. data/features/exclude_paths_to_lint.feature +0 -12
  36. data/features/ignore_via_line_comments.feature +0 -69
  37. data/features/include_custom_rules.feature +0 -29
  38. data/features/individual_file.feature +0 -28
  39. data/features/limit_rules_to_specific_versions.feature +0 -65
  40. data/features/multiple_paths.feature +0 -35
  41. data/features/show_lines_matched.feature +0 -20
  42. data/features/sort_warnings.feature +0 -10
  43. data/features/specify_search_grammar.feature +0 -25
  44. data/features/step_definitions/cookbook_steps.rb +0 -1826
  45. data/features/support/command_helpers.rb +0 -418
  46. data/features/support/cookbook_helpers.rb +0 -599
  47. data/features/support/env.rb +0 -19
  48. data/man/foodcritic.1.ronn +0 -76
  49. data/spec/functional/fc001_spec.rb +0 -72
  50. data/spec/functional/fc004_spec.rb +0 -84
  51. data/spec/functional/fc007_spec.rb +0 -127
  52. data/spec/functional/fc008_spec.rb +0 -33
  53. data/spec/functional/fc009_spec.rb +0 -37
  54. data/spec/functional/fc010_spec.rb +0 -32
  55. data/spec/functional/fc011_spec.rb +0 -20
  56. data/spec/functional/fc013_spec.rb +0 -39
  57. data/spec/functional/fc015_spec.rb +0 -19
  58. data/spec/functional/fc016_spec.rb +0 -57
  59. data/spec/functional/fc025_spec.rb +0 -60
  60. data/spec/functional/fc026_spec.rb +0 -66
  61. data/spec/functional/fc028_spec.rb +0 -93
  62. data/spec/functional/fc029_spec.rb +0 -33
  63. data/spec/functional/fc031_spec.rb +0 -14
  64. data/spec/functional/fc037_spec.rb +0 -75
  65. data/spec/functional/fc038_spec.rb +0 -28
  66. data/spec/functional/fc040_spec.rb +0 -156
  67. data/spec/functional/fc041_spec.rb +0 -121
  68. data/spec/functional/fc042_spec.rb +0 -13
  69. data/spec/functional/fc043_spec.rb +0 -28
  70. data/spec/functional/fc045_spec.rb +0 -18
  71. data/spec/functional/fc048_spec.rb +0 -67
  72. data/spec/functional/fc049_spec.rb +0 -56
  73. data/spec/functional/fc050_spec.rb +0 -85
  74. data/spec/functional/fc052_spec.rb +0 -13
  75. data/spec/functional/fc053_spec.rb +0 -13
  76. data/spec/functional/fc055_spec.rb +0 -18
  77. data/spec/functional/fc056_spec.rb +0 -18
  78. data/spec/functional/fc058_spec.rb +0 -102
  79. data/spec/functional/fc060_spec.rb +0 -45
  80. data/spec/functional/fc061_spec.rb +0 -48
  81. data/spec/functional/fc062_spec.rb +0 -13
  82. data/spec/functional/fc063_spec.rb +0 -18
  83. data/spec/functional/fc064_spec.rb +0 -13
  84. data/spec/functional/fc065_spec.rb +0 -13
  85. data/spec/functional/fc066_spec.rb +0 -33
  86. data/spec/functional/fc067_spec.rb +0 -13
  87. data/spec/functional/fc068_spec.rb +0 -13
  88. data/spec/functional/fc069_spec.rb +0 -38
  89. data/spec/functional/fc070_spec.rb +0 -65
  90. data/spec/functional/fc071_spec.rb +0 -36
  91. data/spec/functional/fc072_spec.rb +0 -13
  92. data/spec/functional/fc073_spec.rb +0 -56
  93. data/spec/functional/fc074_spec.rb +0 -39
  94. data/spec/functional/fc075_spec.rb +0 -41
  95. data/spec/functional/fc076_spec.rb +0 -13
  96. data/spec/functional/fc077_spec.rb +0 -13
  97. data/spec/functional/fc078_spec.rb +0 -35
  98. data/spec/functional/fc079_spec.rb +0 -21
  99. data/spec/functional/fc080_spec.rb +0 -68
  100. data/spec/functional/fc081_spec.rb +0 -25
  101. data/spec/functional/fc082_spec.rb +0 -23
  102. data/spec/functional/fc083_spec.rb +0 -34
  103. data/spec/functional/fc084_spec.rb +0 -49
  104. data/spec/functional/fc085_spec.rb +0 -77
  105. data/spec/functional/fc086_spec.rb +0 -45
  106. data/spec/functional/fc087_spec.rb +0 -43
  107. data/spec/functional/fc088_spec.rb +0 -18
  108. data/spec/functional/fc089_spec.rb +0 -23
  109. data/spec/functional/fc091_spec.rb +0 -38
  110. data/spec/functional/fc092_spec.rb +0 -31
  111. data/spec/functional/fc093_spec.rb +0 -27
  112. data/spec/functional/fc094_spec.rb +0 -18
  113. data/spec/functional/fc095_spec.rb +0 -18
  114. data/spec/functional/fc096_spec.rb +0 -18
  115. data/spec/functional/fc097_spec.rb +0 -18
  116. data/spec/functional/fc098_spec.rb +0 -18
  117. data/spec/functional/fc099_spec.rb +0 -18
  118. data/spec/functional/fc100_spec.rb +0 -18
  119. data/spec/functional/fc101_spec.rb +0 -23
  120. data/spec/functional/fc102_spec.rb +0 -18
  121. data/spec/functional/fc103_spec.rb +0 -30
  122. data/spec/functional/fc104_spec.rb +0 -54
  123. data/spec/functional/fc105_spec.rb +0 -36
  124. data/spec/functional/fc106_spec.rb +0 -21
  125. data/spec/functional/fc107_spec.rb +0 -22
  126. data/spec/functional/fc108_spec.rb +0 -43
  127. data/spec/functional/fc109_spec.rb +0 -22
  128. data/spec/functional/fc110_spec.rb +0 -21
  129. data/spec/functional/fc111_spec.rb +0 -17
  130. data/spec/functional/fc112_spec.rb +0 -17
  131. data/spec/functional/fc113_spec.rb +0 -98
  132. data/spec/functional/fc114_spec.rb +0 -31
  133. data/spec/functional/fc115_spec.rb +0 -24
  134. data/spec/functional/fc116_spec.rb +0 -18
  135. data/spec/functional/fc117_spec.rb +0 -23
  136. data/spec/functional/fc118_spec.rb +0 -17
  137. data/spec/functional/fc119_spec.rb +0 -27
  138. data/spec/functional/fc120_spec.rb +0 -21
  139. data/spec/functional/fc121_spec.rb +0 -45
  140. data/spec/functional/fc122_spec.rb +0 -18
  141. data/spec/functional/root_aliases_spec.rb +0 -13
  142. data/spec/regression/cookbooks.txt +0 -83
  143. data/spec/regression/expected/activemq.txt +0 -6
  144. data/spec/regression/expected/aix.txt +0 -27
  145. data/spec/regression/expected/apparmor.txt +0 -9
  146. data/spec/regression/expected/apt.txt +0 -14
  147. data/spec/regression/expected/ark.txt +0 -3
  148. data/spec/regression/expected/auditd.txt +0 -2
  149. data/spec/regression/expected/aws.txt +0 -16
  150. data/spec/regression/expected/bluepill.txt +0 -12
  151. data/spec/regression/expected/boost.txt +0 -8
  152. data/spec/regression/expected/build-essential.txt +0 -8
  153. data/spec/regression/expected/chef-client.txt +0 -17
  154. data/spec/regression/expected/chef-ingredient.txt +0 -6
  155. data/spec/regression/expected/chef-server.txt +0 -13
  156. data/spec/regression/expected/chef-vault.txt +0 -7
  157. data/spec/regression/expected/chef.txt +0 -104
  158. data/spec/regression/expected/chef_client_updater.txt +0 -2
  159. data/spec/regression/expected/chef_handler.txt +0 -7
  160. data/spec/regression/expected/chef_hostname.txt +0 -3
  161. data/spec/regression/expected/chef_nginx.txt +0 -4
  162. data/spec/regression/expected/cron.txt +0 -7
  163. data/spec/regression/expected/database.txt +0 -42
  164. data/spec/regression/expected/dmg.txt +0 -11
  165. data/spec/regression/expected/docker.txt +0 -4
  166. data/spec/regression/expected/drbd.txt +0 -29
  167. data/spec/regression/expected/dynect.txt +0 -33
  168. data/spec/regression/expected/erlang.txt +0 -6
  169. data/spec/regression/expected/fail2ban.txt +0 -5
  170. data/spec/regression/expected/firewall.txt +0 -11
  171. data/spec/regression/expected/gecode.txt +0 -10
  172. data/spec/regression/expected/gems.txt +0 -32
  173. data/spec/regression/expected/gunicorn.txt +0 -11
  174. data/spec/regression/expected/heartbeat.txt +0 -8
  175. data/spec/regression/expected/homebrew.txt +0 -7
  176. data/spec/regression/expected/iis.txt +0 -22
  177. data/spec/regression/expected/iptables.txt +0 -9
  178. data/spec/regression/expected/jetty.txt +0 -13
  179. data/spec/regression/expected/jpackage.txt +0 -9
  180. data/spec/regression/expected/keepalived.txt +0 -3
  181. data/spec/regression/expected/kickstart.txt +0 -15
  182. data/spec/regression/expected/libarchive.txt +0 -6
  183. data/spec/regression/expected/logwatch.txt +0 -5
  184. data/spec/regression/expected/lvm.txt +0 -14
  185. data/spec/regression/expected/maradns.txt +0 -14
  186. data/spec/regression/expected/maven.txt +0 -8
  187. data/spec/regression/expected/memcached.txt +0 -31
  188. data/spec/regression/expected/motd-tail.txt +0 -5
  189. data/spec/regression/expected/mysql.txt +0 -19
  190. data/spec/regression/expected/ohai.txt +0 -9
  191. data/spec/regression/expected/openldap.txt +0 -12
  192. data/spec/regression/expected/openssh.txt +0 -6
  193. data/spec/regression/expected/openssl.txt +0 -6
  194. data/spec/regression/expected/partial_search.txt +0 -7
  195. data/spec/regression/expected/passenger_apache2.txt +0 -31
  196. data/spec/regression/expected/perl.txt +0 -14
  197. data/spec/regression/expected/php.txt +0 -6
  198. data/spec/regression/expected/postfix.txt +0 -8
  199. data/spec/regression/expected/powershell.txt +0 -8
  200. data/spec/regression/expected/resolver.txt +0 -7
  201. data/spec/regression/expected/rsync.txt +0 -9
  202. data/spec/regression/expected/rsyslog.txt +0 -11
  203. data/spec/regression/expected/runit.txt +0 -4
  204. data/spec/regression/expected/smokeping.txt +0 -6
  205. data/spec/regression/expected/sql_server.txt +0 -7
  206. data/spec/regression/expected/ssh_known_hosts.txt +0 -6
  207. data/spec/regression/expected/stompserver.txt +0 -6
  208. data/spec/regression/expected/subversion.txt +0 -6
  209. data/spec/regression/expected/sudo.txt +0 -10
  210. data/spec/regression/expected/tar.txt +0 -10
  211. data/spec/regression/expected/tftp.txt +0 -6
  212. data/spec/regression/expected/tomcat.txt +0 -18
  213. data/spec/regression/expected/transmission.txt +0 -13
  214. data/spec/regression/expected/ubuntu.txt +0 -5
  215. data/spec/regression/expected/ufw.txt +0 -12
  216. data/spec/regression/expected/unicorn.txt +0 -7
  217. data/spec/regression/expected/users.txt +0 -12
  218. data/spec/regression/expected/vcruntime.txt +0 -8
  219. data/spec/regression/expected/vim.txt +0 -7
  220. data/spec/regression/expected/webpi.txt +0 -7
  221. data/spec/regression/expected/whitelist-node-attrs.txt +0 -7
  222. data/spec/regression/expected/windows.txt +0 -35
  223. data/spec/regression/expected/wix.txt +0 -5
  224. data/spec/regression/expected/xml.txt +0 -7
  225. data/spec/regression/expected/yum.txt +0 -15
  226. data/spec/regression/regression_spec.rb +0 -23
  227. data/spec/spec_helper.rb +0 -132
  228. data/spec/unit/api_spec.rb +0 -1939
  229. data/spec/unit/chef_spec.rb +0 -66
  230. data/spec/unit/command_line_spec.rb +0 -136
  231. data/spec/unit/domain_spec.rb +0 -78
  232. data/spec/unit/linter_spec.rb +0 -107
  233. data/spec/unit/template_spec.rb +0 -53
@@ -1,29 +0,0 @@
1
- Feature: Include custom rules
2
-
3
- In order to be able detect cookbook issues that are specific to my organisation
4
- As a developer
5
- I want to be able to write custom rules and include them in my check
6
-
7
- Scenario: Valid custom rule
8
- Given a cookbook with a single recipe that reads node attributes via strings
9
- And I have installed the lint tool
10
- When I run it on the command line including a custom rule file containing a rule that matches
11
- Then a warning for the custom rule should be displayed
12
-
13
- Scenario: Valid custom rules (directory)
14
- Given a cookbook with a single recipe that reads node attributes via strings
15
- And I have installed the lint tool
16
- When I run it on the command line including a custom rule directory containing a rule that matches
17
- Then a warning for the custom rule should be displayed
18
-
19
- Scenario: Missing file
20
- Given a cookbook with a single recipe that reads node attributes via strings
21
- And I have installed the lint tool
22
- When I run it on the command line including a missing custom rule file
23
- Then a 'No such file or directory' error should be displayed
24
-
25
- Scenario: Non-ruby file
26
- Given a cookbook with a single recipe that reads node attributes via strings
27
- And I have installed the lint tool
28
- When I run it on the command line including a file which does not contain Ruby code
29
- Then an 'undefined method' error should be displayed
@@ -1,28 +0,0 @@
1
- Feature: Individual file
2
-
3
- In order to get even faster feedback on changes to cookbooks
4
- As a developer
5
- I want to lint individual files in a cookbook
6
-
7
- Scenario: Linting an individual recipe shows warnings only from that file
8
- Given a cookbook with a single recipe that reads node attributes via symbols,strings
9
- And a cookbook that declares normal attributes via symbols
10
- When I check the recipe
11
- Then the attribute consistency warning 019 should be displayed for the recipe
12
- And the attribute consistency warning 019 should not be displayed for the attributes
13
-
14
- Scenario: Linting an individual role
15
- Given a roles directory
16
- And it contains a role file webserver.rb that defines the role name "apache"
17
- And it contains a role file database.rb that defines the role name "postgresql"
18
- When I check the webserver role only
19
- Then the role name does not match file name warning 049 should be shown against the webserver role
20
- And the role name does not match file name warning 049 should not be shown against the database role
21
-
22
- Scenario: Linting an individual environment
23
- Given an environments directory
24
- And it contains an environment file production_eu.rb that defines the environment name "production (eu-west-1)"
25
- And it contains an environment file production_us.rb that defines the environment name "production (us-east-1)"
26
- When I check the eu environment file only
27
- Then the invalid environment name warning 050 should be shown against the eu environment
28
- And the invalid environment name warning 050 should not be shown against the us environment
@@ -1,65 +0,0 @@
1
- Feature: Limit rules to specific versions
2
-
3
- In order to not be shown warnings that do not apply to my version of Chef
4
- As a developer
5
- I want to be able to specify the version of Chef I am using
6
-
7
- Scenario: Rule with no version constraint - no version specified
8
- Given a rule that does not declare a version constraint
9
- And a cookbook that matches that rule
10
- When I check the cookbook without specifying a Chef version
11
- Then the warning should be displayed
12
-
13
- Scenario Outline: Rule with no version constraint - specifying version
14
- Given a rule that does not declare a version constraint
15
- And a cookbook that matches that rule
16
- When I check the cookbook specifying <version> as the Chef version
17
- Then the warning should be displayed
18
-
19
- Examples:
20
- | version |
21
- | 0.10.10.beta.1 |
22
- | 0.10.8 |
23
- | 0.10.6 |
24
- | 0.10.6.rc.5 |
25
- | 0.10.6.beta.3 |
26
- | 0.10.4 |
27
- | 0.10.2 |
28
- | 0.10.0 |
29
- | 0.9.18 |
30
-
31
- Scenario: Rule with version constraint - no version specified
32
- Given a rule that declares a version constraint
33
- And the current stable version of Chef falls within it
34
- And a cookbook that matches that rule
35
- When I check the cookbook without specifying a Chef version
36
- Then the warning should be displayed
37
-
38
- Scenario: Rule with version constraint - no version specified
39
- Given a rule that declares a version constraint
40
- And the current stable version of Chef does not fall within it
41
- And a cookbook that matches that rule
42
- When I check the cookbook without specifying a Chef version
43
- Then the warning should not be displayed
44
-
45
- Scenario Outline: Rule with version constraint - specifying version
46
- Given a rule that declares a version constraint of <from_version> to <to_version>
47
- And a cookbook that matches that rule
48
- When I check the cookbook specifying <version> as the Chef version
49
- Then the warning <warning>
50
-
51
- Examples:
52
- | version | from_version | to_version | warning |
53
- | 0.10.10.beta.1 | 0.10.10 | | should not be displayed |
54
- | 0.10.10 | 0.10.10 | | should be displayed |
55
- | 0.10.8 | 0.10.10 | | should not be displayed |
56
- | 0.10.6.rc.5 | 0.10.8 | | should not be displayed |
57
- | 0.10.6.rc.5 | 0.10.6 | | should not be displayed |
58
- | 0.10.4 | 0.9.14 | | should be displayed |
59
- | 0.10.4 | 0.10.10 | | should not be displayed |
60
- | 0.10.8 | 0.9.18 | 0.10.6 | should not be displayed |
61
- | 0.10.6 | 0.9.18 | 0.10.6 | should be displayed |
62
- | 0.9.18 | 0.9.18 | 0.10.6 | should be displayed |
63
- | 0.9.14 | 0.9.18 | 0.10.6 | should not be displayed |
64
- | 0.9.14 | | 0.10.6 | should be displayed |
65
- | 0.9.14 | | 0.9.12 | should not be displayed |
@@ -1,35 +0,0 @@
1
- Feature: Multiple paths
2
-
3
- In order to avoid needing to run foodcritic multiple times
4
- As a developer
5
- I want to lint multiple paths at once
6
-
7
- Scenario Outline: Linting multiple individual cookbooks
8
- Given a cookbook with a single recipe that reads node attributes via symbols,strings
9
- And another cookbook with a single recipe that reads node attributes via strings
10
- When I check both cookbooks with the command-line <command_line>
11
- Then the attribute consistency warning 019 should be shown
12
- Examples:
13
- | command_line |
14
- | example another_example |
15
- | -B example -B another_example |
16
- | --cookbook-path example --cookbook-path another_example |
17
- | -B example another_example |
18
- | --cookbook-path example another_example |
19
- | -B example --cookbook-path another_example |
20
-
21
- Scenario: Linting multiple role directories
22
- Given two roles directories
23
- And each role directory has a role with a name that does not match the containing file name
24
- When I check both roles directories
25
- Then the role name does not match file name warning 049 should be shown against the files in both directories
26
-
27
- Scenario: Linting a cookbook, role and environment together
28
- Given a cookbook with a single recipe that reads node attributes via symbols,strings
29
- And another cookbook with a single recipe that reads node attributes via strings
30
- And a directory that contains a role file webserver.rb in ruby that defines role name apache
31
- And a directory that contains an environment file production.rb in ruby that defines environment name production (us-east)
32
- When I check the cookbooks, role and environment together
33
- Then the attribute consistency warning 019 should be shown
34
- And the role name does not match file name warning 049 should be shown
35
- And the invalid environment name warning 050 should be shown
@@ -1,20 +0,0 @@
1
- @context
2
- Feature: Show Lines Matched
3
-
4
- In order to understand more quickly the reason for a warning
5
- As a developer
6
- I want to be able to see the lines the warning matches against, with context
7
-
8
- Scenario: Recipe with a single warning
9
- Given a cookbook with a single recipe that reads node attributes via symbols
10
- When I check the cookbook, specifying that context should be shown
11
- Then the recipe filename should be displayed
12
- And the node access warning 001 should be displayed below
13
- And the line number and line of code that triggered the warning should be displayed
14
-
15
- Scenario: Recipe with a multiple warnings of the same type
16
- Given a cookbook with a single recipe that accesses multiple node attributes via symbols
17
- When I check the cookbook, specifying that context should be shown
18
- Then the recipe filename should be displayed
19
- And the node access warning 001 should be displayed below
20
- And the line number and line of code that triggered the warnings should be displayed
@@ -1,10 +0,0 @@
1
- Feature: Sort warnings
2
-
3
- In order to make it easier to see which lines of my recipe have been flagged with warnings
4
- As a developer
5
- I want warnings to appear in line order
6
-
7
- Scenario: Recipe has warnings on lines that don't sort non-numerically
8
- Given a cookbook with a single recipe which accesses node attributes with symbols on lines 2 and 10
9
- When I check the cookbook
10
- Then the node access warning 001 should warn on lines 2 and 10 in that order
@@ -1,25 +0,0 @@
1
- Feature: Specify search grammar
2
-
3
- In order to allow the use of alternate search grammars when validating search syntax
4
- As a developer
5
- I want to be able to specify the grammar to use as a command line option
6
-
7
- Scenario: No grammar passed
8
- Given a cookbook recipe that attempts to perform a search with invalid syntax
9
- When I check the cookbook
10
- Then the invalid search syntax warning 010 should be displayed
11
-
12
- Scenario: Missing grammar passed
13
- Given a cookbook recipe that attempts to perform a search with invalid syntax
14
- When I check the cookbook specifying a search grammar that does not exist
15
- Then the check should abort with an error
16
-
17
- Scenario: Invalid grammar passed
18
- Given a cookbook recipe that attempts to perform a search with invalid syntax
19
- When I check the cookbook specifying a search grammar that is not in treetop format
20
- Then the check should abort with an error
21
-
22
- Scenario: Valid grammar passed
23
- Given a cookbook recipe that attempts to perform a search with invalid syntax
24
- When I check the cookbook specifying a search grammar that is a valid treetop grammar
25
- Then the invalid search syntax warning 010 should be displayed
@@ -1,1826 +0,0 @@
1
- Given "a cookbook attributes file that declares and refers to a local variable" do
2
- write_attributes %q{
3
- master = search(:nodes, 'foo:master')
4
- default[:foo][:master] = master
5
- }
6
- end
7
-
8
- Given /^a cookbook attributes file that refers to an attribute with (.*)$/ do |reference|
9
- write_attributes %Q{
10
- default['myhostname'] = #{reference}
11
- }
12
- end
13
-
14
- Given "a cookbook attributes file that sets an attribute to be the result of a library call" do
15
- write_attributes %q{
16
- ::Chef::Node.send(:include, Opscode::OpenSSL::Password)
17
- default[:admin_password] = secure_password
18
- }
19
- end
20
-
21
- Given "a cookbook attributes file with a brace block that takes arguments" do
22
- write_attributes %q{
23
- foo = {'foo' => 'bar'}
24
- foo.each{|k, v| default['waka'][k] = v}
25
- }
26
- end
27
-
28
- Given "a cookbook attributes file with a do block that takes arguments" do
29
- write_attributes %q{
30
- foo = {'foo' => 'bar'}
31
- foo.each do |k, v|
32
- default['waka'][k] = v
33
- end
34
- }
35
- end
36
-
37
- Given "a cookbook attributes file that sets an attribute to have line break" do
38
- write_attributes %q{
39
- default['foo']['bar']['baz'][
40
- 'bing']['blonk'] = 'stupendous'
41
- }
42
- end
43
-
44
- Given "a cookbook attributes file that sets an attribute to have line break and arguments" do
45
- write_attributes %q{
46
- %w{ foo bar }.each do |baz|
47
- default['foo']["bing_#{baz}"][
48
- 'blonk'] = baz
49
- end
50
- }
51
- end
52
-
53
- Given /^a cookbook (attributes|recipe) file with assignment (.*)$/ do |type, assignment|
54
- if type == "attributes"
55
- write_attributes assignment
56
- else
57
- write_recipe assignment
58
- end
59
- end
60
-
61
- Given "a cookbook recipe that contains a group resource that uses the 'system' bool attribute" do
62
- write_recipe %q{
63
- group "senge" do
64
- system true
65
- end
66
- }
67
- end
68
-
69
- Given "a cookbook recipe that contains a user resource that uses the 'system' string attribute" do
70
- write_recipe %q{
71
- user "foo" do
72
- system "bar"
73
- end
74
- }
75
- end
76
-
77
- Given /^a cookbook recipe that declares (too many )?execute resources varying only in the command in branching conditionals$/ do |too_many|
78
- extra_resource = %q{
79
- execute "bing" do
80
- action :run
81
- end
82
- }
83
- write_recipe %Q{
84
- if true
85
- execute "foo" do
86
- action :run
87
- end
88
- else
89
- #{extra_resource if too_many}
90
- execute "bar" do
91
- action :run
92
- end
93
- execute "baz" do
94
- action :run
95
- end
96
- end
97
- }.strip
98
- end
99
-
100
- Given /^a cookbook recipe that declares a ([^ ]+) resource with the ([^ ]+) attribute set to (.*)$/ do |resource, attribute, value|
101
- write_recipe %Q{
102
- #{resource} "foo" do
103
- #{attribute} #{value}
104
- end
105
- }
106
- end
107
-
108
- Given /^a cookbook recipe that executes '([^']+)' with an execute resource$/ do |command|
109
- write_recipe %Q{
110
- execute "#{command}" do
111
- action :run
112
- end
113
- }
114
- end
115
-
116
- Given /^a cookbook recipe that spawns a sub-process with (.*)$/ do |command|
117
- write_recipe command
118
- end
119
-
120
- Given "a provider that contains a ruby_block resource that spawns a sub-process with system" do
121
- write_provider "site", %q{
122
- action :install do
123
- ruby_block "ruby" do
124
- block do
125
- system "ls"
126
- end
127
- end
128
- end
129
- }
130
- end
131
-
132
- Given "a cookbook recipe with a deploy resource that contains a template resource" do
133
- write_recipe %q{
134
- deploy '/foo/bar' do
135
- before_restart do
136
- template "/tmp/config.conf" do
137
- source "foo.conf.erb"
138
- variables({
139
- :config_var => 'foo'
140
- })
141
- end
142
- end
143
- end
144
- }
145
- write_file "cookbooks/example/templates/default/foo.conf.erb", %q{
146
- <%= @config_var %>
147
- }
148
- end
149
-
150
- Given "a cookbook recipe with a resource that notifies where the action is an expression" do
151
- write_recipe %q{
152
- notify_action = node['platform_family'] == "mac_os_x" ? :restart : :reload
153
-
154
- service 'svc' do
155
- action :nothing
156
- end
157
-
158
- template '/tmp/foo' do
159
- source 'foo.erb'
160
- notifies notify_action, 'service[svc]'
161
- end
162
- }
163
- end
164
-
165
- Given /^a cookbook recipe with an execute resource named (.*)$/ do |name|
166
- write_recipe %Q{
167
- execute "#{name}" do
168
- action :run
169
- end
170
- }
171
- end
172
-
173
- Given /^a cookbook recipe with an execute resource that runs the command (.*)$/ do |command|
174
- write_recipe %Q{
175
- execute "do_stuff" do
176
- command "#{command}"
177
- end
178
- }
179
- end
180
-
181
- Given /^a cookbook recipe that refers to (node.*)$/ do |reference|
182
- write_recipe %Q{
183
- Chef::Log.info #{reference}
184
- }
185
- end
186
-
187
- Given "a cookbook recipe that refers to an attribute with a bare keyword" do
188
- write_recipe %q{
189
- node['myhostname'] = hostname
190
- }
191
- end
192
-
193
- Given "a cookbook provider that declares execute resources varying only in the command in separate actions" do
194
- write_provider "site", %q{
195
- action :start do
196
- execute "foo" do
197
- action :run
198
- end
199
- new_resource.updated_by_last_action(true)
200
- end
201
- action :stop do
202
- execute "bar" do
203
- action :run
204
- end
205
- new_resource.updated_by_last_action(true)
206
- end
207
- action :restart do
208
- execute "baz" do
209
- action :run
210
- end
211
- new_resource.updated_by_last_action(true)
212
- end
213
- }.strip
214
- end
215
-
216
- Given "a cookbook provider that declares execute resources varying only in the command in the same action" do
217
- write_provider "site", %q{
218
- action :start do
219
- execute "foo" do
220
- action :run
221
- end
222
- execute "bar" do
223
- action :run
224
- end
225
- execute "baz" do
226
- action :run
227
- end
228
- new_resource.updated_by_last_action(true)
229
- end
230
- }.strip
231
- end
232
-
233
- Given /^a cookbook recipe that attempts to perform a search with (.*)$/ do |search_type|
234
- recipe_with_search(search_type.include?("subexpression") ? :with_subexpression : search_type.tr(" ", "_").to_sym)
235
- end
236
-
237
- Given /^a cookbook recipe that declares a resource called ([^ ]+) with the condition (.*)(in|outside) a loop$/ do |name, condition, is_loop|
238
- write_recipe %Q{
239
- #{'%w{rover fido}.each do |pet_name|' if is_loop == 'in'}
240
- execute #{name} do
241
- command "echo 'Feeding: \#{pet_name}'; touch '/tmp/\#{pet_name}'"
242
- #{condition.nil? ? 'not_if { ::File.exists?("/tmp/\#{pet_name}")}' : condition}
243
- end
244
- #{'end' if is_loop == 'in'}
245
- }
246
- end
247
-
248
- Given /^a cookbook recipe that declares a resource with a (.*)$/ do |conditional|
249
- write_recipe %Q{
250
- template "/tmp/foo" do
251
- mode "0644"
252
- source "foo.erb"
253
- #{conditional}
254
- end
255
- }
256
- end
257
-
258
- Given "a cookbook recipe that declares a resource with no conditions at all" do
259
- write_recipe %q{
260
- service "apache" do
261
- action :enable
262
- end
263
- }
264
- end
265
-
266
- Given "a cookbook recipe that declares multiple directories with different file modes" do
267
- write_recipe %q{
268
- directory "#{node["nagios"]["dir"]}/dist" do
269
- owner "nagios"
270
- group "nagios"
271
- mode 0755
272
- end
273
-
274
- directory node["nagios"]["state_dir"] do
275
- owner "nagios"
276
- group "nagios"
277
- mode 0751
278
- end
279
-
280
- directory "#{node["nagios"]["state_dir"]}/rw" do
281
- owner "nagios"
282
- group node["apache"]["user"]
283
- mode 2710
284
- end
285
- }
286
- end
287
-
288
- Given "a cookbook recipe that declares multiple package resources mixed with other resources" do
289
- write_recipe %q{
290
- package "erlang-base" do
291
- action :install
292
- end
293
- package "erlang-corba" do
294
- action :install
295
- end
296
- package "erlang-crypto" do
297
- action :install
298
- end
299
- service "apache" do
300
- supports :restart => true, :reload => true
301
- action :enable
302
- end
303
- template "/tmp/somefile" do
304
- mode "0644"
305
- source "somefile.erb"
306
- not_if "test -f /etc/passwd"
307
- end
308
- package "rabbitmq-server" do
309
- action :install
310
- end
311
- }
312
- end
313
-
314
- Given /^a cookbook recipe that declares multiple (varying|non-varying) template resources within a block$/ do |vary|
315
- do_vary = vary == "varying"
316
- write_recipe %Q{
317
- node['apps'].each do |app|
318
- template "/etc/#\{app\}.conf" do
319
- owner "root"
320
- group "root"
321
- #{'mode "0600"' if do_vary}
322
- end
323
- template "/etc/init.d/#\{app\}" do
324
- owner "root"
325
- group "root"
326
- #{'mode "0700"' if do_vary}
327
- end
328
- template "/home/#\{app\}/foo" do
329
- owner "root"
330
- group "root"
331
- #{'mode "0600"' if do_vary}
332
- end
333
- end
334
- }
335
- end
336
-
337
- Given "a cookbook recipe that declares multiple resources varying only in the package name" do
338
- write_recipe %q{
339
- package "erlang-base" do
340
- action :install
341
- end
342
- package "erlang-corba" do
343
- action :install
344
- end
345
- package "erlang-crypto" do
346
- action :install
347
- end
348
- package "rabbitmq-server" do
349
- action :install
350
- end
351
- }
352
- end
353
-
354
- Given "a cookbook recipe that declares multiple resources with more variation" do
355
- write_recipe %q{
356
- package "erlang-base" do
357
- action :install
358
- end
359
- package "erlang-corba" do
360
- action :install
361
- end
362
- package "erlang-crypto" do
363
- version '13.b.3'
364
- action :install
365
- end
366
- package "rabbitmq-server" do
367
- action :install
368
- end
369
- }
370
- end
371
-
372
- Given "a cookbook recipe that declares non contiguous package resources mixed with other resources" do
373
- write_recipe %q{
374
- package "erlang-base" do
375
- action :install
376
- end
377
- service "apache" do
378
- supports :restart => true, :reload => true
379
- action :enable
380
- end
381
- package "erlang-crypto" do
382
- action :install
383
- end
384
- template "/tmp/somefile" do
385
- mode "0644"
386
- source "somefile.erb"
387
- not_if "test -f /etc/passwd"
388
- end
389
- package "rabbitmq-server" do
390
- action :install
391
- end
392
- }
393
- end
394
-
395
- Given "a cookbook recipe that declares two or fewer resources varying only in the package name" do
396
- write_recipe %q{
397
- package "erlang-base" do
398
- action :install
399
- end
400
- package "erlang-corba" do
401
- action :install
402
- end
403
- }
404
- end
405
-
406
- Given 'a cookbook recipe that has a confusingly named local variable "default"' do
407
- write_recipe %q{
408
- default = {'run_list' => 'foo'}; Chef::Log.info default['run_list']
409
- }
410
- end
411
-
412
- Given "a cookbook recipe that refers to a hidden template" do
413
- write_recipe %q{
414
- template '/etc/.s3cfg' do
415
- source '.s3cfg.erb'
416
- end
417
- }
418
- write_file "cookbooks/example/templates/default/.s3cfg.erb", %q{
419
- config=true
420
- }
421
- end
422
-
423
- Given /^a cookbook recipe that refers to a (missing |local )?template( in a subdirectory)?$/ do |missing_or_local, sub_dir|
424
- sub_dir = sub_dir ? "sub_dir/" : ""
425
- write_recipe %Q{
426
- template "/tmp/config.conf" do
427
- #{'local true' if missing_or_local == 'local '}
428
- source "#{sub_dir}config.conf.erb"
429
- variables({
430
- :config_var => 'foo'
431
- })
432
- end
433
- }
434
- unless missing_or_local
435
- write_file "cookbooks/example/templates/default/#{sub_dir}config.conf.erb", %q{
436
- <%= @config_var %>
437
- }
438
- end
439
- end
440
-
441
- Given /^a cookbook recipe that refers to a template in the root of the templates directory$/ do
442
- write_recipe %q{
443
- template "/tmp/config.conf" do
444
- source "config.conf.erb"
445
- variables({
446
- :config_var => 'foo'
447
- })
448
- end
449
- }
450
- write_file "cookbooks/example/templates/config.conf.erb", %q{
451
- <%= @config_var %>
452
- }
453
- end
454
-
455
- Given "a cookbook recipe that refers to a template without an erb extension" do
456
- write_recipe %q{
457
- template '/etc/resolv.conf' do
458
- source 'resolv.conf'
459
- end
460
- }
461
- write_file "cookbooks/example/templates/default/resolv.conf", ""
462
- end
463
-
464
- Given "a cookbook recipe that defines a template where name is a complex expression" do
465
- write_recipe %q{
466
- template ::File.join(new_resource.foo.bar, "str", new_resource.baz) do
467
- variables({
468
- :config_var => 'foo'
469
- })
470
- end
471
- }
472
- write_file "cookbooks/example/templates/default/barstrbaz.conf.erb", %q{
473
- <%= @config_var %>
474
- }
475
- end
476
-
477
- Given "a cookbook recipe that defines a template where both the name and source are complex expressions" do
478
- write_recipe %q{
479
- template ::File.join(new_resource.foo.bar, "str", new_resource.baz) do
480
- source new_resource.foo.template
481
- variables({
482
- :config_var => 'foo'
483
- })
484
- end
485
- }
486
- write_file "cookbooks/example/templates/default/barstrbaz.conf.erb", %q{
487
- <%= @config_var %>
488
- }
489
- end
490
-
491
- Given "a cookbook recipe that defines a template where name and source are both simple expressions" do
492
- write_recipe %q{
493
- template "/tmp/config-#{foo}.conf" do
494
- source "config-#{foo}.erb"
495
- variables({
496
- :config_var => 'foo'
497
- })
498
- end
499
- }
500
- write_file "cookbooks/example/templates/default/config-foo.conf.erb", %q{
501
- <%= @config_var %>
502
- }
503
- end
504
-
505
- Given /^a cookbook recipe that (refers to|infers) a template with an expression$/ do |type|
506
- write_attributes %q{
507
- default['foo']['name'] = 'foo'
508
- }
509
- write_recipe case type
510
- when "infers"
511
- %q{
512
- template "/tmp/config-#{node['foo']['name']}.conf" do
513
- variables({
514
- :config_var => 'foo'
515
- })
516
- end
517
- }
518
- else
519
- %q{
520
- template "/tmp/config.conf" do
521
- source "config-#{node['foo']['name']}.erb"
522
- variables({
523
- :config_var => 'foo'
524
- })
525
- end
526
- }
527
- end
528
- write_file "cookbooks/example/templates/default/config-foo.conf.erb", %q{
529
- <%= @config_var %>
530
- }
531
- end
532
-
533
- Given "a cookbook recipe that uses a template from another cookbook" do
534
- write_recipe %q{
535
- template "foo" do
536
- cookbook "othercookbook"
537
- source "source_in_the_other_cookbook.erb"
538
- end
539
- }
540
- end
541
-
542
- Given /^a cookbook recipe that uses a(?:n)? (missing )?inferred template$/ do |missing|
543
- write_recipe %Q{
544
- template "/tmp/config.conf" do
545
- variables({
546
- :config_var => 'foo'
547
- })
548
- end
549
- }
550
- unless missing
551
- write_file "cookbooks/example/templates/default/config.conf.erb", %q{
552
- <%= @config_var %>
553
- }
554
- end
555
- end
556
-
557
- Given /^a cookbook recipe that uses execute to (sleep and then )?([^ ]+) a service via (.*)$/ do |sleep, action, method|
558
- method = "service" if method == "the service command"
559
- recipe_controls_service(method.include?("full path") ? :service_full_path : method.gsub(/[^a-z_]/, "_").to_sym, sleep, action)
560
- end
561
-
562
- Given "a cookbook recipe that uses execute to list a directory" do
563
- write_recipe %Q{
564
- execute "nothing-to-see-here" do
565
- command "ls"
566
- action :run
567
- end
568
- }
569
- end
570
-
571
- Given "a cookbook recipe that uses execute with a name attribute to start a service" do
572
- write_recipe %Q{
573
- execute "/etc/init.d/foo start" do
574
- cwd "/tmp"
575
- end
576
- }
577
- end
578
-
579
- Given /^a cookbook recipe with a ([^ ]+) resource that subscribes to ([^ ]+) when notified by a remote_file$/ do |source, action|
580
- write_recipe %Q{
581
- #{source} "foo" do
582
- action :nothing
583
- subscribes :#{action}, resources(:remote_file => "/foo/bar"), :immediately
584
- end
585
- }
586
- end
587
-
588
- Given /^a cookbook recipe with a ([^ ]+) resource with action (.*)$/ do |resource, action|
589
- write_recipe %Q{
590
- #{resource} "foo" do
591
- action :#{action}
592
- end
593
- }
594
- end
595
-
596
- Given /^a cookbook recipe with a ([^ ]+) resource with actions (.*)$/ do |resource, actions|
597
- write_recipe %Q{
598
- #{resource} "foo" do
599
- action [#{actions.split(', ').map { |a| ":#{a}" }.join(", ")}]
600
- end
601
- }
602
- end
603
-
604
- Given "a cookbook recipe with a case condition unrelated to platform" do
605
- write_recipe %Q{
606
- case day_of_week
607
- when "Monday", "Tuesday"
608
- package "foo" do
609
- action :install
610
- end
611
- when "Wednesday", "Thursday"
612
- package "bar" do
613
- action :install
614
- end
615
- end
616
- }.strip
617
- end
618
-
619
- Given /^a cookbook recipe with a resource that ([^ ]+)(?: )?([^ ]+)?$/ do |type, notification_timing|
620
- write_recipe %Q{
621
- template "/etc/foo.conf" do
622
- #{type} :restart, "service[foo]"#{", :#{notification_timing}" if notification_timing}
623
- end
624
- }
625
- end
626
-
627
- Given /^a cookbook recipe with a resource that (notifies|subscribes) a ([^ ]+) to ([^ ]+)$/ do |type, resource, action|
628
- notification = case type
629
- when "notifies" then %Q{notifies :#{action}, "#{resource}[foo]"}
630
- when "subscribes" then %Q{subscribes :#{action}, resources(:#{resource} => "foo")}
631
- end
632
- write_recipe %Q{
633
- template "/etc/apache.conf" do
634
- #{notification}
635
- end
636
- }
637
- end
638
-
639
- Given /^a cookbook recipe with a '([^']+)' condition for flavours (.*)$/ do |type, flavours|
640
- platforms = %Q{"#{flavours.split(',').join('","')}"}
641
- if type == "case"
642
- @expected_line = 6
643
- write_recipe %Q{
644
- case node[:platform]
645
- when "debian", "ubuntu"
646
- package "foo" do
647
- action :install
648
- end
649
- when #{platforms}
650
- package "bar" do
651
- action :install
652
- end
653
- end
654
- }.strip
655
- elsif type == "platform?"
656
- @expected_line = 1
657
- write_recipe %Q{
658
- if platform?(#{platforms})
659
- package "bar" do
660
- action :install
661
- end
662
- end
663
- }.strip
664
- else
665
- raise "Unrecognised type: #{type}"
666
- end
667
- end
668
-
669
- Given "a cookbook recipe with a service resource that does not specify an action" do
670
- write_recipe %q{
671
- service "foo" do
672
- start_command "/sbin/service foo start"
673
- end
674
- }.strip
675
- end
676
-
677
- Given "a cookbook recipe with a service resource with an action specified via a variable" do
678
- write_recipe %q{
679
- service "foo" do
680
- action action
681
- end
682
- }.strip
683
- end
684
-
685
- Given "a cookbook template that uses all variables passed" do
686
- write_recipe %q{
687
- template "/tmp/config.conf" do
688
- source "config.conf.erb"
689
- variables(
690
- :config_var => node[:configs][:config_var]
691
- )
692
- end
693
- }
694
- write_file "cookbooks/example/templates/default/config.conf.erb", %q{
695
- <%= @config_var %>
696
- }
697
- end
698
-
699
- Given /^a cookbook that passes no variables to a template$/ do
700
- write_recipe %q{
701
- template "/tmp/config.conf" do
702
- source "config.conf.erb"
703
- end
704
- }
705
- end
706
-
707
- Given /^a cookbook that passes variables (.*) to a template with extension (.*)$/ do |vars, ext|
708
- write_recipe %Q{
709
- template "/tmp/config.conf" do
710
- source "config#{ext}"
711
- variables(
712
- :#{vars.split(',').map { |v| "#{v} => node[:#{v}]" }.join(",\n:")}
713
- )
714
- end
715
- }
716
- end
717
-
718
- Given /^a cookbook that passes variables (.*) to an inferred template$/ do |vars|
719
- write_recipe %Q{
720
- template "/tmp/config.conf" do
721
- variables(
722
- :#{vars.split(',').map { |v| "#{v} => node[:#{v}]" }.join(",\n:")}
723
- )
724
- end
725
- }
726
- end
727
-
728
- Given /^a cookbook that contains a (short|long) ruby block$/ do |length|
729
- recipe_with_ruby_block(length.to_sym)
730
- end
731
-
732
- Given /^a cookbook that contains a LWRP (?:with a single notification|that uses the current notification syntax)$/ do
733
- cookbook_with_lwrp({ :notifies => :does_notify })
734
- end
735
-
736
- Given "a cookbook that contains a LWRP with a single notification without parentheses" do
737
- cookbook_with_lwrp({ :notifies => :does_notify_without_parens })
738
- end
739
-
740
- Given /^a cookbook that contains a LWRP that declares a resource called ([^ ]+) with the condition (.*)$/ do |name, condition|
741
- write_resource("site", %q{
742
- actions :create
743
- attribute :name, :name_attribute => true
744
- })
745
- write_provider("site", %Q{
746
- action :create do
747
- execute #{name} do
748
- command "echo 'Creating: \#{new_resource.name}'; touch '/tmp/\#{new_resource.name}'"
749
- #{condition}
750
- end
751
- end
752
- })
753
- end
754
-
755
- Given /^a cookbook that contains a LWRP that (?:does not trigger notifications|declares a resource with no condition)$/ do
756
- write_resource("site", %q{
757
- actions :create
758
- attribute :name, :kind_of => String, :name_attribute => true
759
- })
760
- write_provider("site", %q{
761
- action :create do
762
- log "Here is where I would create a site"
763
- end
764
- })
765
- end
766
-
767
- Given /^a cookbook that contains a LWRP that uses converge_by - (brace|do) block (with|without) parentheses$/ do |block_type, with_parens|
768
- write_resource("site", %q{
769
- actions :create
770
- attribute :name, :kind_of => String, :name_attribute => true
771
- })
772
- if block_type == "brace"
773
- write_provider("site", %q{
774
- action :create do
775
- converge_by("Creating site #{new_resource.name}"){ Site.new(new_resource.name).create }
776
- end
777
- })
778
- else
779
- if with_parens == "with"
780
- write_provider("site", %q{
781
- action :create do
782
- converge_by("Creating site #{new_resource.name}") do
783
- Site.new(new_resource.name).create
784
- end
785
- end
786
- })
787
- else
788
- write_provider("site", %q{
789
- action :create do
790
- converge_by "Creating site #{new_resource.name}" do
791
- Site.new(new_resource.name).create
792
- end
793
- end
794
- })
795
- end
796
- end
797
- end
798
-
799
- Given /^a cookbook that contains a LWRP that uses the deprecated notification syntax(.*)$/ do |qualifier|
800
- cookbook_with_lwrp({ :notifies => qualifier.include?("class variable") ? :class_variable : :deprecated_syntax })
801
- end
802
-
803
- Given "a cookbook that contains a LWRP that uses use_inline_resources" do
804
- cookbook_with_lwrp({ :use_inline_resources => true })
805
- end
806
-
807
- Given "a cookbook that contains a LWRP with multiple notifications" do
808
- write_resource("site", %q{
809
- actions :create, :delete
810
- attribute :name, :kind_of => String, :name_attribute => true
811
- })
812
- write_provider("site", %q{
813
- action :create do
814
- log "Here is where I would create a site"
815
- new_resource.updated_by_last_action(true)
816
- end
817
- action :delete do
818
- log "Here is where I would delete a site"
819
- new_resource.updated_by_last_action(true)
820
- end
821
- })
822
- end
823
-
824
- Given "a cookbook that contains no ruby blocks" do
825
- write_recipe %q{
826
- package "tar" do
827
- action :install
828
- end
829
- }
830
- end
831
-
832
- Given /^a cookbook that declares ([a-z]+) attributes via symbols$/ do |attribute_type|
833
- attributes_with_symbols(attribute_type)
834
- end
835
-
836
- Given /^a cookbook that has ([^ ]+) problems$/ do |problems|
837
- cookbook_that_matches_rules(
838
- problems.split(",").map do |problem|
839
- case problem
840
- when "no " then next
841
- when "style" then "FC002"
842
- when "correctness" then "FC006"
843
- end
844
- end
845
- )
846
- end
847
-
848
- Given /^a cookbook that matches rules (.*)$/ do |rules|
849
- cookbook_that_matches_rules(rules.split(","))
850
- end
851
-
852
- Given "a cookbook that matches that rule" do
853
- write_recipe %q{
854
- execute "bar" do
855
- action :run
856
- end
857
- }
858
- end
859
-
860
- Given /^a cookbook with a ([^ ]+) that (includes|does not include) a breakpoint$/ do |component, includes|
861
- content = case component
862
- when "template" then includes == "includes" ? "Hello <% require 'pry'; binding.pry %>" : "Hello World"
863
- else includes == "includes" ? "binding.pry" : "# No breakpoint"
864
- end
865
- write_recipe ""
866
- case component
867
- when "library" then write_library "foo", content
868
- when "metadata" then write_metadata content
869
- when "provider" then write_provider "foo", content
870
- when "recipe" then write_recipe content
871
- when "resource" then write_resource "foo", content
872
- when "template" then write_file "cookbooks/example/templates/default/foo.erb",
873
- content
874
- else raise "Unrecognised component: #{component}"
875
- end
876
- end
877
-
878
- Given /^a cookbook with a single recipe for which the first hash (key|value) is an interpolated string$/ do |key_or_value|
879
- write_recipe case key_or_value
880
- when "key" then %q{{"#{foo}" => 'bar', 'bar' => 'foo'}}
881
- when "value" then %q{{'foo' => "#{bar}", 'bar' => 'foo'}}
882
- end
883
- end
884
-
885
- Given "a cookbook with a single recipe that mixes node access types in an interpolated value" do
886
- write_recipe %q{
887
- execute "interpolated-example" do
888
- command "#{node['foo'][:bar]}'"
889
- end
890
- }
891
- end
892
-
893
- Given "a cookbook with a single recipe that accesses multiple node attributes via symbols" do
894
- write_recipe %q{
895
- node[:foo] = 'bar'
896
- node[:testing] = 'bar'
897
- }
898
- end
899
-
900
- Given "a cookbook with a single recipe that reads node attributes via symbols and quoted_symbols" do
901
- write_recipe %q{default[:foo][:'bar-baz']}
902
- end
903
-
904
- Given /^a cookbook with a single recipe that triggers FC019 with comment (.*)$/ do |comment|
905
- write_recipe %Q{
906
- file node[:bar] do
907
- content node['foo'] #{comment}
908
- action:create
909
- end
910
- }.strip
911
- end
912
-
913
- Given "a cookbook with a single recipe that calls a patched node method" do
914
- write_library "search", %q{
915
- class Chef
916
- class Node
917
- def in_tier?(*tier)
918
- tier.flatten.include?(node['tier'])
919
- end
920
- end
921
- end
922
- }
923
- write_recipe %q{
924
- if node['something']['bar'] || node.in_tier?('foof')
925
- Chef::Log.info("Node has been patched")
926
- end
927
- }
928
- end
929
-
930
- Given /^a cookbook with a single recipe that explicitly calls a node method( with multiple arguments)?$/ do |multi|
931
- write_recipe %Q{
932
- if node[:bar] and node.foo(#{multi ? 'bar, baz' : ''})
933
- Chef::Log.info('Explicit node method call should be ignored')
934
- end
935
- }
936
- end
937
-
938
- Given "a cookbook with a single recipe that uses a hash value to access a node attribute" do
939
- write_recipe %q{
940
- some_hash = {
941
- :key => "value"
942
- }
943
- execute "accesses-hash" do
944
- command "echo #{node['foo'][some_hash[:key]]}"
945
- end
946
- }.strip
947
- end
948
-
949
- Given /a(nother)? cookbook with a single recipe that (reads|updates|ignores)(nested)? node attributes via ([a-z,]*)(?:(?: and calls node\.)?([a-z_?]+)?| with (.*)?)(?: only)?$/ do |more_than_one, op, nested, types, method, expr|
950
- cookbook_name = more_than_one.nil? ? "example" : "another_example"
951
-
952
- access = if nested.nil?
953
- { :strings => "['foo']", :symbols => "[:foo]", :vivified => ".foo" }
954
- else
955
- { :strings => "['bar']['baz']", :symbols => "[:fee][:fi][:fo][:fum]", :vivified => ".bar.baz" }
956
- end
957
-
958
- recipe_content =
959
- (if types == "none"
960
- "log 'hello world'"
961
- elsif op == "reads"
962
- types.split(",").map { |type| "log node#{access[type.to_sym]}" }.join("\n")
963
- else
964
- types.split(",").map { |type| "node#{access[type.to_sym]} = 'foo'" }.join("\n")
965
- end)
966
-
967
- recipe_content += "\n#{expr}"
968
-
969
- unless method.nil?
970
- recipe_content += { :platform? => "node.platform?('redhat')",
971
- :run_list => "log 'hello' if node.run_list.roles.include?(node[:foo][:bar])",
972
- :run_state => "node.run_state[:reboot_requested] = true",
973
- :set => "node.set['foo']['bar']['baz'] = 'secret'" }[method.to_sym]
974
- end
975
-
976
- write_recipe(recipe_content, cookbook_name)
977
-
978
- end
979
-
980
- Given "a cookbook with a single recipe which accesses node attributes with symbols on lines 2 and 10" do
981
- write_recipe %q{
982
- # Here we access the node attributes via a symbol
983
- foo = node[:foo]
984
-
985
- directory "/tmp/foo" do
986
- owner "root"
987
- group "root"
988
- action :create
989
- end
990
-
991
- bar = node[:bar]
992
- }
993
- end
994
-
995
- Given /^a cookbook with a single recipe that creates a directory resource with (.*)$/ do |path_type|
996
- recipe_with_dir_path({ "an interpolated name" => :interpolated_symbol,
997
- "an interpolated name from a string" => :interpolated_string,
998
- "a string literal" => :string_literal,
999
- "a compound expression" => :compound_symbols,
1000
- "an interpolated variable and a literal" => :interpolated_symbol_and_literal,
1001
- "a literal and interpolated variable" => :literal_and_interpolated_symbol }[path_type])
1002
- end
1003
-
1004
- Given "a cookbook with a single recipe that logs an interpolated string heredoc" do
1005
- write_recipe %q(
1006
- Chef::Log.warn <<-LOG
1007
- Warning stuff has gone wrong: #{stuff}
1008
- LOG
1009
- )
1010
- end
1011
-
1012
- Given "a cookbook with five recipes" do
1013
-
1014
- end
1015
-
1016
- Given /^a directory that contains a role file ([^ ]+) in (json|ruby) that defines role name (.*)$/ do |file_name, format, role_name|
1017
- role(:role_name => %Q{"#{role_name}"}, :file_name => file_name, :format => format.to_sym)
1018
- end
1019
-
1020
- Given /^a directory that contains an environment file (.*) in ruby that defines environment name (.*)$/ do |file_name, env_name|
1021
- environment(:environment_name => %Q{"#{env_name}"}, :file_name => "production.rb")
1022
- end
1023
-
1024
- Given /^a ([a-z_]+) resource declared with the mode ([^\s]+)(?: with comment (.*)?)?$/ do |resource, mode, comment|
1025
- recipe_resource_with_mode(resource, mode, comment)
1026
- end
1027
-
1028
- Given "a file resource declared without a mode" do
1029
- write_recipe %q{
1030
- file "/tmp/something" do
1031
- action :delete
1032
- end
1033
- }
1034
- end
1035
-
1036
- Given /^a file with multiple errors on one line(?: with comment (.*))?$/ do |comment|
1037
- write_file "cookbooks/example/recipes/default.rb", %Q{node['run_state']['nginx_force_recompile'] = "\#{foo}"#{comment}}
1038
- end
1039
-
1040
- Given(/^a LWRP with an action :create that notifies with (converge_by|updated_by_last_action) and another :delete that does not notify$/) do |notify_type|
1041
- cookbook_with_lwrp_actions([
1042
- { :name => :create, :notify_type => notify_type.to_sym },
1043
- { :name => :delete, :notify_type => :none },
1044
- ])
1045
- end
1046
-
1047
- Given /^(?:a roles|an environments) directory$/ do
1048
-
1049
- end
1050
-
1051
- Given /^a Rakefile that defines (no lint task|a lint task with no block|a lint task with an empty block|a lint task with a block setting options to)(.*)?$/ do |task, options|
1052
- rakefile(
1053
- case task
1054
- when /no block/ then :no_block
1055
- when /empty block/ then :empty_block
1056
- when /a block/ then :block
1057
- end,
1058
- options.strip.empty? ? {} : { :options => options.strip })
1059
- end
1060
-
1061
- Given /^a Rakefile that defines a lint task specifying files to lint as (.*)$/ do |files|
1062
- rakefile(:block, :files => files)
1063
- end
1064
-
1065
- Given "a Rakefile that defines a lint task specifying a different name" do
1066
- rakefile(:block, :name => "lint")
1067
- end
1068
-
1069
- Given "a recipe that contains a ruby block without a block attribute" do
1070
- write_recipe %q{
1071
- ruby_block "missing block" do
1072
- puts "Missing a block attribute"
1073
- end
1074
- }
1075
- end
1076
-
1077
- Given "a recipe that contains both long and short ruby blocks" do
1078
- recipe_with_ruby_block(:both)
1079
- end
1080
-
1081
- Given /^a recipe that declares a ([^ ]+) resource with these attributes: (.*)$/ do |type, attributes|
1082
- recipe_with_resource(type, attributes.split(","))
1083
- end
1084
-
1085
- Given "a recipe that declares a resource with an attribute value set to the result of a method call" do
1086
- write_recipe %q{
1087
- cron "run a command at a random minute" do
1088
- user "root"
1089
- minute rand(60)
1090
- command "/usr/bin/whatever"
1091
- end
1092
- }
1093
- end
1094
-
1095
- Given "a recipe that declares a resource with only a name attribute" do
1096
- write_recipe %q{
1097
- package 'foo'
1098
- }
1099
- end
1100
-
1101
- Given "a recipe that declares a resource with recognised attributes and a conditional execution ruby block" do
1102
- write_recipe %q{
1103
- file "/tmp/something" do
1104
- owner "root"
1105
- group "root"
1106
- mode "0755"
1107
- not_if do
1108
- require 'foo'
1109
- Foo.bar?(filename)
1110
- end
1111
- action :create
1112
- end
1113
- }
1114
- end
1115
-
1116
- Given "a recipe that declares a resource with recognised attributes and a nested block" do
1117
- write_recipe %q{
1118
- deploy_revision "foo" do
1119
- revision "HEAD"
1120
- repository "git://github.com/git/git.git"
1121
- deploy_to "/foo"
1122
- action :deploy
1123
- before_migrate do
1124
- execute "bundle install" do
1125
- cwd release_path
1126
- action :run
1127
- end
1128
- end
1129
- end
1130
- }
1131
- end
1132
-
1133
- Given "a recipe that declares a resource with standard attributes" do
1134
- write_recipe %q{
1135
- file "/tmp/something" do
1136
- owner "root"
1137
- group "root"
1138
- mode "0755"
1139
- action :create
1140
- end
1141
- }
1142
- end
1143
-
1144
- Given "a recipe that declares a user-defined resource" do
1145
- write_recipe %q{
1146
- apple "golden-delicious" do
1147
- colour "yellow"
1148
- action :consume
1149
- end
1150
- }
1151
- end
1152
-
1153
- Given "a recipe that declares multiple resources of the same type of which one has a bad attribute" do
1154
- write_recipe %q{
1155
- file "/tmp/something" do
1156
- owner "root"
1157
- group "root"
1158
- mode "0755"
1159
- action :create
1160
- end
1161
- file "/tmp/something" do
1162
- punter "root"
1163
- group "root"
1164
- mode "0755"
1165
- action :create
1166
- end
1167
- package "foo" do
1168
- action :install
1169
- end
1170
- }
1171
- end
1172
-
1173
- Given "a resource declared with a guard within a loop with multiple block arguments" do
1174
- write_recipe %q{
1175
- {
1176
- 'foo' => 'bar',
1177
- 'baz' => 'bing',
1178
- }.each do |foo, bar|
1179
- package bar do
1180
- not_if { node['foo'] == foo }
1181
- action :install
1182
- end
1183
- end
1184
- }
1185
- end
1186
-
1187
- Given "a resource that declares a guard containing a block" do
1188
- write_recipe %q{
1189
- template '/etc/foo' do
1190
- not_if do
1191
- s = false
1192
- node['mylist'].each do |realm|
1193
- s = node['mylist'][realm].empty?
1194
- break if s
1195
- end
1196
- s
1197
- end
1198
- owner 'root'
1199
- group 'root'
1200
- mode '0644'
1201
- source 'foo.erb'
1202
- end
1203
- }
1204
- end
1205
-
1206
- Given "a resource declared within a definition" do
1207
- write_recipe %q{
1208
- define :toto, {
1209
- } do
1210
- [:a, :b].each do |x|
1211
- package x do
1212
- not_if { node['foo'] == x }
1213
- action :install
1214
- end
1215
- end
1216
- end
1217
- }
1218
- end
1219
-
1220
- Given /^a rule that (declares|does not declare) a version constraint(?: of ([^ ]+)? to ([^ ]+)?)?$/ do |constraint, from, to|
1221
- if from || to
1222
- rule_with_version_constraint(from, to)
1223
- else
1224
- from_version = case constraint
1225
- when /not/ then nil
1226
- else "0.10.6"
1227
- end
1228
- rule_with_version_constraint(from_version, nil)
1229
- end
1230
- end
1231
-
1232
- Given /^a template that includes a partial( that includes the original template again)?$/ do |loops|
1233
- write_recipe %q{
1234
- template "/tmp/a" do
1235
- source "a.erb"
1236
- variables({
1237
- :config_var => "foo"
1238
- })
1239
- end
1240
- }
1241
- write_file "cookbooks/example/templates/default/a.erb", '<%= render "b.erb" %>'
1242
- content = if loops
1243
- '<%= render "a.erb" %>'
1244
- else
1245
- "<%= @config_var %>"
1246
- end
1247
- write_file "cookbooks/example/templates/default/b.erb", content
1248
- end
1249
-
1250
- Given /^a template that includes a (missing )?partial with a relative subdirectory path$/ do |missing|
1251
- write_recipe %q{
1252
- template "/tmp/a" do
1253
- source "a.erb"
1254
- variables({
1255
- :config_var => "foo"
1256
- })
1257
- end
1258
- }
1259
- write_file "cookbooks/example/templates/default/a.erb", '<%= render "partials/b.erb" %>'
1260
- unless missing
1261
- write_file "cookbooks/example/templates/default/partials/b.erb", "Partial content"
1262
- end
1263
- end
1264
-
1265
- Given "access to the man page documentation" do
1266
-
1267
- end
1268
-
1269
- Given "I have installed the lint tool" do
1270
-
1271
- end
1272
-
1273
- Given "metadata" do
1274
- write_metadata %q{
1275
- name 'example'
1276
- }.strip
1277
- end
1278
-
1279
- Given /^(?:a cookbook that has|the cookbook has) a Gemfile that includes rake and foodcritic$/ do
1280
- buildable_gemfile
1281
- end
1282
-
1283
- Given /^the current stable version of Chef (falls|does not fall) within it$/ do |falls_within|
1284
- rule_with_version_constraint("98.10", nil) unless falls_within.include?("falls")
1285
- end
1286
-
1287
- Given "the gems have been vendored" do
1288
- vendor_gems
1289
- end
1290
-
1291
- Given /^the inferred template contains the expression (.*)$/ do |expr|
1292
- write_file "cookbooks/example/templates/default/config.conf.erb", %Q{
1293
- <%= #{expr} %>
1294
- }
1295
- end
1296
-
1297
- Given /^the template (.+)?contains the expression (.*)$/ do |ext, expr|
1298
- file = if ext
1299
- "templates/default/config#{ext.strip}"
1300
- else
1301
- "templates/default/config.conf.erb"
1302
- end
1303
- write_file "cookbooks/example/#{file}", %Q{
1304
- <%= #{expr} %>
1305
- }
1306
- end
1307
-
1308
- Given /^the template (.+)?contains partial includes of type (.*) with the expression (.*)$/ do |ext, type, expr|
1309
- file = if ext
1310
- "config#{ext.strip}"
1311
- else
1312
- "config.conf.erb"
1313
- end
1314
- if type == "nested" && expr.split(",").length > 1
1315
- expressions = expr.split(",")
1316
- includes = (1..expressions.length).map { |i| "included_template_#{i}.erb" }
1317
- (Array(file) + includes).zip(includes).map do |parent, child|
1318
- content = if child
1319
- "<%= render '#{child}' %>"
1320
- else
1321
- expressions.map { |e| "<%= #{e} %>" }.join("\n")
1322
- end
1323
- [parent, content]
1324
- end.each do |template_name, content|
1325
- write_file "cookbooks/example/templates/default/#{template_name}", content
1326
- end
1327
- else
1328
- if type == "no parentheses"
1329
- include_string = "<%= render 'included_template.erb' %>"
1330
- else
1331
- include_string = "<%= render('included_template.erb') %>"
1332
- end
1333
- write_file "cookbooks/example/templates/default/#{file}", %Q{
1334
- #{include_string}
1335
- }
1336
- write_file "cookbooks/example/templates/default/included_template.erb", %Q{
1337
- <%= #{expr} %>
1338
- }
1339
- end
1340
- end
1341
-
1342
- Given "unit tests under a top-level test directory" do
1343
- minitest_spec_attributes
1344
- end
1345
-
1346
- Given "a recipe that includes dsc_resource with the module_version attribute" do
1347
- write_recipe %q{
1348
- dsc_resource 'foo' do
1349
- resource :something
1350
- module_name 'foo'
1351
- module_version '1.0.0.0'
1352
- end
1353
- }
1354
- end
1355
-
1356
- Given /^a ruby environment that triggers FC050 with comment (.*)$/ do |comment|
1357
- write_file "environments/production.rb", %Q{
1358
- name "Production (eu-west-1)" #{comment}
1359
- run_list "recipe[apache2]"
1360
- }.strip
1361
- end
1362
-
1363
- Given /^a ruby role that triggers FC049 with comment (.*)$/ do |comment|
1364
- write_file "roles/webserver.rb", %Q{
1365
- name "apache" #{comment}
1366
- run_list "recipe[apache2]"
1367
- }.strip
1368
- end
1369
-
1370
- Given /^a template directory that contains a binary file (.*) that is not valid UTF-8$/ do |filename|
1371
- template_dir = "cookbooks/example/templates/default"
1372
- write_recipe ""
1373
- write_file "#{template_dir}/innocent_template.erb", "<%= hello %>"
1374
- File.open("#{expand_path('.')}/#{template_dir}/#{filename}", "wb") { |f| f.putc(0x93) }
1375
- end
1376
-
1377
- Given "each role directory has a role with a name that does not match the containing file name" do
1378
- role(:dir => "roles1", :role_name => '"apache"', :file_name => "webserver.rb")
1379
- role(:dir => "roles2", :role_name => '"postgresql"', :file_name => "database.rb")
1380
- end
1381
-
1382
- Given /^it contains an environment file (.*\.rb) that defines the environment name (.*)$/ do |file_name, env_name|
1383
- environment(:environment_name => env_name, :file_name => file_name)
1384
- end
1385
-
1386
- Given /^it contains a role file ([a-z]+\.rb) that defines the role name (.*)$/ do |file_name, role_name|
1387
- role(:role_name => role_name, :file_name => file_name)
1388
- end
1389
-
1390
- Given /^the cookbook metadata declares support for (.*)$/ do |supported_platforms|
1391
- write_metadata(supported_platforms.split(",").map do |platform|
1392
- "supports '#{platform}'"
1393
- end.join("\n"))
1394
- end
1395
-
1396
- Given "the cookbook metadata declares support with versions specified" do
1397
- write_metadata %q{
1398
- supports 'redhat', '>= 6'
1399
- supports 'scientific', '>= 6'
1400
- }.strip
1401
- end
1402
-
1403
- Given "three of the recipes read node attributes via strings" do
1404
- (1..3).map { |i| "string_#{i}" }.each do |recipe|
1405
- write_file "cookbooks/example/recipes/#{recipe}.rb", "Chef::Log.warn node['foo']"
1406
- end
1407
- end
1408
-
1409
- Given "two of the recipes read node attributes via symbols" do
1410
- (1..2).map { |i| "symbol_#{i}" }.each do |recipe|
1411
- write_file "cookbooks/example/recipes/#{recipe}.rb", "Chef::Log.warn node[:foo]"
1412
- end
1413
- end
1414
-
1415
- Given "two roles directories" do
1416
-
1417
- end
1418
-
1419
- When /^I check the cookbook specifying ([^ ]+) as the Chef version$/ do |version|
1420
- options = ["-c", version, "cookbooks/example"]
1421
- cd "." do
1422
- options = ["-I", "rules/test.rb"] + options if Dir.exist?("rules")
1423
- end
1424
- options += %w{--no-progress}
1425
- run_lint(options)
1426
- end
1427
-
1428
- When /^I check the cookbook( tree)?(?: specifying tags(.*))?(, specifying that context should be shown)?$/ do |whole_tree, tags, context|
1429
- options = tags.nil? ? [] : tags.split(" ")
1430
- options += ["-C"] unless context.nil?
1431
- options += %w{--no-progress}
1432
- run_lint(options + ["cookbooks/#{whole_tree.nil? ? 'example' : ''}"])
1433
- end
1434
-
1435
- Given /^the cookbook directory has a \.foodcritic file specifying tags (.*)$/ do |tags|
1436
- write_file "cookbooks/example/.foodcritic", tags
1437
- run_lint(["--no-progress", "cookbooks/example"])
1438
- end
1439
-
1440
- When /^I check both cookbooks with the command-line (.*)$/ do |command_line|
1441
- cmds = command_line.split(" ").map do |c|
1442
- if c.end_with?("example")
1443
- "cookbooks/#{c}"
1444
- else
1445
- c
1446
- end
1447
- end
1448
- run_lint(%w{--no-progress} + cmds)
1449
- end
1450
-
1451
- When "I check both roles directories" do
1452
- run_lint ["--no-progress", "-R", "roles1", "-R", "roles2"]
1453
- end
1454
-
1455
- When "I check the cookbooks, role and environment together" do
1456
- run_lint([
1457
- "--no-progress",
1458
- "-B", "cookbooks/another_example", "-B", "cookbooks/example",
1459
- "-E", "environments",
1460
- "-R", "roles"
1461
- ])
1462
- end
1463
-
1464
- When "I check the cookbook without specifying a Chef version" do
1465
- run_lint(["--no-progress", "-I", "rules/test.rb", "cookbooks/example"])
1466
- end
1467
-
1468
- When "I check the environment directory" do
1469
- run_lint ["--no-progress", "-E", "environments"]
1470
- end
1471
-
1472
- When "I check the eu environment file only" do
1473
- run_lint ["--no-progress", "-E", "environments/production_eu.rb"]
1474
- end
1475
-
1476
- When /^I check the cookbook( without)? excluding the ([^ ]+) directory$/ do |no_exclude, dir|
1477
- options = no_exclude.nil? ? ["-X", dir] : []
1478
- run_lint(options + ["--no-progress", "cookbooks/example"])
1479
- end
1480
-
1481
- When "I check the recipe" do
1482
- run_lint(["--no-progress", "cookbooks/example/recipes/default.rb"])
1483
- end
1484
-
1485
- When "I compare the man page options against the usage options" do
1486
-
1487
- end
1488
-
1489
- When "I check the role directory" do
1490
- run_lint ["--no-progress", "-R", "roles"]
1491
- end
1492
-
1493
- When "I check the webserver role only" do
1494
- run_lint ["--no-progress", "-R", "roles/webserver.rb"]
1495
- end
1496
-
1497
- When "I list the available build tasks" do
1498
- list_available_build_tasks
1499
- end
1500
-
1501
- When /^I run it on the command line including a custom rule (file|directory) containing a rule that matches$/ do |path_type|
1502
- write_file "rules/custom_rules.rb", %q{
1503
- rule "BAR001", "Use symbols in preference to strings to access node attributes" do
1504
- tags %w{style attributes}
1505
- recipe do |ast|
1506
- attribute_access(ast, :type => :string).map{|ar| match(ar)}
1507
- end
1508
- end
1509
- }
1510
- run_lint(["--no-progress", "-I",
1511
- path_type == "file" ? "rules/custom_rules.rb" : "rules",
1512
- "cookbooks/example"])
1513
- end
1514
-
1515
- When /^I run it on the command line including a file which does not contain Ruby code$/ do
1516
- write_file "rules/invalid_rules.rb", 'echo "not ruby"'
1517
- capture_error do
1518
- run_lint(["--no-progress", "-I", "rules/invalid_rules.rb", "cookbooks/example"])
1519
- end
1520
- end
1521
-
1522
- When /^I run it on the command line including a missing custom rule file$/ do
1523
- capture_error do
1524
- run_lint(["--no-progress", "-I", "rules/missing_rules.rb", "cookbooks/example"])
1525
- end
1526
- end
1527
-
1528
- When "I run it on the command line specifying a cookbook that does not exist" do
1529
- run_lint(["--no-progress", "no-such-cookbook"])
1530
- end
1531
-
1532
- When /^I run it on the command line specifying a( role|n environment) directory that does not exist$/ do |type|
1533
- if type.include?("role")
1534
- run_lint(["--no-progress", "-R", "no-such-role-dir"])
1535
- else
1536
- run_lint(["--no-progress", "-E", "no-such-environment-dir"])
1537
- end
1538
- end
1539
-
1540
- When "I run it on the command line with no arguments" do
1541
- run_lint([])
1542
- end
1543
-
1544
- When /^I run it on the command line with the (?:unimplemented |)([^ ]+) option( with an argument)?$/ do |option, with_argument|
1545
- options = []
1546
- if option =~ /\-\w$/
1547
- options << option
1548
- else
1549
- options << "--#{option}"
1550
- end
1551
- options << "cookbooks/example" unless with_argument.nil?
1552
- run_lint(options)
1553
- end
1554
-
1555
- When "I run the build" do
1556
- run_build
1557
- end
1558
-
1559
- Then "a warning for the custom rule should be displayed" do
1560
- expect_output("BAR001: Use symbols in preference to strings to access node attributes: cookbooks/example/recipes/default.rb:1")
1561
- end
1562
-
1563
- Then "all options should be documented in the man page" do
1564
- man_page_options.must_equal usage_options_for_diff
1565
- end
1566
-
1567
- Then /^an? '([^']+)' error should be displayed$/ do |expected_error|
1568
- last_error.must_include expected_error
1569
- end
1570
-
1571
- Then "the attribute consistency warning 019 should be shown for both of the recipes that use symbols" do
1572
- expect_warning "FC019", :file => "recipes/symbol_1.rb"
1573
- expect_warning "FC019", :file => "recipes/symbol_2.rb"
1574
- end
1575
-
1576
- Then /^the bare attribute keys warning 044 should not be displayed against the (brace|do) block$/ do |block_type|
1577
- line = block_type == "brace" ? 2 : 3
1578
- expect_warning "FC044", { :expect_warning => false, :line => line, :file_type => :attributes }
1579
- end
1580
-
1581
- Then /^the bare attribute keys warning 044 should not be displayed against the (?:local variable|library call)$/ do
1582
- expect_warning "FC044", { :expect_warning => false, :line => 2, :file_type => :attributes }
1583
- end
1584
-
1585
- Then /^the bare attribute keys warning 044 should not be displayed against the new line$/ do
1586
- expect_warning "FC044", { :expect_warning => false, :line => 3, :file_type => :attributes }
1587
- end
1588
-
1589
- Then "the execute resource used to run git commands warning 040 should be displayed against the last resource" do
1590
- expect_warning "FC040", { :line => 7 }
1591
- end
1592
-
1593
- Then /^the invalid (role|environment) name warning 050 should( not)? be shown$/ do |type, not_shown|
1594
- file = type == "role" ? "roles/webserver.rb" : "environments/production.rb"
1595
- expect_warning "FC050", { :expect_warning => ! not_shown, :file => file }
1596
- end
1597
-
1598
- Then /^the invalid environment name warning 050 should( not)? be shown against the (eu|us) environment$/ do |not_shown, env|
1599
- expect_warning "FC050", { :expect_warning => ! not_shown,
1600
- :file => "environments/production_#{env}.rb", :line => 1 }
1601
- end
1602
-
1603
- Then /^the role name does not match file name warning 049 should( not)? be shown( against the second name)?$/ do |not_shown, second|
1604
- expect_warning "FC049", { :expect_warning => ! not_shown,
1605
- :file => "roles/webserver.rb", :line => second ? 2 : 1 }
1606
- end
1607
-
1608
- Then "the role name does not match file name warning 049 should be shown against the files in both directories" do
1609
- expect_warning "FC049", { :file => "roles1/webserver.rb", :line => 1 }
1610
- expect_warning "FC049", { :file => "roles2/database.rb", :line => 1 }
1611
- end
1612
-
1613
- Then /^the role name does not match file name warning 049 should( not)? be shown against the (webserver|database) role$/ do |not_shown, role|
1614
- expect_warning "FC049", { :expect_warning => ! not_shown,
1615
- :file => "roles/#{role}.rb", :line => 1 }
1616
- end
1617
-
1618
- Then "the long ruby block warning 014 should be displayed against the long block only" do
1619
- expect_warning "FC014", { :expect_warning => false, :line => 1 }
1620
- expect_warning "FC014", { :expect_warning => true, :line => 11 }
1621
- end
1622
-
1623
- Then /^the lint task will be listed( under the different name)?$/ do |diff_name|
1624
- expected_name = diff_name ? "lint" : "foodcritic"
1625
- build_tasks.must_include([expected_name, "Lint Chef cookbooks"])
1626
- end
1627
-
1628
- Then /^(no )?warnings will be displayed against the tests$/ do |no_display|
1629
- if no_display.nil?
1630
- assert_test_warnings
1631
- else
1632
- assert_no_test_warnings
1633
- end
1634
- end
1635
-
1636
- Then "the attribute consistency warning 019 should be displayed for the recipe" do
1637
- expect_warning("FC019", :line => 2)
1638
- end
1639
-
1640
- Then "the attribute consistency warning 019 should not be displayed for the attributes" do
1641
- expect_warning("FC019", :file_type => :attributes, :line => 1, :expect_warning => false)
1642
- end
1643
-
1644
- Then /^the warning ([0-9]+ )?should (not )?be (?:displayed|shown)$/ do |warning, should_not|
1645
- code = warning.nil? ? "FCTEST001" : "FC#{warning.strip}"
1646
- expect_warning code, { :expect_warning => should_not.nil? }
1647
- end
1648
-
1649
- Then /^the (?:[a-zA-Z \-_]+) warning ([0-9]+) should (not )?be displayed(?: against the (attributes|libraries|definition|metadata|provider|resource|README.md|README.rdoc) file)?( below)?(?: on (?:(any line)|(?:line ([0-9]+))))?$/ do |code, no_display, file, warning_only, any_line, line|
1650
- options = {}
1651
- options[:expect_warning] = no_display != "not "
1652
- unless file.nil?
1653
- if file.include?(".")
1654
- options[:file] = file
1655
- else
1656
- options[:file_type] = file.to_sym
1657
- end
1658
- end
1659
- options[:line] = 3 if code == "018" && options[:expect_warning]
1660
- options[:line] = 2 if %w{021 022}.include?(code)
1661
-
1662
- if any_line
1663
- options[:line] = nil
1664
- else
1665
- options[:line] = line unless line.nil?
1666
- end
1667
-
1668
- options[:warning_only] = ! warning_only.nil?
1669
- expect_warning("FC#{code}", options)
1670
- end
1671
-
1672
- Then /^the attribute consistency warning 019 should be (shown|not shown)$/ do |show_warning|
1673
- expect_warning("FC019", :line => nil, :expect_warning => show_warning == "shown")
1674
- end
1675
-
1676
- Then /the build status should be (successful|failed)$/ do |build_outcome|
1677
- build_outcome == "successful" ? assert_no_error_occurred : assert_error_occurred
1678
- end
1679
-
1680
- Then /^the build will (succeed|fail) with (?:no )?warnings(.*)$/ do |build_outcome, warnings|
1681
- assert_build_result(build_outcome == "succeed", warnings.delete(" ").split(","))
1682
- end
1683
-
1684
- Then /^the consider adding platform warning 024 should( not)? be shown$/ do |should_not|
1685
- expect_warning("FC024", :line => should_not.nil? ? @expected_line : nil, :expect_warning => should_not.nil?)
1686
- end
1687
-
1688
- Then /^the conditional block contains only string warning 026 should be (shown|not shown)$/ do |show_warning|
1689
- expect_warning("FC026", :line => nil, :expect_warning => show_warning == "shown")
1690
- end
1691
-
1692
- Then /^the current version should( not)? be displayed$/ do |no_display|
1693
- version_str = "foodcritic #{FoodCritic::VERSION}"
1694
- if no_display.nil?
1695
- expect_output(version_str)
1696
- else
1697
- expect_no_output(version_str)
1698
- end
1699
- end
1700
-
1701
- Then /^the debugger breakpoint warning 030 should be (not )?shown against the (.*)$/ do |should_not, component|
1702
- filename = case component
1703
- when "library" then "libraries/foo.rb"
1704
- when "metadata" then "metadata.rb"
1705
- when "provider" then "providers/foo.rb"
1706
- when "recipe" then "recipes/default.rb"
1707
- when "resource" then "resources/foo.rb"
1708
- when "template" then "templates/default/foo.erb"
1709
- end
1710
- expect_warning("FC030", :line => nil, :expect_warning => should_not.nil?, :file => filename)
1711
- end
1712
-
1713
- Then "the dodgy resource condition warning 022 should not be shown" do
1714
- expect_warning("FC022", { :line => nil, :expect_warning => false })
1715
- end
1716
-
1717
- Then /^the warning (\w+) should be (valid|invalid)$/ do |code, valid|
1718
- code = "FC#{code}"
1719
- valid == "valid" ? expect_no_warning(code) : expect_warning(code)
1720
- end
1721
-
1722
- Then /^the line number and line of code that triggered the warning(s)? should be displayed$/ do |multiple|
1723
- if multiple.nil?
1724
- expect_line_shown 1, "log node[:foo]"
1725
- else
1726
- expect_line_shown 1, "node[:foo] = 'bar'"
1727
- expect_line_shown 2, " node[:testing] = 'bar'"
1728
- end
1729
- end
1730
-
1731
- Then "the missing template warning 033 should not be displayed against the template" do
1732
- expect_warning("FC033", :line => 3, :expect_warning => false)
1733
- end
1734
-
1735
- Then "the node access warning 001 should warn on lines 2 and 10 in that order" do
1736
- expected_warnings = [2, 10].map do |line|
1737
- "FC001: Use strings in preference to symbols to access node attributes: cookbooks/example/recipes/default.rb:#{line}"
1738
- end
1739
- expect_output(expected_warnings.join("\n"))
1740
- end
1741
-
1742
- Then "the recipe filename should be displayed" do
1743
- expect_output "cookbooks/example/recipes/default.rb"
1744
- end
1745
-
1746
- Then /^the resource sets internal attribute warning 027 should be (not )?shown$/ do |should_not|
1747
- expect_warning("FC027", :line => nil, :expect_warning => should_not.nil?)
1748
- end
1749
-
1750
- Then /^the service resource warning 005 should( not)? be visible$/ do |dont_show|
1751
- expect_warning("FC005", :line => dont_show ? 2 : 7, :expect_warning => ! dont_show)
1752
- end
1753
-
1754
- Then /^the service resource warning 005 should( not)? be displayed against the first resource in the block$/ do |dont_show|
1755
- expect_warning("FC005", :line => 2, :expect_warning => ! dont_show)
1756
- end
1757
-
1758
- Then /^the service resource warning 005 should( not)? be shown$/ do |dont_show|
1759
- expect_warning("FC005", :line => 2, :file_type => :provider,
1760
- :expect_warning => ! dont_show)
1761
- end
1762
-
1763
- Then /^the simple usage text should be displayed along with a (non-)?zero exit code$/ do |non_zero|
1764
- usage_displayed(non_zero.nil?)
1765
- end
1766
-
1767
- Then /^the template partials loop indefinitely warning 051 should (not )?be displayed against the templates$/ do |not_shown|
1768
- expect_warning("FC051", :file => "templates/default/a.erb", :line => 1,
1769
- :expect_warning => ! not_shown)
1770
- expect_warning("FC051", :file => "templates/default/b.erb", :line => 1,
1771
- :expect_warning => ! not_shown)
1772
- end
1773
-
1774
- Then /^the unused template variables warning 034 should (not )?be displayed against the (?:inferred )?template(.*)?$/ do |not_shown, ext|
1775
- file = if ext.empty?
1776
- "templates/default/config.conf.erb"
1777
- else
1778
- "templates/default/config#{ext.strip}"
1779
- end
1780
- expect_warning("FC034", :file => file, :line => 1,
1781
- :expect_warning => ! not_shown)
1782
- end
1783
-
1784
- Then /^the unrecognised attribute warning 009 should be (true|false)$/ do |shown|
1785
- shown == "true" ? expect_warning("FC009") : expect_no_warning("FC009")
1786
- end
1787
-
1788
- Then "the unrecognised attribute warning 009 should be displayed against the correct resource" do
1789
- expect_warning("FC009", :line => 7)
1790
- end
1791
-
1792
- Then "the usage text should include an option for specifying tags that will fail the build" do
1793
- expect_usage_option("f", "epic-fail TAGS",
1794
- "Fail the build based on tags. Default of 'any' to fail on all warnings.")
1795
- end
1796
-
1797
- Then /^the warnings shown should be (.*)$/ do |warnings|
1798
- warnings.split(",").each { |warning| expect_warning(warning, :line => nil) }
1799
- end
1800
-
1801
- When /^I check the cookbook specifying a search grammar that (does not exist|is not in treetop format|is a valid treetop grammar)$/ do |search_grammar|
1802
- case search_grammar
1803
- when "is not in treetop format"
1804
- write_file("search.treetop", "I am not a valid treetop grammar")
1805
- when "is a valid treetop grammar"
1806
- write_file("search.treetop", IO.read(FoodCritic::Chef::Search.new.chef_search_grammars.first))
1807
- end
1808
- run_lint(["--no-progress", "--search-grammar", "search.treetop", "cookbooks/example"])
1809
- end
1810
-
1811
- Then /^the check should abort with an error$/ do
1812
- assert_error_occurred
1813
- end
1814
-
1815
- Given(/^a cookbook with an? (.*) file with an interpolated name$/) do |file_type|
1816
- content = %q{
1817
- a = "#{node.hostname}"
1818
- }
1819
- write_recipe content if file_type == "recipe"
1820
- write_attributes content if file_type == "attribute"
1821
- write_metadata content if file_type == "metadata"
1822
- write_provider "site", content if file_type == "provider"
1823
- write_resource "site", content if file_type == "resource"
1824
- write_definition "apache_site", content if file_type == "definition"
1825
- write_library "lib", content if file_type == "library"
1826
- end