foodcritic 10.4.1 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -1
  3. data/Rakefile +7 -1
  4. data/features/step_definitions/cookbook_steps.rb +0 -96
  5. data/lib/foodcritic/api.rb +77 -79
  6. data/lib/foodcritic/rules/fc008.rb +2 -2
  7. data/lib/foodcritic/rules/fc029.rb +1 -1
  8. data/lib/foodcritic/rules/fc042.rb +1 -1
  9. data/lib/foodcritic/rules/fc052.rb +1 -1
  10. data/lib/foodcritic/rules/fc053.rb +1 -1
  11. data/lib/foodcritic/rules/fc057.rb +1 -1
  12. data/lib/foodcritic/rules/fc058.rb +1 -1
  13. data/lib/foodcritic/rules/fc060.rb +1 -1
  14. data/lib/foodcritic/rules/fc061.rb +3 -3
  15. data/lib/foodcritic/rules/fc063.rb +1 -2
  16. data/lib/foodcritic/rules/fc069.rb +2 -4
  17. data/lib/foodcritic/rules/fc078.rb +2 -3
  18. data/lib/foodcritic/rules/fc079.rb +6 -0
  19. data/lib/foodcritic/rules/fc080.rb +6 -0
  20. data/lib/foodcritic/rules/fc081.rb +6 -0
  21. data/lib/foodcritic/rules/fc082.rb +9 -0
  22. data/lib/foodcritic/rules/fc083.rb +6 -0
  23. data/lib/foodcritic/rules/fc084.rb +9 -0
  24. data/lib/foodcritic/rules/fc085.rb +12 -0
  25. data/lib/foodcritic/version.rb +1 -1
  26. data/spec/functional/fc007_spec.rb +127 -0
  27. data/spec/functional/fc049_spec.rb +56 -0
  28. data/spec/functional/fc050_spec.rb +85 -0
  29. data/spec/functional/fc066_spec.rb +20 -0
  30. data/spec/functional/fc069_spec.rb +15 -0
  31. data/spec/functional/fc070_spec.rb +9 -0
  32. data/spec/functional/fc076_spec.rb +2 -2
  33. data/spec/functional/fc077_spec.rb +2 -2
  34. data/spec/functional/fc078_spec.rb +14 -4
  35. data/spec/functional/fc079_spec.rb +21 -0
  36. data/spec/functional/fc080_spec.rb +68 -0
  37. data/spec/functional/fc081_spec.rb +25 -0
  38. data/spec/functional/fc082_spec.rb +23 -0
  39. data/spec/functional/fc083_spec.rb +34 -0
  40. data/spec/functional/fc084_spec.rb +49 -0
  41. data/spec/functional/fc085_spec.rb +58 -0
  42. data/spec/regression/expected/aix.txt +1 -0
  43. data/spec/regression/expected/aws.txt +3 -0
  44. data/spec/regression/expected/chef-client.txt +2 -0
  45. data/spec/regression/expected/chef.txt +67 -0
  46. data/spec/regression/expected/database.txt +1 -0
  47. data/spec/regression/expected/drbd.txt +1 -0
  48. data/spec/regression/expected/jetty.txt +1 -0
  49. data/spec/regression/expected/mysql.txt +4 -0
  50. data/spec/regression/expected/openssh.txt +1 -0
  51. data/spec/regression/expected/postfix.txt +1 -0
  52. data/spec/regression/expected/rsyslog.txt +1 -0
  53. data/spec/regression/expected/smokeping.txt +1 -0
  54. data/spec/regression/expected/sql_server.txt +1 -0
  55. data/spec/regression/expected/ufw.txt +1 -0
  56. data/spec/regression/expected/users.txt +2 -0
  57. data/spec/regression/expected/xml.txt +1 -0
  58. data/spec/regression/expected/yum.txt +0 -1
  59. data/spec/regression/regression_spec.rb +2 -2
  60. data/spec/unit/api_spec.rb +130 -149
  61. metadata +20 -32
  62. data/features/007_check_for_undeclared_recipe_dependencies.feature +0 -59
  63. data/features/049_check_for_role_name_mismatch_with_file_name.feature +0 -31
  64. data/features/050_check_for_invalid_name.feature +0 -33
  65. data/man/foodcritic.1 +0 -81
  66. data/spec/foodcritic/coverage/assets/0.10.0/application.css +0 -799
  67. data/spec/foodcritic/coverage/assets/0.10.0/application.js +0 -1707
  68. data/spec/foodcritic/coverage/assets/0.10.0/colorbox/border.png +0 -0
  69. data/spec/foodcritic/coverage/assets/0.10.0/colorbox/controls.png +0 -0
  70. data/spec/foodcritic/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
  71. data/spec/foodcritic/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
  72. data/spec/foodcritic/coverage/assets/0.10.0/favicon_green.png +0 -0
  73. data/spec/foodcritic/coverage/assets/0.10.0/favicon_red.png +0 -0
  74. data/spec/foodcritic/coverage/assets/0.10.0/favicon_yellow.png +0 -0
  75. data/spec/foodcritic/coverage/assets/0.10.0/loading.gif +0 -0
  76. data/spec/foodcritic/coverage/assets/0.10.0/magnify.png +0 -0
  77. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  78. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  79. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  80. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  81. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  82. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  83. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  84. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  85. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  86. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  87. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  88. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  89. data/spec/foodcritic/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  90. data/spec/foodcritic/coverage/index.html +0 -72
@@ -7,8 +7,8 @@ rule "FC008", "Generated cookbook metadata needs updating" do
7
7
  { "maintainer_email" => "YOUR_EMAIL" },
8
8
  { "maintainer_email" => "you@example.com" },
9
9
  ].map do |metadata_hash|
10
- ast.xpath(%Q{//command[ident/@value='#{metadata_hash.keys[0]}']/
11
- descendant::tstring_content[@value='#{metadata_hash.values[0]}']})
10
+ field, value = metadata_hash.to_a.first
11
+ field(ast, field).xpath("descendant::tstring_content[@value='#{value}']")
12
12
  end
13
13
  end
14
14
  end
@@ -1,7 +1,7 @@
1
1
  rule "FC029", "No leading cookbook name in recipe metadata" do
2
2
  tags %w{correctness metadata}
3
3
  metadata do |ast, filename|
4
- ast.xpath('//command[ident/@value="recipe"]').map do |declared_recipe|
4
+ field(ast, "recipe").map do |declared_recipe|
5
5
  next unless declared_recipe.xpath("count(//vcall|//var_ref)").to_i == 0
6
6
  recipe_name = declared_recipe.xpath('args_add_block/
7
7
  descendant::tstring_content[1]/@value').to_s
@@ -1,6 +1,6 @@
1
1
  rule "FC042", "Prefer include_recipe to require_recipe" do
2
2
  tags %w{correctness deprecated}
3
3
  recipe do |ast|
4
- ast.xpath('//command[ident/@value="require_recipe"]')
4
+ field(ast, "require_recipe")
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  rule "FC052", 'Metadata uses the deprecated "suggests" keyword' do
2
2
  tags %w{style metadata deprecated}
3
3
  metadata do |ast, filename|
4
- ast.xpath(%q{//command[ident/@value='suggests']})
4
+ field(ast, "suggests")
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  rule "FC053", 'Metadata uses the deprecated "recommends" keyword' do
2
2
  tags %w{style metadata deprecated}
3
3
  metadata do |ast, filename|
4
- ast.xpath(%q{//command[ident/@value='recommends']})
4
+ field(ast, "recommends")
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
1
  rule "FC057", "Library provider does not declare use_inline_resources" do
2
2
  tags %w{correctness lwrp}
3
- library do |ast, filename|
3
+ library do |ast|
4
4
  ast.xpath('//const_path_ref/const[@value="LWRPBase"]/..//const[@value="Provider"]/../../..').select do |x|
5
5
  x.xpath('//*[self::vcall or self::var_ref]/ident[@value="use_inline_resources"]').empty?
6
6
  end
@@ -1,6 +1,6 @@
1
1
  rule "FC058", "Library provider declares use_inline_resources and declares #action_<name> methods" do
2
2
  tags %w{correctness lwrp}
3
- library do |ast, filename|
3
+ library do |ast|
4
4
  ast.xpath('//const_path_ref/const[@value="LWRPBase"]/..//const[@value="Provider"]/../../..').select do |x|
5
5
  x.xpath('//*[self::vcall or self::var_ref]/ident[@value="use_inline_resources"]').length > 0 &&
6
6
  x.xpath(%q{//def[ident[contains(@value, 'action_')]]}).length > 0
@@ -1,6 +1,6 @@
1
1
  rule "FC060", "LWRP provider declares use_inline_resources and declares #action_<name> methods" do
2
2
  tags %w{correctness lwrp}
3
- provider do |ast, filename|
3
+ provider do |ast|
4
4
  use_inline_resources = !ast.xpath('//*[self::vcall or self::var_ref]/ident
5
5
  [@value="use_inline_resources"]').empty?
6
6
  if use_inline_resources
@@ -2,9 +2,9 @@ rule "FC061", "Valid cookbook versions are of the form x.y or x.y.z" do
2
2
  tags %w{metadata correctness supermarket}
3
3
  metadata do |ast, filename|
4
4
  # matches a version method with a string literal with no interpolation
5
- ver = ast.xpath('//command[ident/@value="version"]/args_add_block/args_add/string_literal[not(.//string_embexpr)]//tstring_content/@value')
6
- if !ver.empty? && ver.to_s !~ /\A\d+\.\d+(\.\d+)?\z/
7
- [file_match(filename)]
5
+ ver = field_value(ast, "version")
6
+ if ver && !ver.empty? && ver.to_s !~ /\A\d+\.\d+(\.\d+)?\z/
7
+ field(ast, "version")
8
8
  end
9
9
  end
10
10
  end
@@ -2,7 +2,6 @@ rule "FC063", "Cookbook incorrectly depends on itself" do
2
2
  tags %w{metadata correctness}
3
3
  metadata do |ast, filename|
4
4
  name = cookbook_name(filename)
5
- ast.xpath(%Q{//command[ident/@value='depends']/
6
- descendant::tstring_content[@value='#{name}']})
5
+ field(ast, "depends").xpath("descendant::tstring_content[@value='#{name}']")
7
6
  end
8
7
  end
@@ -2,8 +2,7 @@ rule "FC069", "Ensure standardized license defined in metadata" do
2
2
  tags %w{metadata supermarket license}
3
3
  metadata do |ast, filename|
4
4
  begin
5
- license = ast.xpath(%Q{//command[ident/@value='license']/
6
- descendant::tstring_content}).attribute("value").to_s
5
+ license = field_value(ast, "license")
7
6
 
8
7
  # list of valid SPDX.org license strings. To build an array run this:
9
8
  # require 'json'
@@ -356,8 +355,7 @@ rule "FC069", "Ensure standardized license defined in metadata" do
356
355
  StandardML-NJ
357
356
  WXwindows
358
357
  }
359
- valid << "All Rights Reserved" # Chef-DK's non-standard extra value
360
- [file_match(filename)] unless valid.include?(license)
358
+ [file_match(filename)] unless valid.include?(license) || license =~ /all rights reserved/i
361
359
  rescue NoMethodError # no license in the metadata
362
360
  [file_match(filename)]
363
361
  end
@@ -1,9 +1,8 @@
1
1
  rule "FC078", "Ensure cookbook shared under an OSI-approved open source license" do
2
- tags %w{opensource}
2
+ tags %w{opensource license supermarket}
3
3
  metadata do |ast, filename|
4
4
  begin
5
- license = ast.xpath(%Q{//command[ident/@value='license']/
6
- descendant::tstring_content}).attribute("value").to_s
5
+ license = field_value(ast, "license")
7
6
 
8
7
  # list of valid SPDX.org license strings. To build an array run this:
9
8
  # require 'json'
@@ -0,0 +1,6 @@
1
+ rule "FC079", "Deprecated easy_install_package resource usage" do
2
+ tags %w{deprecated chef13}
3
+ recipe do |ast|
4
+ find_resources(ast, type: "easy_install_package")
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ rule "FC080", "User resource uses supports property" do
2
+ tags %w{deprecated chef13}
3
+ recipe do |ast|
4
+ find_resources(ast, type: "user").xpath(%q{descendant::fcall[ident/@value='supports']|descendant::command[ident/@value='supports']})
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ rule "FC081", "Cookbook depends on the partial_search cookbook" do
2
+ tags %w{chef12}
3
+ metadata do |ast, filename|
4
+ [file_match(filename)] if declared_dependencies(ast).include?("partial_search")
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ rule "FC082", "node.set or node.set_unless used to set node attributes" do
2
+ tags %w{chef14 deprecated}
3
+ def node_sets(ast)
4
+ ast.xpath('//call[(vcall|var_ref)/ident/@value="node"]
5
+ [ident[@value="set" or @value="set_unless"]]')
6
+ end
7
+ recipe { |ast| node_sets(ast) }
8
+ library { |ast| node_sets(ast) }
9
+ end
@@ -0,0 +1,6 @@
1
+ rule "FC083", "Execute resource using 'path' property" do
2
+ tags %w{deprecated chef12}
3
+ recipe do |ast|
4
+ find_resources(ast, type: "execute").xpath('(.//command|.//fcall)[ident/@value="path"]')
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ rule "FC084", "Deprecated Chef::REST class used" do
2
+ tags %w{chef13 deprecated}
3
+ def rest(ast)
4
+ ast.xpath('//const_path_ref/const[@value="REST"]/..//const[@value="Chef"]/../../..')
5
+ end
6
+ recipe { |ast| rest(ast) }
7
+ library { |ast| rest(ast) }
8
+
9
+ end
@@ -0,0 +1,12 @@
1
+ rule "FC085", "Resource using new_resource.updated_by_last_action to converge resource" do
2
+ tags %w{chef13 deprecated}
3
+ def updated_by(ast)
4
+ ast.xpath('//call[(vcall|var_ref)/ident/@value="new_resource"]
5
+ [ident/@value="updated_by_last_action"]')
6
+ end
7
+
8
+ resource { |ast| updated_by(ast) }
9
+ provider { |ast| updated_by(ast) }
10
+ library { |ast| updated_by(ast) }
11
+
12
+ end
@@ -1,4 +1,4 @@
1
1
  module FoodCritic
2
2
  # The current version of foodcritic
3
- VERSION = "10.4.1"
3
+ VERSION = "11.0.0"
4
4
  end
@@ -0,0 +1,127 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC007" do
4
+ metadata_file "name 'test'\ndepends 'dep'"
5
+ context "with an undeclared dependency" do
6
+ recipe_file 'include_recipe "foo"'
7
+
8
+ it { is_expected.to violate_rule }
9
+
10
+ context "with parens" do
11
+ recipe_file 'include_recipe("foo")'
12
+ it { is_expected.to violate_rule }
13
+ end
14
+
15
+ context "with ::default" do
16
+ recipe_file 'include_recipe "foo::default"'
17
+ it { is_expected.to violate_rule }
18
+ end
19
+
20
+ context "with parens and ::default" do
21
+ recipe_file 'include_recipe("foo::default")'
22
+ it { is_expected.to violate_rule }
23
+ end
24
+
25
+ # context 'with a partial expression' do
26
+ # recipe_file 'include_recipe "foo::#{something}"'
27
+ # it { pending; is_expected.to violate_rule }
28
+ # end
29
+ end
30
+
31
+ context "with a declared dependency" do
32
+ recipe_file 'include_recipe "dep"'
33
+
34
+ it { is_expected.to_not violate_rule }
35
+
36
+ context "with parens" do
37
+ recipe_file 'include_recipe("dep")'
38
+ it { is_expected.to_not violate_rule }
39
+ end
40
+
41
+ context "with ::default" do
42
+ recipe_file 'include_recipe "dep::default"'
43
+ it { is_expected.to_not violate_rule }
44
+ end
45
+
46
+ context "with parens and ::default" do
47
+ recipe_file 'include_recipe("dep::default")'
48
+ it { is_expected.to_not violate_rule }
49
+ end
50
+
51
+ # context 'with a partial expression' do
52
+ # recipe_file 'include_recipe "dep::#{something}"'
53
+ # it { pending; is_expected.to_not violate_rule }
54
+ # end
55
+ end
56
+ context "with an unknowable include_recipe" do
57
+ context "with a node attribute" do
58
+ recipe_file 'include_recipe node["foo"]'
59
+ it { is_expected.to_not violate_rule }
60
+ end
61
+
62
+ context "with a variable" do
63
+ recipe_file "include_recipe something"
64
+ it { is_expected.to_not violate_rule }
65
+ end
66
+
67
+ context "with a string expression" do
68
+ recipe_file 'include_recipe "#{something}"'
69
+ it { is_expected.to_not violate_rule }
70
+ end
71
+
72
+ context "with a parial string expression" do
73
+ recipe_file 'include_recipe "#{something}::default"'
74
+ it { is_expected.to_not violate_rule }
75
+ end
76
+ end
77
+
78
+ context "with an include from the same cookbook" do
79
+ recipe_file 'incldue_recipe "test::other"'
80
+ it { is_expected.to_not violate_rule }
81
+
82
+ context "with the shorthand syntax" do
83
+ recipe_file 'include_recipe "::other"'
84
+ it { is_expected.to_not violate_rule }
85
+ end
86
+ end
87
+
88
+ context "with multiple includes" do
89
+ recipe_file "include_recipe 'test::other'\ninclude_recipe 'foo'"
90
+ it { is_expected.to violate_rule.in("recipes/default.rb:2") }
91
+ end
92
+
93
+ context "with multiple dependencies" do
94
+ shared_examples "multiple includes" do
95
+ context "with declared includes" do
96
+ recipe_file %Q{include_recipe 'one'\ninclude_recipe "two"\ninclude_recipe 'three::default'}
97
+ it { is_expected.to_not violate_rule }
98
+ end
99
+
100
+ context "with undeclared includes" do
101
+ recipe_file %Q{include_recipe 'one'\ninclude_recipe "other"\ninclude_recipe 'foo::default'}
102
+ it { is_expected.to violate_rule.in("recipes/default.rb:2") }
103
+ it { is_expected.to violate_rule.in("recipes/default.rb:2") }
104
+ end
105
+ end
106
+
107
+ context "using multiple depends" do
108
+ metadata_file "name 'test'\ndepends 'one'\ndepends 'two'\ndepends 'three'"
109
+ it_behaves_like "multiple includes"
110
+ end
111
+
112
+ context "using a word array and a one-line block" do
113
+ metadata_file "name 'test'\n%w{one two three}.each {|d| depends d }"
114
+ it_behaves_like "multiple includes"
115
+ end
116
+
117
+ context "using a word array and a multi-line block" do
118
+ metadata_file "name 'test'\n%w{one two three}.each do |d|\n depends d\nend"
119
+ it_behaves_like "multiple includes"
120
+ end
121
+
122
+ context "using a non-standard word array" do
123
+ metadata_file "name 'test'\n%w|one two three|.each {|d| depends d }"
124
+ it_behaves_like "multiple includes"
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC049" do
4
+ foodcritic_command("--no-progress", "-R", "roles")
5
+
6
+ context "with webserver.rb" do
7
+ context "with name webserver" do
8
+ file "roles/webserver.rb", 'name "webserver"'
9
+ it { is_expected.to_not violate_rule }
10
+ end
11
+
12
+ context "with name apache" do
13
+ file "roles/webserver.rb", 'name "apache"'
14
+ it { is_expected.to violate_rule }
15
+ end
16
+
17
+ context "with a string expression in the name" do
18
+ file "roles/webserver.rb", 'name "ap#{ache}"'
19
+ it { is_expected.to_not violate_rule }
20
+ end
21
+
22
+ context "with multiple names" do
23
+ file "roles/webserver.rb", "name 'apache'\nname 'webserver'"
24
+ it { is_expected.to_not violate_rule }
25
+ end
26
+
27
+ context "with multiple mismatched names" do
28
+ file "roles/webserver.rb", "name 'webserver'\nname 'apache'"
29
+ it { is_expected.to violate_rule }
30
+ end
31
+ end
32
+
33
+ context "with webserver.json" do
34
+ context "with name webserver" do
35
+ file "roles/webserver.json", '{"name": "webserver"}'
36
+ it { is_expected.to_not violate_rule }
37
+ end
38
+
39
+ context "with name apache" do
40
+ file "roles/webserver.json", '{"name": "apache"}'
41
+ it { is_expected.to_not violate_rule }
42
+ end
43
+ end
44
+
45
+ context "in -B mode" do
46
+ foodcritic_command("--no-progress", "-B", "roles")
47
+ file "roles/webserver.rb", 'name "apache"'
48
+ it { is_expected.to_not violate_rule }
49
+ end
50
+
51
+ context "in normal mode" do
52
+ foodcritic_command("--no-progress", "roles")
53
+ file "roles/webserver.rb", 'name "apache"'
54
+ it { is_expected.to_not violate_rule }
55
+ end
56
+ end
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+
3
+ describe "FC050" do
4
+ context "with a role" do
5
+ foodcritic_command("--no-progress", "-R", "roles")
6
+ let(:role_name) { "" }
7
+ file("roles/webserver.rb") { "name '#{role_name}'\nrun_list ['recipe[apache]']" }
8
+
9
+ context "with name webserver" do
10
+ let(:role_name) { "webserver" }
11
+ it { is_expected.to_not violate_rule }
12
+ end
13
+
14
+ context "with name web_server" do
15
+ let(:role_name) { "web_server" }
16
+ it { is_expected.to_not violate_rule }
17
+ end
18
+
19
+ context "with name web-server" do
20
+ let(:role_name) { "web-server" }
21
+ it { is_expected.to_not violate_rule }
22
+ end
23
+
24
+ context "with name webserver123" do
25
+ let(:role_name) { "webserver123" }
26
+ it { is_expected.to_not violate_rule }
27
+ end
28
+
29
+ context "with name Webserver" do
30
+ let(:role_name) { "Webserver" }
31
+ it { is_expected.to_not violate_rule }
32
+ end
33
+
34
+ context "with name web server" do
35
+ let(:role_name) { "web server" }
36
+ it { is_expected.to violate_rule }
37
+ end
38
+
39
+ context "with name webserver%" do
40
+ let(:role_name) { "webserver%" }
41
+ it { is_expected.to violate_rule }
42
+ end
43
+ end
44
+
45
+ context "with an environment" do
46
+ foodcritic_command("--no-progress", "-E", "environments")
47
+ let(:environment_name) { "" }
48
+ file("environments/production.rb") { "name '#{environment_name}'\ncookbook 'apache2'" }
49
+
50
+ context "with name production" do
51
+ let(:environment_name) { "production" }
52
+ it { is_expected.to_not violate_rule }
53
+ end
54
+
55
+ context "with name pre_production" do
56
+ let(:environment_name) { "pre_production" }
57
+ it { is_expected.to_not violate_rule }
58
+ end
59
+
60
+ context "with name production-eu" do
61
+ let(:environment_name) { "production-eu" }
62
+ it { is_expected.to_not violate_rule }
63
+ end
64
+
65
+ context "with name production2" do
66
+ let(:environment_name) { "production2" }
67
+ it { is_expected.to_not violate_rule }
68
+ end
69
+
70
+ context "with name Production" do
71
+ let(:environment_name) { "Production" }
72
+ it { is_expected.to_not violate_rule }
73
+ end
74
+
75
+ context "with name EU West" do
76
+ let(:environment_name) { "EU West" }
77
+ it { is_expected.to violate_rule }
78
+ end
79
+
80
+ context "with name production (eu-west)" do
81
+ let(:environment_name) { "production (eu-west)" }
82
+ it { is_expected.to violate_rule }
83
+ end
84
+ end
85
+ end