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
@@ -1,4 +1,4 @@
1
- require_relative "../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe FoodCritic::Chef do
4
4
 
@@ -9,49 +9,49 @@ describe FoodCritic::Chef do
9
9
  api.chef_dsl_methods.each { |m| m }
10
10
  end
11
11
  it "does not return an empty" do
12
- api.chef_dsl_methods.wont_be_empty
12
+ expect(api.chef_dsl_methods).to_not be_empty
13
13
  end
14
14
  it "returns dsl methods as symbols" do
15
- assert api.chef_dsl_methods.all? { |m| m == m.to_sym }
15
+ expect(api.chef_dsl_methods.all? { |m| m == m.to_sym }).to be_truthy
16
16
  end
17
17
  end
18
18
 
19
19
  describe "#resource_attribute?" do
20
20
  it "raises if the resource_type is nil" do
21
- lambda { api.resource_attribute?(nil, :name) }.must_raise(ArgumentError)
21
+ expect { api.resource_attribute?(nil, :name) }.to raise_error ArgumentError
22
22
  end
23
23
  it "raises if the resource_type is empty" do
24
- lambda { api.resource_attribute?("", :name) }.must_raise(ArgumentError)
24
+ expect { api.resource_attribute?("", :name) }.to raise_error ArgumentError
25
25
  end
26
26
  it "raises if the attribute_name is nil" do
27
- lambda { api.resource_attribute?(:file, nil) }.must_raise(ArgumentError)
27
+ expect { api.resource_attribute?(:file, nil) }.to raise_error ArgumentError
28
28
  end
29
29
  it "raises if the attribute_name is empty" do
30
- lambda { api.resource_attribute?(:file, "") }.must_raise(ArgumentError)
30
+ expect { api.resource_attribute?(:file, "") }.to raise_error ArgumentError
31
31
  end
32
32
  it "returns true if the resource attribute is known" do
33
- assert api.resource_attribute?(:file, :name)
33
+ expect(api.resource_attribute?(:file, :name)).to be_truthy
34
34
  end
35
35
  it "returns false if the resource attribute is not known" do
36
- refute api.resource_attribute?(:file, :size)
36
+ expect(api.resource_attribute?(:file, :size)).to be_falsey
37
37
  end
38
38
  it "returns true for unrecognised resources" do
39
- assert api.resource_attribute?(:cluster_file, :size)
39
+ expect(api.resource_attribute?(:cluster_file, :size)).to be_truthy
40
40
  end
41
41
  it "allows the resource type to be passed as a string" do
42
- refute api.resource_attribute?("file", :size)
42
+ expect(api.resource_attribute?("file", :size)).to be_falsey
43
43
  end
44
44
  it "allows the attribute_name to be passed as a string" do
45
- assert api.resource_attribute?(:file, "mode")
45
+ expect(api.resource_attribute?(:file, "mode")).to be_truthy
46
46
  end
47
47
  end
48
48
 
49
49
  describe "#valid_query?" do
50
50
  it "raises if the query is nil" do
51
- lambda { api.valid_query?(nil) }.must_raise(ArgumentError)
51
+ expect { api.valid_query?(nil) }.to raise_error ArgumentError
52
52
  end
53
53
  it "raises if the query is empty" do
54
- lambda { api.valid_query?("") }.must_raise(ArgumentError)
54
+ expect { api.valid_query?("") }.to raise_error ArgumentError
55
55
  end
56
56
  it "coerces the provided object to a string" do
57
57
  query = Class.new do
@@ -59,7 +59,7 @@ describe FoodCritic::Chef do
59
59
  "*:*"
60
60
  end
61
61
  end.new
62
- assert api.valid_query?(query)
62
+ expect(api.valid_query?(query)).to be_truthy
63
63
  end
64
64
  end
65
65
 
@@ -0,0 +1,122 @@
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
+ end
@@ -1,4 +1,4 @@
1
- require_relative "../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe FoodCritic::Review do
4
4
  it "is instantiable with no warnings" do
@@ -6,19 +6,19 @@ describe FoodCritic::Review do
6
6
  end
7
7
  describe "#cookbook_paths" do
8
8
  it "returns the cookbook paths provided" do
9
- FoodCritic::Review.new(["example"], []).cookbook_paths.must_equal ["example"]
9
+ expect(FoodCritic::Review.new(["example"], []).cookbook_paths).to eq ["example"]
10
10
  end
11
11
  it "returns the cookbook paths provided when there are multiple" do
12
- FoodCritic::Review.new(%w{example example2}, []).cookbook_paths.must_equal %w{example example2}
12
+ expect(FoodCritic::Review.new(%w{example example2}, []).cookbook_paths).to eq %w{example example2}
13
13
  end
14
14
  end
15
15
  describe "#warnings" do
16
16
  it "returns empty when there are no warnings" do
17
- FoodCritic::Review.new("example", []).warnings.must_be_empty
17
+ expect(FoodCritic::Review.new("example", []).warnings).to be_empty
18
18
  end
19
19
  it "makes the warnings available" do
20
20
  warning = "Danger Will Robinson"
21
- FoodCritic::Review.new("example", [warning]).warnings.must_equal [warning]
21
+ expect(FoodCritic::Review.new("example", [warning]).warnings).to eq [warning]
22
22
  end
23
23
  end
24
24
  end
@@ -33,11 +33,11 @@ describe FoodCritic::RuleList do
33
33
  describe "#rules" do
34
34
 
35
35
  it "is empty when instantiated with an empty rule list" do
36
- assert FoodCritic::RuleList.new([]).rules.empty?
36
+ expect(FoodCritic::RuleList.new([]).rules).to be_empty
37
37
  end
38
38
 
39
39
  it "contains the given rule" do
40
- assert FoodCritic::RuleList.new([rule]).rules.include?(rule)
40
+ expect(FoodCritic::RuleList.new([rule]).rules).to include rule
41
41
  end
42
42
  end
43
43
  end
@@ -47,17 +47,17 @@ describe FoodCritic::Rule do
47
47
 
48
48
  describe "#matches_tags?" do
49
49
  it "matches the rule's code" do
50
- rule.matches_tags?(["FCTEST001"]).must_equal true
50
+ expect(rule.matches_tags?(["FCTEST001"])).to be_truthy
51
51
  end
52
52
 
53
53
  it "doesn't match an unrelated code" do
54
- rule.matches_tags?(["FCTEST999"]).must_equal false
54
+ expect(rule.matches_tags?(["FCTEST999"])).to be_falsey
55
55
  end
56
56
  end
57
57
 
58
58
  describe "#tags" do
59
59
  it "returns any + the rule's code" do
60
- rule.tags.must_equal %w{any FCTEST001}
60
+ expect(rule.tags).to eq %w{any FCTEST001}
61
61
  end
62
62
  end
63
63
  end
@@ -68,11 +68,11 @@ describe FoodCritic::Warning do
68
68
 
69
69
  describe "failure indication" do
70
70
  it "is false if no fail_tags match" do
71
- FoodCritic::Warning.new(rule, match_opts, { :fail_tags => [] }).failed?.must_equal false
71
+ expect(FoodCritic::Warning.new(rule, match_opts, { :fail_tags => [] })).to_not be_failed
72
72
  end
73
73
 
74
74
  it "is true if fail_tags do match" do
75
- FoodCritic::Warning.new(rule, match_opts, { :fail_tags => ["any"] }).failed?.must_equal true
75
+ expect(FoodCritic::Warning.new(rule, match_opts, { :fail_tags => ["any"] })).to be_failed
76
76
  end
77
77
  end
78
78
  end
@@ -1,33 +1,33 @@
1
- require_relative "../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe FoodCritic::Linter do
4
4
  let(:linter) { FoodCritic::Linter.new }
5
5
 
6
6
  describe "#initialize" do
7
7
  it "is instantiable" do
8
- linter.wont_be_nil
8
+ # Check for errors from .new
9
+ linter
9
10
  end
10
11
  end
11
12
 
12
13
  describe "chef version" do
13
14
  it "should be the latest stable version of Chef" do
14
- FoodCritic::Linter::DEFAULT_CHEF_VERSION.must_equal "12.19.36"
15
+ expect(FoodCritic::Linter::DEFAULT_CHEF_VERSION).to eq "12.19.36"
15
16
  end
16
17
  end
17
18
 
18
19
  describe "#check" do
19
-
20
20
  it "requires a cookbook_path, role_path or environment_path to be specified" do
21
- lambda { linter.check({}) }.must_raise ArgumentError
21
+ expect { linter.check({}) }.to raise_error ArgumentError
22
22
  end
23
23
 
24
24
  [:cookbook, :role, :environment].each do |path_type|
25
25
  key = "#{path_type}_paths".to_sym
26
26
  it "requires a #{path_type}_path by itself not to be nil" do
27
- lambda { linter.check(key => nil) }.must_raise ArgumentError
27
+ expect { linter.check(key => nil) }.to raise_error ArgumentError
28
28
  end
29
29
  it "requires a #{path_type}_path by itself not to be empty" do
30
- lambda { linter.check(key => []) }.must_raise ArgumentError
30
+ expect { linter.check(key => []) }.to raise_error ArgumentError
31
31
  end
32
32
  it "accepts a scalar with a single #{path_type} path" do
33
33
  linter.check(key => ".")
@@ -36,20 +36,23 @@ describe FoodCritic::Linter do
36
36
  linter.check(key => ["."])
37
37
  end
38
38
  it "returns a review when a #{path_type} path is provided" do
39
- linter.check(key => ["."]).must_respond_to(:warnings)
39
+ expect(linter.check(key => ["."])).to respond_to :warnings
40
40
  end
41
41
  end
42
-
43
42
  end
44
43
 
45
44
  describe "#list_rules" do
45
+ it "runs when --list is specified on the command line" do
46
+ cli = FoodCritic::CommandLine.new %w{--list -t FC001 --search-gems}
47
+ FoodCritic::Linter.run(cli)
48
+ end
46
49
 
47
50
  it "does not require cookbook_path, role_path or environment_path to be specified" do
48
51
  linter.list(:list => true)
49
52
  end
50
53
 
51
54
  it "returns a rule listing" do
52
- linter.list(:list => true).must_respond_to(:rules)
55
+ expect(linter.list(:list => true)).to respond_to :rules
53
56
  end
54
57
  end
55
58
 
@@ -59,42 +62,24 @@ describe FoodCritic::Linter do
59
62
  Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "../../lib/foodcritic/rules/*")))
60
63
  end
61
64
 
62
- let(:rule_dsl_load_mock) { MiniTest::Mock.new }
63
-
64
65
  it "should add the default rule file" do
65
- rule_dsl_load_mock.expect(:call, nil, [default_rule_files, nil])
66
- verify_loaded
66
+ expect(FoodCritic::RuleDsl).to receive(:load).with(default_rule_files, nil)
67
+ linter.load_rules!({})
67
68
  end
68
69
 
69
70
  it "should include rules found in gems if the :search_gems option is true" do
70
71
  gem_rules = ["/path/to/rules1.rb", "/path/to/rules2.rb"]
71
72
  expected_rules = [*default_rule_files, *gem_rules]
72
- rule_dsl_load_mock.expect(:call, nil, [expected_rules, nil])
73
-
74
- metaclass = class << linter; self; end
75
- metaclass.send(:define_method, :rule_files_in_gems) do
76
- gem_rules
77
- end
78
-
79
- verify_loaded :search_gems => true
73
+ expect(FoodCritic::RuleDsl).to receive(:load).with(expected_rules, nil)
74
+ expect(linter).to receive(:rule_files_in_gems).and_return(gem_rules)
75
+ linter.load_rules!(:search_gems => true)
80
76
  end
81
77
 
82
78
  it "should include files found in :include_rules option" do
83
79
  include_rules = ["/path/to/rules1.rb", "/path/to/rules2.rb"]
84
80
  expected_rules = [*default_rule_files, *include_rules]
85
- rule_dsl_load_mock.expect(:call, nil, [expected_rules, nil])
86
-
87
- verify_loaded :include_rules => include_rules
81
+ expect(FoodCritic::RuleDsl).to receive(:load).with(expected_rules, nil)
82
+ linter.load_rules!(:include_rules => include_rules)
88
83
  end
89
-
90
- def verify_loaded(options = {})
91
- FoodCritic::RuleDsl.stub :load, rule_dsl_load_mock do
92
- linter.load_rules! options
93
- end
94
-
95
- rule_dsl_load_mock.verify
96
- end
97
-
98
84
  end
99
-
100
85
  end
@@ -1,23 +1,23 @@
1
- require_relative "../spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
  describe FoodCritic::Template::ExpressionExtractor do
4
4
  let(:extractor) { FoodCritic::Template::ExpressionExtractor.new }
5
5
  describe "#expressions" do
6
6
  it "returns empty if the template is empty" do
7
- extractor.extract("").must_be_empty
7
+ expect(extractor.extract("")).to be_empty
8
8
  end
9
9
  it "returns empty if the template contains no erb at all" do
10
- extractor.extract(%q{
10
+ expect(extractor.extract(%q{
11
11
  Hello World!
12
- }).must_be_empty
12
+ })).to be_empty
13
13
  end
14
14
  it "returns erb conditionals" do
15
- extractor.extract(%q{
15
+ expect(extractor.extract(%q{
16
16
  <% if true %>
17
17
  Hello World!
18
18
  <% end %>
19
- }).must_equal([{ :type => :statement, :code => "if true", :line => 2 },
20
- { :type => :statement, :code => "end", :line => 4 }])
19
+ })).to eq [{ :type => :statement, :code => "if true", :line => 2 },
20
+ { :type => :statement, :code => "end", :line => 4 }]
21
21
  end
22
22
  it "does not evaluate erb statements" do
23
23
  extractor.extract(%q{
@@ -25,9 +25,9 @@ describe FoodCritic::Template::ExpressionExtractor do
25
25
  })
26
26
  end
27
27
  it "extracts an expression from within the template" do
28
- extractor.extract(%q{
28
+ expect(extractor.extract(%q{
29
29
  <%= foo %>
30
- }).must_equal([{ :type => :expression, :code => "foo", :line => 2 }])
30
+ })).to eq [{ :type => :expression, :code => "foo", :line => 2 }]
31
31
  end
32
32
  it "does not evaluate erb expressions" do
33
33
  extractor.extract(%q{
@@ -35,18 +35,18 @@ describe FoodCritic::Template::ExpressionExtractor do
35
35
  })
36
36
  end
37
37
  it "extracts multiple expressions" do
38
- extractor.extract(%q{
38
+ expect(extractor.extract(%q{
39
39
  <Connector port="<%= node["tomcat"]["port"] %>" protocol="HTTP/1.1"
40
40
  connectionTimeout="20000"
41
41
  URIEncoding="UTF-8"
42
42
  redirectPort="<%= node["tomcat"]["ssl_port"] %>" />
43
- }).must_equal([
43
+ })).to eq [
44
44
  { :type => :expression, :code => 'node["tomcat"]["port"]', :line => 2 },
45
45
  { :type => :expression, :code => 'node["tomcat"]["ssl_port"]', :line => 5 },
46
- ])
46
+ ]
47
47
  end
48
48
  it "excludes comment-only expressions" do
49
- extractor.extract("<%# A comment %>").must_be_empty
49
+ expect(extractor.extract("<%# A comment %>")).to be_empty
50
50
  end
51
51
  end
52
52