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,66 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe FoodCritic::Chef do
4
-
5
- let(:api) { Object.new.extend(FoodCritic::Api) }
6
-
7
- describe "#chef_dsl_methods" do
8
- it "returns an enumerable" do
9
- api.chef_dsl_methods.each { |m| m }
10
- end
11
- it "does not return an empty" do
12
- expect(api.chef_dsl_methods).to_not be_empty
13
- end
14
- it "returns dsl methods as symbols" do
15
- expect(api.chef_dsl_methods.all? { |m| m == m.to_sym }).to be_truthy
16
- end
17
- end
18
-
19
- describe "#resource_attribute?" do
20
- it "raises if the resource_type is nil" do
21
- expect { api.resource_attribute?(nil, :name) }.to raise_error ArgumentError
22
- end
23
- it "raises if the resource_type is empty" do
24
- expect { api.resource_attribute?("", :name) }.to raise_error ArgumentError
25
- end
26
- it "raises if the attribute_name is nil" do
27
- expect { api.resource_attribute?(:file, nil) }.to raise_error ArgumentError
28
- end
29
- it "raises if the attribute_name is empty" do
30
- expect { api.resource_attribute?(:file, "") }.to raise_error ArgumentError
31
- end
32
- it "returns true if the resource attribute is known" do
33
- expect(api.resource_attribute?(:file, :name)).to be_truthy
34
- end
35
- it "returns false if the resource attribute is not known" do
36
- expect(api.resource_attribute?(:file, :size)).to be_falsey
37
- end
38
- it "returns true for unrecognised resources" do
39
- expect(api.resource_attribute?(:cluster_file, :size)).to be_truthy
40
- end
41
- it "allows the resource type to be passed as a string" do
42
- expect(api.resource_attribute?("file", :size)).to be_falsey
43
- end
44
- it "allows the attribute_name to be passed as a string" do
45
- expect(api.resource_attribute?(:file, "mode")).to be_truthy
46
- end
47
- end
48
-
49
- describe "#valid_query?" do
50
- it "raises if the query is nil" do
51
- expect { api.valid_query?(nil) }.to raise_error ArgumentError
52
- end
53
- it "raises if the query is empty" do
54
- expect { api.valid_query?("") }.to raise_error ArgumentError
55
- end
56
- it "coerces the provided object to a string" do
57
- query = Class.new do
58
- def to_s
59
- "*:*"
60
- end
61
- end.new
62
- expect(api.valid_query?(query)).to be_truthy
63
- end
64
- end
65
-
66
- end
@@ -1,136 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe FoodCritic::CommandLine do
4
- it "is instantiable" do
5
- expect(FoodCritic::CommandLine.new([])).to_not be_nil
6
- end
7
-
8
- describe "#cookbook_paths" do
9
- it "returns an empty array if no paths are specified" do
10
- expect(FoodCritic::CommandLine.new([]).cookbook_paths).to be_empty
11
- end
12
-
13
- it "returns a single item array for a specified directory" do
14
- expect(FoodCritic::CommandLine.new(["example"]).cookbook_paths).to eq ["example"]
15
- end
16
-
17
- it "returns multiple items for multiple specified directories" do
18
- expect(FoodCritic::CommandLine.new(%w{example another_example}).cookbook_paths).to eq %w{example another_example}
19
- end
20
-
21
- it "ignores known arguments" do
22
- expect(FoodCritic::CommandLine.new(["example", "--context"]).cookbook_paths).to eq ["example"]
23
- end
24
- end
25
-
26
- describe "#role_paths" do
27
- it "returns an empty if no role paths are specified" do
28
- expect(FoodCritic::CommandLine.new([]).role_paths).to be_empty
29
- end
30
- it "returns the provided role path" do
31
- expect(FoodCritic::CommandLine.new(["-R", "roles"]).role_paths).to eq %w{roles}
32
- end
33
- it "returns the provided role paths when there are multiple" do
34
- expect(FoodCritic::CommandLine.new(["-R", "roles1",
35
- "-R", "roles2"]).role_paths).to eq %w{roles1 roles2}
36
- end
37
- end
38
-
39
- describe "#valid_paths?" do
40
- it "returns false if no paths are specified" do
41
- expect(FoodCritic::CommandLine.new([]).valid_paths?).to be_falsey
42
- end
43
-
44
- it "returns true if the specified directory exists" do
45
- expect(FoodCritic::CommandLine.new(["lib"]).valid_paths?).to be_truthy
46
- end
47
-
48
- it "returns false if the specified directory does not exist" do
49
- expect(FoodCritic::CommandLine.new(["lib2"]).valid_paths?).to be_falsey
50
- end
51
-
52
- it "returns true if the specified file exists" do
53
- expect(FoodCritic::CommandLine.new(["lib/foodcritic.rb"]).valid_paths?).to be_truthy
54
- end
55
-
56
- it "returns true if both specified paths exist" do
57
- expect(FoodCritic::CommandLine.new(["lib", "lib/foodcritic.rb"]).valid_paths?).to be_truthy
58
- end
59
-
60
- it "returns false if any on the specified paths do not exist" do
61
- expect(FoodCritic::CommandLine.new(%w{lib lib2}).valid_paths?).to be_falsey
62
- end
63
- end
64
-
65
- describe "#list_rules?" do
66
- it "returns false if ---list is not specified" do
67
- expect(FoodCritic::CommandLine.new([]).list_rules?).to be_falsey
68
- end
69
-
70
- it "returns true if --list is specified" do
71
- expect(FoodCritic::CommandLine.new(["--list"]).list_rules?).to be_truthy
72
- end
73
- end
74
-
75
- describe ":progress" do
76
- it "is true by default" do
77
- expect(FoodCritic::CommandLine.new(["."]).options[:progress]).to be_truthy
78
- end
79
-
80
- it "is true if -P is specified" do
81
- expect(FoodCritic::CommandLine.new(["-P", "."]).options[:progress]).to be_truthy
82
- end
83
-
84
- it "is true if --progres is specified" do
85
- expect(FoodCritic::CommandLine.new(["--progress", "."]).options[:progress]).to be_truthy
86
- end
87
-
88
- it "is false if --no-progress is specified" do
89
- expect(FoodCritic::CommandLine.new(["--no-progress", "."]).options[:progress]).to be_falsey
90
- end
91
- end
92
-
93
- describe ":search_gems" do
94
- it "is unset if -G/--search-gems is not specified" do
95
- expect(FoodCritic::CommandLine.new(["."]).options[:search_gems].nil?).to be_truthy
96
- end
97
-
98
- it "is true if -G is specified" do
99
- expect(FoodCritic::CommandLine.new(["-G", "."]).options[:search_gems]).to be_truthy
100
- end
101
-
102
- it "is true if --search-gems is specified" do
103
- expect(FoodCritic::CommandLine.new(["--search-gems", "."]).options[:search_gems]).to be_truthy
104
- end
105
- end
106
-
107
- describe "#show_context?" do
108
- it "is unset by default" do
109
- expect(FoodCritic::CommandLine.new(["."]).show_context?).to be_falsey
110
- end
111
-
112
- it "is true if -C is specified" do
113
- expect(FoodCritic::CommandLine.new(["-C", "."]).show_context?).to be_truthy
114
- end
115
- it "is true if --context is specified" do
116
- expect(FoodCritic::CommandLine.new(["--context", "."]).show_context?).to be_truthy
117
- end
118
- it "is false if --no-context is specified" do
119
- expect(FoodCritic::CommandLine.new(["--no-context", "."]).show_context?).to be_falsey
120
- end
121
- end
122
-
123
- describe ":rule_file" do
124
- it "is unset if -r/--rule-file is not specified" do
125
- expect(FoodCritic::CommandLine.new(["."]).options[:rule_file].nil?).to be_truthy
126
- end
127
-
128
- it "is equal to the provided path if -r is set and path is specified" do
129
- expect(FoodCritic::CommandLine.new(["-r", "example", "."]).options[:rule_file]).to eq "example"
130
- end
131
-
132
- it "is equal to the provided path if --rule-file is set and path is specified" do
133
- expect(FoodCritic::CommandLine.new(["--rule-file", "example", "."]).options[:rule_file]).to eq "example"
134
- end
135
- end
136
- end
@@ -1,78 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe FoodCritic::Review do
4
- it "is instantiable with no warnings" do
5
- FoodCritic::Review.new("example", [])
6
- end
7
- describe "#cookbook_paths" do
8
- it "returns the cookbook paths provided" do
9
- expect(FoodCritic::Review.new(["example"], []).cookbook_paths).to eq ["example"]
10
- end
11
- it "returns the cookbook paths provided when there are multiple" do
12
- expect(FoodCritic::Review.new(%w{example example2}, []).cookbook_paths).to eq %w{example example2}
13
- end
14
- end
15
- describe "#warnings" do
16
- it "returns empty when there are no warnings" do
17
- expect(FoodCritic::Review.new("example", []).warnings).to be_empty
18
- end
19
- it "makes the warnings available" do
20
- warning = "Danger Will Robinson"
21
- expect(FoodCritic::Review.new("example", [warning]).warnings).to eq [warning]
22
- end
23
- end
24
- end
25
-
26
- describe FoodCritic::RuleList do
27
- it "is instantiable with no warnings" do
28
- FoodCritic::RuleList.new([])
29
- end
30
-
31
- let(:rule) { FoodCritic::Rule.new("FCTEST001", "Test rule") }
32
-
33
- describe "#rules" do
34
-
35
- it "is empty when instantiated with an empty rule list" do
36
- expect(FoodCritic::RuleList.new([]).rules).to be_empty
37
- end
38
-
39
- it "contains the given rule" do
40
- expect(FoodCritic::RuleList.new([rule]).rules).to include rule
41
- end
42
- end
43
- end
44
-
45
- describe FoodCritic::Rule do
46
- let(:rule) { FoodCritic::Rule.new("FCTEST001", "Test rule") }
47
-
48
- describe "#matches_tags?" do
49
- it "matches the rule's code" do
50
- expect(rule.matches_tags?(["FCTEST001"])).to be_truthy
51
- end
52
-
53
- it "doesn't match an unrelated code" do
54
- expect(rule.matches_tags?(["FCTEST999"])).to be_falsey
55
- end
56
- end
57
-
58
- describe "#tags" do
59
- it "returns any + the rule's code" do
60
- expect(rule.tags).to eq %w{any FCTEST001}
61
- end
62
- end
63
- end
64
-
65
- describe FoodCritic::Warning do
66
- let(:rule) { FoodCritic::Rule.new("FCTEST001", "Test rule") }
67
- let(:match_opts) { { filename: "foo/recipes.default.rb", line: 5, column: 40 } }
68
-
69
- describe "failure indication" do
70
- it "is false if no fail_tags match" do
71
- expect(FoodCritic::Warning.new(rule, match_opts, { fail_tags: [] })).to_not be_failed
72
- end
73
-
74
- it "is true if fail_tags do match" do
75
- expect(FoodCritic::Warning.new(rule, match_opts, { fail_tags: ["any"] })).to be_failed
76
- end
77
- end
78
- end
@@ -1,107 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe FoodCritic::Linter do
4
- let(:linter) { FoodCritic::Linter.new }
5
-
6
- describe "#initialize" do
7
- it "is instantiable" do
8
- # Check for errors from .new
9
- linter
10
- end
11
- end
12
-
13
- describe "chef version" do
14
- it "should be the latest stable version of Chef" do
15
- expect(FoodCritic::Linter::DEFAULT_CHEF_VERSION).to eq "14.7.17"
16
- end
17
- end
18
-
19
- describe "#cookbook_dir" do
20
- it "given a root alias file the cookbook is correctly detected" do
21
- expect(linter.send(:cookbook_dir, "./cookbook/recipe.rb").to_s).to eq "cookbook"
22
- end
23
-
24
- it "given the metadata.rb file the cookbook is correctly detected" do
25
- expect(linter.send(:cookbook_dir, "./cookbook/metadata.rb").to_s).to eq "cookbook"
26
- end
27
-
28
- it "given a template nested multiple levels deep the cookbook is correctly detected" do
29
- expect(linter.send(:cookbook_dir, "./cookbook/templates/foo/bar/file.erb").to_s).to eq "./cookbook"
30
- end
31
-
32
- it "given a template directly in the templates directory the cookbook is correctly detected" do
33
- expect(linter.send(:cookbook_dir, "./cookbook/templates/file.erb").to_s).to eq "./cookbook"
34
- end
35
-
36
- it "given a standard recipe file the cookbook is correctly detected" do
37
- expect(linter.send(:cookbook_dir, "./cookbook/recipes/default.rb").to_s).to eq "cookbook"
38
- end
39
- end
40
-
41
- describe "#check" do
42
- it "requires a cookbook_path, role_path or environment_path to be specified" do
43
- expect { linter.check({}) }.to raise_error ArgumentError
44
- end
45
-
46
- [:cookbook, :role, :environment].each do |path_type|
47
- key = "#{path_type}_paths".to_sym
48
- it "requires a #{path_type}_path by itself not to be nil" do
49
- expect { linter.check(key => nil) }.to raise_error ArgumentError
50
- end
51
- it "requires a #{path_type}_path by itself not to be empty" do
52
- expect { linter.check(key => []) }.to raise_error ArgumentError
53
- end
54
- it "accepts a scalar with a single #{path_type} path" do
55
- linter.check(key => ".")
56
- end
57
- it "accepts an array of #{path_type} paths" do
58
- linter.check(key => ["."])
59
- end
60
- it "returns a review when a #{path_type} path is provided" do
61
- expect(linter.check(key => ["."])).to respond_to :warnings
62
- end
63
- end
64
- end
65
-
66
- describe "#list_rules" do
67
- it "runs when --list is specified on the command line" do
68
- cli = FoodCritic::CommandLine.new %w{--list -t FC001 --search-gems}
69
- FoodCritic::Linter.run(cli)
70
- end
71
-
72
- it "does not require cookbook_path, role_path or environment_path to be specified" do
73
- linter.list(list: true)
74
- end
75
-
76
- it "returns a rule listing" do
77
- expect(linter.list(list: true)).to respond_to :rules
78
- end
79
- end
80
-
81
- describe "#load_files!" do
82
- let(:default_rule_files) do
83
- # an array of each of the absolute paths to the default rules
84
- Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "../../lib/foodcritic/rules/*")))
85
- end
86
-
87
- it "should add the default rule file" do
88
- expect(FoodCritic::RuleDsl).to receive(:load).with(default_rule_files, nil)
89
- linter.load_rules!({})
90
- end
91
-
92
- it "should include rules found in gems if the :search_gems option is true" do
93
- gem_rules = ["/path/to/rules1.rb", "/path/to/rules2.rb"]
94
- expected_rules = [*default_rule_files, *gem_rules]
95
- expect(FoodCritic::RuleDsl).to receive(:load).with(expected_rules, nil)
96
- expect(linter).to receive(:rule_files_in_gems).and_return(gem_rules)
97
- linter.load_rules!(search_gems: true)
98
- end
99
-
100
- it "should include files found in :include_rules option" do
101
- include_rules = ["/path/to/rules1.rb", "/path/to/rules2.rb"]
102
- expected_rules = [*default_rule_files, *include_rules]
103
- expect(FoodCritic::RuleDsl).to receive(:load).with(expected_rules, nil)
104
- linter.load_rules!(include_rules: include_rules)
105
- end
106
- end
107
- end
@@ -1,53 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe FoodCritic::Template::ExpressionExtractor do
4
- let(:extractor) { FoodCritic::Template::ExpressionExtractor.new }
5
- describe "#expressions" do
6
- it "returns empty if the template is empty" do
7
- expect(extractor.extract("")).to be_empty
8
- end
9
- it "returns empty if the template contains no erb at all" do
10
- expect(extractor.extract(%q{
11
- Hello World!
12
- })).to be_empty
13
- end
14
- it "returns erb conditionals" do
15
- expect(extractor.extract(%q{
16
- <% if true %>
17
- Hello World!
18
- <% end %>
19
- })).to eq [{ type: :statement, code: "if true", line: 2 },
20
- { type: :statement, code: "end", line: 4 }]
21
- end
22
- it "does not evaluate erb statements" do
23
- extractor.extract(%q{
24
- <% raise 'Should not have been evaluated' %>
25
- })
26
- end
27
- it "extracts an expression from within the template" do
28
- expect(extractor.extract(%q{
29
- <%= foo %>
30
- })).to eq [{ type: :expression, code: "foo", line: 2 }]
31
- end
32
- it "does not evaluate erb expressions" do
33
- extractor.extract(%q{
34
- <%= raise 'Should not have been evaluated' %>
35
- })
36
- end
37
- it "extracts multiple expressions" do
38
- expect(extractor.extract(%q{
39
- <Connector port="<%= node["tomcat"]["port"] %>" protocol="HTTP/1.1"
40
- connectionTimeout="20000"
41
- URIEncoding="UTF-8"
42
- redirectPort="<%= node["tomcat"]["ssl_port"] %>" />
43
- })).to eq [
44
- { type: :expression, code: 'node["tomcat"]["port"]', line: 2 },
45
- { type: :expression, code: 'node["tomcat"]["ssl_port"]', line: 5 },
46
- ]
47
- end
48
- it "excludes comment-only expressions" do
49
- expect(extractor.extract("<%# A comment %>")).to be_empty
50
- end
51
- end
52
-
53
- end