foodcritic 10.2.2 → 10.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -2
  3. data/Gemfile +2 -1
  4. data/README.md +7 -1
  5. data/Rakefile +55 -35
  6. data/bin/foodcritic +1 -7
  7. data/features/024_check_for_missing_platforms.feature +3 -4
  8. data/features/continuous_integration_support.feature +2 -2
  9. data/features/step_definitions/cookbook_steps.rb +24 -285
  10. data/features/support/command_helpers.rb +3 -0
  11. data/foodcritic.gemspec +12 -6
  12. data/lib/foodcritic/api.rb +14 -2
  13. data/lib/foodcritic/command_line.rb +8 -0
  14. data/lib/foodcritic/linter.rb +1 -1
  15. data/lib/foodcritic/output.rb +17 -3
  16. data/lib/foodcritic/rules/fc008.rb +8 -6
  17. data/lib/foodcritic/rules/fc024.rb +1 -1
  18. data/lib/foodcritic/rules/fc045.rb +1 -8
  19. data/lib/foodcritic/rules/fc068.rb +1 -1
  20. data/lib/foodcritic/rules/fc069.rb +365 -0
  21. data/lib/foodcritic/rules/fc070.rb +63 -0
  22. data/lib/foodcritic/rules/fc071.rb +6 -0
  23. data/lib/foodcritic/rules/fc072.rb +6 -0
  24. data/lib/foodcritic/rules/fc073.rb +17 -0
  25. data/lib/foodcritic/rules/fc074.rb +10 -0
  26. data/lib/foodcritic/rules/fc075.rb +9 -0
  27. data/lib/foodcritic/version.rb +1 -1
  28. data/spec/functional/fc001_spec.rb +67 -0
  29. data/spec/functional/fc008_spec.rb +33 -0
  30. data/spec/functional/fc011_spec.rb +20 -0
  31. data/spec/functional/fc012_spec.rb +20 -0
  32. data/spec/functional/fc016_spec.rb +48 -0
  33. data/spec/functional/fc028_spec.rb +48 -0
  34. data/spec/functional/fc029_spec.rb +33 -0
  35. data/spec/functional/fc031_spec.rb +14 -0
  36. data/spec/functional/fc042_spec.rb +13 -0
  37. data/spec/functional/fc045_spec.rb +18 -0
  38. data/spec/functional/fc052_spec.rb +13 -0
  39. data/spec/functional/fc053_spec.rb +13 -0
  40. data/spec/functional/fc055_spec.rb +18 -0
  41. data/spec/functional/fc056_spec.rb +18 -0
  42. data/spec/functional/fc061_spec.rb +48 -0
  43. data/spec/functional/fc062_spec.rb +13 -0
  44. data/spec/functional/fc063_spec.rb +18 -0
  45. data/spec/functional/fc064_spec.rb +13 -0
  46. data/spec/functional/fc065_spec.rb +13 -0
  47. data/spec/functional/fc066_spec.rb +13 -0
  48. data/spec/functional/fc067_spec.rb +13 -0
  49. data/spec/functional/fc068_spec.rb +13 -0
  50. data/spec/functional/fc069_spec.rb +23 -0
  51. data/spec/functional/fc070_spec.rb +38 -0
  52. data/spec/functional/fc071_spec.rb +14 -0
  53. data/spec/functional/fc072_spec.rb +13 -0
  54. data/spec/functional/fc073_spec.rb +56 -0
  55. data/spec/functional/fc074_spec.rb +39 -0
  56. data/spec/functional/fc075_spec.rb +41 -0
  57. data/spec/functional/root_aliases_spec.rb +13 -0
  58. data/spec/regression/cookbooks.txt +0 -2
  59. data/spec/regression/expected/activemq.txt +5 -0
  60. data/spec/regression/expected/apparmor.txt +8 -0
  61. data/spec/regression/expected/apt.txt +12 -0
  62. data/spec/regression/expected/aws.txt +13 -0
  63. data/spec/regression/expected/bluepill.txt +6 -0
  64. data/spec/regression/expected/boost.txt +6 -0
  65. data/spec/regression/expected/build-essential.txt +6 -0
  66. data/spec/regression/expected/chef-client.txt +13 -0
  67. data/spec/regression/expected/chef-server.txt +12 -0
  68. data/spec/regression/expected/chef.txt +36 -0
  69. data/spec/regression/expected/chef_handler.txt +7 -0
  70. data/spec/regression/expected/cron.txt +7 -0
  71. data/spec/regression/expected/database.txt +13 -0
  72. data/spec/regression/expected/dmg.txt +12 -0
  73. data/spec/regression/expected/drbd.txt +25 -0
  74. data/spec/regression/expected/dynect.txt +29 -0
  75. data/spec/regression/expected/erlang.txt +4 -0
  76. data/spec/regression/expected/fail2ban.txt +4 -0
  77. data/spec/regression/expected/firewall.txt +12 -0
  78. data/spec/regression/expected/gecode.txt +8 -0
  79. data/spec/regression/expected/gems.txt +31 -0
  80. data/spec/regression/expected/gunicorn.txt +9 -0
  81. data/spec/regression/expected/heartbeat.txt +8 -0
  82. data/spec/regression/expected/homebrew.txt +8 -0
  83. data/spec/regression/expected/iis.txt +30 -0
  84. data/spec/regression/expected/iptables.txt +8 -0
  85. data/spec/regression/expected/jetty.txt +11 -0
  86. data/spec/regression/expected/jpackage.txt +8 -0
  87. data/spec/regression/expected/keepalived.txt +4 -0
  88. data/spec/regression/expected/kickstart.txt +14 -0
  89. data/spec/regression/expected/logwatch.txt +4 -0
  90. data/spec/regression/expected/lvm.txt +12 -0
  91. data/spec/regression/expected/maradns.txt +13 -0
  92. data/spec/regression/expected/maven.txt +9 -0
  93. data/spec/regression/expected/memcached.txt +30 -0
  94. data/spec/regression/expected/motd-tail.txt +4 -0
  95. data/spec/regression/expected/mysql.txt +12 -0
  96. data/spec/regression/expected/ohai.txt +6 -0
  97. data/spec/regression/expected/openldap.txt +10 -0
  98. data/spec/regression/expected/openssh.txt +4 -0
  99. data/spec/regression/expected/openssl.txt +5 -0
  100. data/spec/regression/expected/partial_search.txt +5 -0
  101. data/spec/regression/expected/passenger_apache2.txt +29 -0
  102. data/spec/regression/expected/perl.txt +11 -0
  103. data/spec/regression/expected/php.txt +9 -0
  104. data/spec/regression/expected/postfix.txt +6 -0
  105. data/spec/regression/expected/powershell.txt +8 -0
  106. data/spec/regression/expected/resolver.txt +6 -0
  107. data/spec/regression/expected/rsync.txt +10 -0
  108. data/spec/regression/expected/rsyslog.txt +8 -0
  109. data/spec/regression/expected/sql_server.txt +4 -0
  110. data/spec/regression/expected/sqlite.txt +4 -0
  111. data/spec/regression/expected/ssh_known_hosts.txt +5 -0
  112. data/spec/regression/expected/stompserver.txt +5 -0
  113. data/spec/regression/expected/subversion.txt +5 -0
  114. data/spec/regression/expected/sudo.txt +8 -0
  115. data/spec/regression/expected/tftp.txt +5 -0
  116. data/spec/regression/expected/tomcat.txt +8 -0
  117. data/spec/regression/expected/transmission.txt +10 -0
  118. data/spec/regression/expected/ubuntu.txt +4 -0
  119. data/spec/regression/expected/ufw.txt +9 -0
  120. data/spec/regression/expected/unicorn.txt +6 -0
  121. data/spec/regression/expected/users.txt +7 -0
  122. data/spec/regression/expected/vim.txt +6 -0
  123. data/spec/regression/expected/webpi.txt +7 -0
  124. data/spec/regression/expected/whitelist-node-attrs.txt +6 -0
  125. data/spec/regression/expected/windows.txt +57 -0
  126. data/spec/regression/expected/wix.txt +4 -0
  127. data/spec/regression/expected/xfs.txt +4 -0
  128. data/spec/regression/expected/xml.txt +4 -0
  129. data/spec/regression/expected/yum.txt +17 -0
  130. data/spec/regression/expected/zlib.txt +4 -0
  131. data/spec/regression/expected/zsh.txt +4 -0
  132. data/spec/regression/regression_spec.rb +16 -10
  133. data/spec/spec_helper.rb +115 -10
  134. data/spec/{foodcritic → unit}/api_spec.rb +549 -593
  135. data/spec/{foodcritic → unit}/chef_spec.rb +15 -15
  136. data/spec/unit/command_line_spec.rb +122 -0
  137. data/spec/{foodcritic → unit}/domain_spec.rb +12 -12
  138. data/spec/{foodcritic → unit}/linter_spec.rb +20 -35
  139. data/spec/{foodcritic → unit}/template_spec.rb +13 -13
  140. metadata +161 -33
  141. data/features/001_check_node_access.feature +0 -60
  142. data/features/008_check_for_boilerplate_metadata.feature +0 -25
  143. data/features/011_check_for_markdown_readme.feature +0 -20
  144. data/features/012_check_for_deprecated_readme_format.feature +0 -20
  145. data/features/016_check_for_no_lwrp_default_action.feature +0 -25
  146. data/features/028_check_for_incorrect_platform_method.feature +0 -20
  147. data/features/029_check_for_no_leading_cookbook_name.feature +0 -18
  148. data/features/031_check_for_metadata_existence.feature +0 -15
  149. data/features/042_check_for_deprecated_require_recipe.feature +0 -15
  150. data/features/045_check_for_cookbook_name_in_metadata.feature +0 -20
  151. data/features/052_check_for_metadata_using_suggests_keyword.feature +0 -15
  152. data/features/053_check_for_metadata_using_recommends_keyword.feature +0 -15
  153. data/features/055_check_for_no_maintainer.feature +0 -25
  154. data/features/056_check_for_no_maintainer_email.feature +0 -25
  155. data/features/061_valid_cookbook_version_should_be_defined.feature +0 -55
  156. data/features/062_cookbook_should_have_cookbook_version.feature +0 -50
  157. data/features/063_cookbook_incorrectly_depends_on_itself.feature +0 -15
  158. data/features/064_check_for_no_issues_url.feature +0 -25
  159. data/features/065_check_for_no_source_url.feature +0 -25
  160. data/features/066_check_for_no_chef_version_metadata.feature +0 -20
  161. data/features/067_check_for_no_supports_metadata.feature +0 -20
  162. data/features/068_check_for_no_license_metadata.feature +0 -20
  163. data/spec/foodcritic/command_line_spec.rb +0 -74
  164. data/spec/regression/expected-output.txt +0 -355
  165. data/spec/regression_helpers.rb +0 -37
@@ -0,0 +1,63 @@
1
+ rule "FC070", "Ensure supports metadata defines valid platforms" do
2
+ tags %w{metadata supermarket}
3
+ metadata do |ast, filename|
4
+ # Where did this come from? We pulled every unique platform for supermarket cookbooks
5
+ # and then looked at all the invalid names. Lots of typos and bad characters and then
6
+ # a few entirely made up platforms
7
+ bad_chars = [" ", "'", ",", "\"", "/", "]", "[", "{", "}", "-", "=", ">"]
8
+ invalid_platforms = %w{
9
+ aws
10
+ archlinux
11
+ amazonlinux
12
+ darwin
13
+ debuan
14
+ mingw32
15
+ mswin
16
+ mac_os_x_server
17
+ linux
18
+ oel
19
+ oraclelinux
20
+ rhel
21
+ schientific
22
+ scientificlinux
23
+ sles
24
+ solaris
25
+ true
26
+ ubundu
27
+ ubunth
28
+ ubunutu
29
+ windwos
30
+ xcp
31
+ }
32
+ matches = false
33
+
34
+ metadata_platforms = supported_platforms(ast).map { |x| x[:platform] }
35
+
36
+ metadata_platforms.each do |plat|
37
+ break if matches # we found one on the previous run so stop looking
38
+
39
+ # see if the platform is uppercase, which is invalid
40
+ unless plat.scan(/[A-Z]/).empty?
41
+ matches = true
42
+ break # stop looking
43
+ end
44
+
45
+ # search for platform strings with bad strings in them
46
+ # these can't possibly be valid platforms
47
+ bad_chars.each do |char|
48
+ unless plat.scan(char).empty?
49
+ matches = true
50
+ break # stop looking
51
+ end
52
+ end
53
+
54
+ # see if the platform is a commonly mistaken platform string
55
+ if invalid_platforms.include?(plat)
56
+ matches = true
57
+ break # stop looking
58
+ end
59
+ end
60
+
61
+ [file_match(filename)] if matches
62
+ end
63
+ end
@@ -0,0 +1,6 @@
1
+ rule "FC071", "Missing LICENSE file" do
2
+ tags %w{style license}
3
+ cookbook do |path|
4
+ ensure_file_exists(path, "LICENSE")
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ rule "FC072", 'Metadata should not contain "attribute" keyword' do
2
+ tags %w{metadata style}
3
+ metadata do |ast, filename|
4
+ [file_match(filename)] if field(ast, "attribute").any?
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ rule "FC073", "Root alias file shadowing non-alias file" do
2
+ tags %w{correctness chef13}
3
+ cookbook do |path|
4
+ {
5
+ "attributes.rb" => "attributes/default.rb",
6
+ "recipe.rb" => "recipes/default.rb",
7
+ }.map do |alias_path, folder_path|
8
+ full_alias_path = File.join(path, alias_path)
9
+ full_folder_path = File.join(path, folder_path)
10
+ if File.exist?(full_alias_path) && File.exist?(full_folder_path)
11
+ file_match(full_folder_path)
12
+ else
13
+ nil
14
+ end
15
+ end.compact
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ rule "FC074", "LWRP should use DSL to define resource's default action" do
2
+ tags %w{correctness lwrp}
3
+ resource do |ast, filename|
4
+ # See if we're in a custom resource not an LWRP. Only LWRPs need the default_action
5
+ if ["//def/bodystmt/descendant::assign/
6
+ var_field/ivar/@value='@action'"].any? { |expr| ast.xpath(expr) }
7
+ [file_match(filename)]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ rule "FC075", "Cookbook uses node.save to save partial node data to the chef-server mid-run" do
2
+ tags %w{correctness}
3
+ def node_saves(ast)
4
+ ast.xpath('//call[(vcall|var_ref)/ident/@value="node"]
5
+ [ident/@value="save"]')
6
+ end
7
+ recipe { |ast| node_saves(ast) }
8
+ library { |ast| node_saves(ast) }
9
+ end
@@ -1,4 +1,4 @@
1
1
  module FoodCritic
2
2
  # The current version of foodcritic
3
- VERSION = "10.2.2"
3
+ VERSION = "10.3.0"
4
4
  end
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC001" do
4
+ context "with a cookbook with a single recipe that reads node attributes via symbols" do
5
+ recipe_file "log node[:foo]\n"
6
+ it { is_expected.to violate_rule("FC001") }
7
+ end
8
+
9
+ context "with a cookbook with a single recipe that accesses multiple node attributes via symbols" do
10
+ recipe_file "node[:foo] = 'bar'\nnode[:testing] = 'bar'\n"
11
+ it { is_expected.to violate_rule("FC001") }
12
+ end
13
+
14
+ context "with a cookbook with a single recipe that assigns node attributes accessed via symbols to a local variable" do
15
+ recipe_file "baz = node[:foo]\n"
16
+ it { is_expected.to violate_rule("FC001") }
17
+ end
18
+
19
+ context "with a cookbook with a single recipe that accesses nested node attributes via symbols" do
20
+ recipe_file "node[:foo][:foo2] = 'bar'\n"
21
+ it { is_expected.to violate_rule("FC001") }
22
+ end
23
+
24
+ context "with a cookbook with a single recipe that reads node attributes via strings" do
25
+ recipe_file "log node['foo']\n"
26
+ it { is_expected.to_not violate_rule("FC001") }
27
+ end
28
+
29
+ context "with a cookbook with a single recipe that searches based on a node attribute accessed via strings" do
30
+ recipe_file %Q{remote = search(:node, "name:\#{node['drbd']['remote_host']}")[0]\n}
31
+ it { is_expected.to_not violate_rule("FC001") }
32
+ end
33
+
34
+ context "with a cookbook with a single recipe that passes node attributes accessed via symbols to a template" do
35
+ recipe_file <<-EOH
36
+ template "/etc/foo" do
37
+ source "foo.erb"
38
+ variables({
39
+ :port => node[:foo][:port],
40
+ :user => node[:foo][:user]
41
+ })
42
+ end
43
+ EOH
44
+ it { is_expected.to violate_rule("FC001").in("recipes/default.rb:4") }
45
+ it { is_expected.to violate_rule("FC001").in("recipes/default.rb:5") }
46
+ end
47
+
48
+ context "with a cookbook that declares default attributes via symbols" do
49
+ attributes_file "default[:apache][:dir] = '/etc/apache2'\n"
50
+ it { is_expected.to violate_rule("FC001") }
51
+ end
52
+
53
+ context "with a cookbook that declares override attributes via symbols" do
54
+ attributes_file "override[:apache][:dir] = '/etc/apache2'\n"
55
+ it { is_expected.to violate_rule("FC001") }
56
+ end
57
+
58
+ context "with a cookbook that declares set attributes via symbols" do
59
+ attributes_file "set[:apache][:dir] = '/etc/apache2'\n"
60
+ it { is_expected.to violate_rule("FC001") }
61
+ end
62
+
63
+ context "with a cookbook that declares normal attributes via symbols" do
64
+ attributes_file "normal[:apache][:dir] = '/etc/apache2'\n"
65
+ it { is_expected.to violate_rule("FC001") }
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC008" do
4
+ context "with a cookbook with a metadata file containing boilerplate maintainer from knife CLI" do
5
+ metadata_file "maintainer 'YOUR_COMPANY_NAME'"
6
+ it { is_expected.to violate_rule("FC008") }
7
+ end
8
+
9
+ context "with a cookbook with a metadata file containing boilerplate maintainer from chef CLI" do
10
+ metadata_file "maintainer 'The Authors'"
11
+ it { is_expected.to violate_rule("FC008") }
12
+ end
13
+
14
+ context "with a cookbook with a metadata file containing boilerplate maintainer_email from knife CLI" do
15
+ metadata_file "maintainer_email 'YOUR_EMAIL'"
16
+ it { is_expected.to violate_rule("FC008") }
17
+ end
18
+
19
+ context "with a cookbook with a metadata file containing boilerplate maintainer_email from chef CLI" do
20
+ metadata_file "maintainer_email 'you@example.com'"
21
+ it { is_expected.to violate_rule("FC008") }
22
+ end
23
+
24
+ context "with a cookbook with a metadata file containing non-boilerplate maintainer and maintainer_email" do
25
+ metadata_file "maintainer 'John Smith'\nmaintainer_email 'john@smith.com'"
26
+ it { is_expected.not_to violate_rule("FC008") }
27
+ end
28
+
29
+ context "with a cookbook with a metadata file not containing maintainer or maintainer_email" do
30
+ metadata_file
31
+ it { is_expected.not_to violate_rule("FC008") }
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC011" do
4
+ context "with a cookbook with a README.md file" do
5
+ metadata_file "name 'mycookbook'"
6
+ file("README.md")
7
+ it { is_expected.not_to violate_rule("FC011") }
8
+ end
9
+
10
+ context "with a cookbook without a README.md file" do
11
+ metadata_file "name 'mycookbook'"
12
+ it { is_expected.to violate_rule("FC011") }
13
+ end
14
+
15
+ context "with a cookbook with a README.rdoc file" do
16
+ metadata_file "name 'mycookbook'"
17
+ file("README.rdoc")
18
+ it { is_expected.to violate_rule("FC011") }
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC012" do
4
+ context "with a cookbook with a README.md file" do
5
+ metadata_file "name 'mycookbook'"
6
+ file("README.md")
7
+ it { is_expected.not_to violate_rule("FC012") }
8
+ end
9
+
10
+ context "with a cookbook without a README file" do
11
+ metadata_file "name 'mycookbook'"
12
+ it { is_expected.not_to violate_rule("FC012") }
13
+ end
14
+
15
+ context "with a cookbook with a README.rdoc file" do
16
+ metadata_file "name 'mycookbook'"
17
+ file("README.rdoc")
18
+ it { is_expected.to violate_rule("FC012") }
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC016" do
4
+
5
+ context "with a cookbook with a LWRP that includes a default_action" do
6
+ resource_file <<-EOH
7
+ actions :create, :remove
8
+ default_action :create
9
+
10
+ attribute :name, String, name_attribute: true
11
+ EOH
12
+ it { is_expected.to_not violate_rule("FC016") }
13
+ end
14
+
15
+ context "with a cookbook with a LWRP that includes a non-DSL default_action" do
16
+ resource_file <<-EOH
17
+ actions :create, :remove,
18
+
19
+ def initialize(*args)
20
+ super
21
+ @action = :create
22
+ end
23
+
24
+ attribute :name, String, name_attribute: true
25
+ EOH
26
+ it { is_expected.to_not violate_rule("FC016") }
27
+ end
28
+
29
+ context "with a cookbook with a LWRP that does not include a default_action" do
30
+ resource_file <<-EOH
31
+ actions :create, :remove,
32
+
33
+ attribute :name, String, name_attribute: true
34
+ EOH
35
+ it { is_expected.to violate_rule("FC016") }
36
+ end
37
+
38
+ context "with a custom resource" do
39
+ resource_file <<-EOH
40
+ property :name, String, name_property: true
41
+
42
+ action :create do
43
+ cookbook_file "/etc/something"
44
+ end
45
+ EOH
46
+ it { is_expected.to_not violate_rule("FC016") }
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC028" do
4
+ context "with a cookbook with a single recipe that calls platform? without parentheses for a single platform" do
5
+ recipe_file "platform? 'ubuntu'"
6
+ it { is_expected.not_to violate_rule("FC028") }
7
+ end
8
+
9
+ context "with a cookbook with a single recipe that calls platform? without parentheses for two platforms" do
10
+ recipe_file "platform?('ubuntu','windows')"
11
+ it { is_expected.not_to violate_rule("FC028") }
12
+ end
13
+
14
+ context "with a cookbook with a single recipe that calls platform? with parentheses for a single platform" do
15
+ recipe_file "platform?('ubuntu')"
16
+ it { is_expected.not_to violate_rule("FC028") }
17
+ end
18
+
19
+ context "with a cookbook with a single recipe that calls platform? with parentheses for two platforms" do
20
+ recipe_file "platform?('ubuntu', 'windows')"
21
+ it { is_expected.not_to violate_rule("FC028") }
22
+ end
23
+
24
+ context "with a cookbook with a single recipe that compares a value against node.platform" do
25
+ recipe_file "node.platform == 'ubuntu'"
26
+ it { is_expected.not_to violate_rule("FC028") }
27
+ end
28
+
29
+ context "with a cookbook with a single recipe that uses checks a value against node.platform" do
30
+ recipe_file "node.platform == 'ubuntu'"
31
+ it { is_expected.not_to violate_rule("FC028") }
32
+ end
33
+
34
+ context "with a cookbook with a single recipe that calls node.platform? without a parentheses" do
35
+ recipe_file "node.platform? 'ubuntu'"
36
+ it { is_expected.to violate_rule("FC028") }
37
+ end
38
+
39
+ context "with a cookbook with a single recipe that calls node.platform? with a parentheses" do
40
+ recipe_file "node.platform?('ubuntu')"
41
+ it { is_expected.to violate_rule("FC028") }
42
+ end
43
+
44
+ context "with a cookbook with a single recipe that calls node.platform? with a parentheses for 2 platforms" do
45
+ recipe_file "node.platform?('ubuntu', 'windows')"
46
+ it { is_expected.to violate_rule("FC028") }
47
+ end
48
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC029" do
4
+ context "with a cookbook with a metadata file that doesn't contain the recipe keyword" do
5
+ metadata_file("name 'example'")
6
+ it { is_expected.not_to violate_rule("FC029") }
7
+ end
8
+
9
+ context "with a cookbook with a metadata file that contains contain the recipe keyword with the cookbook name only" do
10
+ metadata_file("name 'example'\nrecipe 'example', 'Installs Example'")
11
+ it { is_expected.not_to violate_rule("FC029") }
12
+ end
13
+
14
+ context "with a cookbook with a metadata file that contains the recipe keyword with the cookbook::recipe format name" do
15
+ metadata_file("name 'example'\nrecipe 'example::default', 'Installs Example'")
16
+ it { is_expected.not_to violate_rule("FC029") }
17
+ end
18
+
19
+ context "with a cookbook with a metadata file that contains the recipe keyword and lacks the cookbook name" do
20
+ metadata_file("name 'example'\nrecipe 'default', 'Installs Example'")
21
+ it { is_expected.to violate_rule("FC029") }
22
+ end
23
+
24
+ context "with a cookbook with a metadata file that contains the recipe keyword and stores full recipe name as a var" do
25
+ metadata_file("name 'example'\nvar = 'example::default'\nrecipe my_var, 'Installs Example'")
26
+ it { is_expected.not_to violate_rule("FC029") }
27
+ end
28
+
29
+ context "with a cookbook with a metadata file that contains the recipe keyword and stores part of the recipe name as a var" do
30
+ metadata_file('name "example"\nvar = "example"\nrecipe "#{my_var}::default", "Installs Example"')
31
+ it { is_expected.not_to violate_rule("FC029") }
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC031" do
4
+ context "with a cookbook with a metadata file" do
5
+ metadata_file
6
+ recipe_file
7
+ it { is_expected.to_not violate_rule("FC031") }
8
+ end
9
+
10
+ context "with a cookbook without a metadata file" do
11
+ recipe_file
12
+ it { is_expected.to violate_rule("FC031") }
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC042" do
4
+ context "with a cookbook with a single recipe that uses require_recipe" do
5
+ recipe_file "require_recipe 'my_recipe::default'"
6
+ it { is_expected.to violate_rule("FC042") }
7
+ end
8
+
9
+ context "with a cookbook with a single recipe that uses include_recipe" do
10
+ recipe_file "include_recipe 'my_recipe::default'"
11
+ it { is_expected.not_to violate_rule("FC042") }
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC045" do
4
+ context "with a cookbook with a metadata file that includes the name keyword" do
5
+ metadata_file "name 'food'"
6
+ it { is_expected.to_not violate_rule("FC045") }
7
+ end
8
+
9
+ context "with a cookbook with a metadata file that doesn't include the name keyword" do
10
+ metadata_file
11
+ it { is_expected.to violate_rule("FC045") }
12
+ end
13
+
14
+ context "with a cookbook without a metadata file" do
15
+ recipe_file
16
+ it { is_expected.to_not violate_rule("FC045") }
17
+ end
18
+ end