chef 12.0.0.alpha.0 → 12.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -5
  3. data/lib/chef/api_client.rb +1 -1
  4. data/lib/chef/application.rb +16 -8
  5. data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
  6. data/lib/chef/chef_fs/command_line.rb +1 -1
  7. data/lib/chef/chef_fs/file_system.rb +1 -1
  8. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  9. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
  10. data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
  11. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
  12. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
  13. data/lib/chef/config.rb +6 -5
  14. data/lib/chef/config_fetcher.rb +1 -1
  15. data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
  16. data/lib/chef/cookbook/metadata.rb +102 -53
  17. data/lib/chef/cookbook/syntax_check.rb +1 -1
  18. data/lib/chef/cookbook_loader.rb +62 -14
  19. data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
  20. data/lib/chef/cookbook_version.rb +13 -4
  21. data/lib/chef/data_bag.rb +28 -15
  22. data/lib/chef/data_bag_item.rb +5 -7
  23. data/lib/chef/digester.rb +5 -9
  24. data/lib/chef/dsl/recipe.rb +14 -0
  25. data/lib/chef/encrypted_data_bag_item.rb +1 -0
  26. data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
  27. data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
  28. data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
  29. data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
  30. data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
  31. data/lib/chef/environment.rb +1 -3
  32. data/lib/chef/exceptions.rb +18 -3
  33. data/lib/chef/formatters/base.rb +7 -0
  34. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  35. data/lib/chef/handler/json_file.rb +0 -1
  36. data/lib/chef/http/json_output.rb +1 -1
  37. data/lib/chef/json_compat.rb +24 -6
  38. data/lib/chef/knife/bootstrap.rb +2 -2
  39. data/lib/chef/knife/client_delete.rb +1 -1
  40. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  41. data/lib/chef/knife/cookbook_site_list.rb +1 -1
  42. data/lib/chef/knife/cookbook_site_search.rb +1 -1
  43. data/lib/chef/knife/cookbook_site_share.rb +2 -2
  44. data/lib/chef/knife/cookbook_site_show.rb +3 -3
  45. data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
  46. data/lib/chef/knife/core/node_editor.rb +2 -3
  47. data/lib/chef/knife/core/ui.rb +2 -2
  48. data/lib/chef/knife/deps.rb +2 -3
  49. data/lib/chef/mixin/shell_out.rb +1 -1
  50. data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
  51. data/lib/chef/node.rb +1 -2
  52. data/lib/chef/platform/provider_mapping.rb +33 -6
  53. data/lib/chef/provider.rb +0 -2
  54. data/lib/chef/provider/cookbook_file/content.rb +1 -1
  55. data/lib/chef/provider/cron.rb +11 -0
  56. data/lib/chef/provider/deploy.rb +3 -2
  57. data/lib/chef/provider/deploy/revision.rb +2 -2
  58. data/lib/chef/provider/env.rb +1 -1
  59. data/lib/chef/provider/env/windows.rb +5 -9
  60. data/lib/chef/provider/file.rb +84 -33
  61. data/lib/chef/provider/git.rb +2 -1
  62. data/lib/chef/provider/group/aix.rb +17 -2
  63. data/lib/chef/provider/group/dscl.rb +27 -9
  64. data/lib/chef/provider/group/pw.rb +8 -1
  65. data/lib/chef/provider/http_request.rb +4 -4
  66. data/lib/chef/provider/log.rb +4 -14
  67. data/lib/chef/provider/mount/mount.rb +2 -2
  68. data/lib/chef/provider/package/ips.rb +17 -23
  69. data/lib/chef/provider/package/paludis.rb +2 -2
  70. data/lib/chef/provider/package/rpm.rb +2 -2
  71. data/lib/chef/provider/package/rubygems.rb +2 -0
  72. data/lib/chef/provider/package/yum.rb +2 -0
  73. data/lib/chef/provider/package/zypper.rb +1 -1
  74. data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
  75. data/lib/chef/provider/service/windows.rb +87 -21
  76. data/lib/chef/provider/user/aix.rb +95 -0
  77. data/lib/chef/provider/user/dscl.rb +544 -156
  78. data/lib/chef/provider/user/useradd.rb +1 -0
  79. data/lib/chef/providers.rb +1 -0
  80. data/lib/chef/resource.rb +4 -3
  81. data/lib/chef/resource/freebsd_package.rb +10 -2
  82. data/lib/chef/resource/paludis_package.rb +1 -0
  83. data/lib/chef/resource/scm.rb +10 -0
  84. data/lib/chef/resource/user.rb +27 -0
  85. data/lib/chef/resource/windows_service.rb +53 -0
  86. data/lib/chef/resource_collection.rb +23 -12
  87. data/lib/chef/resource_reporter.rb +10 -10
  88. data/lib/chef/resources.rb +1 -0
  89. data/lib/chef/role.rb +3 -3
  90. data/lib/chef/run_list.rb +6 -3
  91. data/lib/chef/user.rb +1 -1
  92. data/lib/chef/util/diff.rb +1 -2
  93. data/lib/chef/version.rb +1 -1
  94. data/lib/chef/version_constraint.rb +4 -4
  95. data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
  96. data/spec/data/cookbooks/apache2/metadata.rb +2 -0
  97. data/spec/data/cookbooks/borken/metadata.rb +2 -0
  98. data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
  99. data/spec/data/cookbooks/java/metadata.rb +2 -0
  100. data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
  101. data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
  102. data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
  103. data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
  104. data/spec/data/cookbooks/preseed/metadata.rb +2 -0
  105. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
  106. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
  107. data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
  108. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
  109. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
  110. data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
  111. data/spec/data/mac_users/10.7-8.plist.xml +559 -0
  112. data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
  113. data/spec/data/mac_users/10.7.plist.xml +559 -0
  114. data/spec/data/mac_users/10.7.shadow.xml +11 -0
  115. data/spec/data/mac_users/10.8.plist.xml +559 -0
  116. data/spec/data/mac_users/10.8.shadow.xml +21 -0
  117. data/spec/data/mac_users/10.9.plist.xml +560 -0
  118. data/spec/data/mac_users/10.9.shadow.xml +21 -0
  119. data/spec/data/object_loader/environments/test.json +2 -0
  120. data/spec/data/object_loader/environments/test_json_class.json +2 -0
  121. data/spec/data/object_loader/nodes/test.json +2 -0
  122. data/spec/data/object_loader/nodes/test_json_class.json +2 -0
  123. data/spec/data/object_loader/roles/test.json +2 -0
  124. data/spec/data/object_loader/roles/test_json_class.json +2 -0
  125. data/spec/functional/resource/bff_spec.rb +1 -1
  126. data/spec/functional/resource/cron_spec.rb +20 -1
  127. data/spec/functional/resource/env_spec.rb +137 -0
  128. data/spec/functional/resource/group_spec.rb +7 -5
  129. data/spec/functional/resource/remote_file_spec.rb +12 -1
  130. data/spec/functional/resource/user/dscl_spec.rb +198 -0
  131. data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
  132. data/spec/integration/client/client_spec.rb +6 -4
  133. data/spec/integration/client/ipv6_spec.rb +16 -14
  134. data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
  135. data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
  136. data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
  137. data/spec/integration/knife/chefignore_spec.rb +76 -46
  138. data/spec/integration/knife/common_options_spec.rb +16 -21
  139. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
  140. data/spec/integration/knife/delete_spec.rb +66 -46
  141. data/spec/integration/knife/deps_spec.rb +145 -94
  142. data/spec/integration/knife/diff_spec.rb +176 -110
  143. data/spec/integration/knife/download_spec.rb +229 -133
  144. data/spec/integration/knife/list_spec.rb +62 -54
  145. data/spec/integration/knife/raw_spec.rb +24 -9
  146. data/spec/integration/knife/redirection_spec.rb +2 -2
  147. data/spec/integration/knife/serve_spec.rb +2 -2
  148. data/spec/integration/knife/show_spec.rb +32 -26
  149. data/spec/integration/knife/upload_spec.rb +308 -165
  150. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
  151. data/spec/integration/solo/solo_spec.rb +22 -11
  152. data/spec/spec_helper.rb +3 -0
  153. data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
  154. data/spec/support/platform_helpers.rb +12 -0
  155. data/spec/support/shared/functional/file_resource.rb +10 -0
  156. data/spec/support/shared/integration/chef_zero_support.rb +130 -0
  157. data/spec/support/shared/integration/integration_helper.rb +100 -98
  158. data/spec/support/shared/integration/knife_support.rb +0 -1
  159. data/spec/support/shared/unit/provider/file.rb +6 -4
  160. data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
  161. data/spec/unit/api_client/registration_spec.rb +83 -74
  162. data/spec/unit/application_spec.rb +32 -9
  163. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
  164. data/spec/unit/cookbook/metadata_spec.rb +190 -150
  165. data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
  166. data/spec/unit/cookbook_loader_spec.rb +114 -53
  167. data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
  168. data/spec/unit/data_bag_spec.rb +88 -13
  169. data/spec/unit/deprecation_spec.rb +1 -2
  170. data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
  171. data/spec/unit/environment_spec.rb +1 -1
  172. data/spec/unit/formatters/base_spec.rb +48 -0
  173. data/spec/unit/json_compat_spec.rb +48 -17
  174. data/spec/unit/knife/client_delete_spec.rb +4 -4
  175. data/spec/unit/knife/client_show_spec.rb +15 -5
  176. data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
  177. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  178. data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
  179. data/spec/unit/knife/data_bag_show_spec.rb +23 -14
  180. data/spec/unit/knife/node_show_spec.rb +32 -15
  181. data/spec/unit/knife/role_show_spec.rb +59 -0
  182. data/spec/unit/platform_spec.rb +10 -0
  183. data/spec/unit/provider/deploy_spec.rb +4 -0
  184. data/spec/unit/provider/env_spec.rb +19 -0
  185. data/spec/unit/provider/git_spec.rb +22 -2
  186. data/spec/unit/provider/group/dscl_spec.rb +38 -1
  187. data/spec/unit/provider/group/pw_spec.rb +2 -2
  188. data/spec/unit/provider/http_request_spec.rb +8 -8
  189. data/spec/unit/provider/log_spec.rb +33 -53
  190. data/spec/unit/provider/mount/mount_spec.rb +12 -3
  191. data/spec/unit/provider/package/ips_spec.rb +96 -63
  192. data/spec/unit/provider/package/paludis_spec.rb +5 -5
  193. data/spec/unit/provider/package/rpm_spec.rb +12 -0
  194. data/spec/unit/provider/package/zypper_spec.rb +28 -16
  195. data/spec/unit/provider/service/windows_spec.rb +77 -17
  196. data/spec/unit/provider/user/dscl_spec.rb +659 -264
  197. data/spec/unit/provider/user/useradd_spec.rb +1 -0
  198. data/spec/unit/recipe_spec.rb +41 -0
  199. data/spec/unit/resource/scm_spec.rb +11 -0
  200. data/spec/unit/resource/user_spec.rb +4 -0
  201. data/spec/unit/resource/windows_service_spec.rb +46 -0
  202. data/spec/unit/resource_collection_spec.rb +33 -0
  203. data/spec/unit/resource_reporter_spec.rb +48 -0
  204. data/spec/unit/resource_spec.rb +9 -2
  205. data/spec/unit/role_spec.rb +6 -0
  206. data/spec/unit/version_constraint_spec.rb +28 -0
  207. metadata +61 -4
@@ -21,10 +21,8 @@ require 'spec_helper'
21
21
  require 'chef/cookbook/metadata'
22
22
 
23
23
  describe Chef::Cookbook::Metadata do
24
- before(:each) do
25
- @cookbook = Chef::CookbookVersion.new('test_cookbook')
26
- @meta = Chef::Cookbook::Metadata.new(@cookbook)
27
- end
24
+
25
+ let(:metadata) { Chef::Cookbook::Metadata.new }
28
26
 
29
27
  describe "when comparing for equality" do
30
28
  before do
@@ -35,7 +33,7 @@ describe Chef::Cookbook::Metadata do
35
33
  end
36
34
 
37
35
  it "does not depend on object identity for equality" do
38
- @meta.should == @meta.dup
36
+ metadata.should == metadata.dup
39
37
  end
40
38
 
41
39
  it "is not equal to another object if it isn't have all of the metadata fields" do
@@ -45,7 +43,7 @@ describe Chef::Cookbook::Metadata do
45
43
  almost_duck_type = Struct.new(*fields_to_include).new
46
44
  @fields.each do |field|
47
45
  setter = "#{field}="
48
- metadata_value = @meta.send(field)
46
+ metadata_value = metadata.send(field)
49
47
  almost_duck_type.send(setter, metadata_value) if almost_duck_type.respond_to?(setter)
50
48
  @mets.should_not == almost_duck_type
51
49
  end
@@ -56,10 +54,10 @@ describe Chef::Cookbook::Metadata do
56
54
  duck_type = Struct.new(*@fields).new
57
55
  @fields.each do |field|
58
56
  setter = "#{field}="
59
- metadata_value = @meta.send(field)
57
+ metadata_value = metadata.send(field)
60
58
  duck_type.send(setter, metadata_value)
61
59
  end
62
- @meta.should == duck_type
60
+ metadata.should == duck_type
63
61
  end
64
62
 
65
63
  it "is not equal if any values are different" do
@@ -69,78 +67,117 @@ describe Chef::Cookbook::Metadata do
69
67
 
70
68
  @fields.each do |field|
71
69
  setter = "#{field}="
72
- metadata_value = @meta.send(field)
70
+ metadata_value = metadata.send(field)
73
71
  duck_type.send(setter, metadata_value)
74
72
  end
75
73
 
76
- field_to_change
77
-
78
74
  duck_type.send("#{field_to_change}=".to_sym, :epic_fail)
79
- @meta.should_not == duck_type
75
+ metadata.should_not == duck_type
80
76
  end
81
77
  end
82
78
 
83
79
  end
84
80
 
85
81
  describe "when first created" do
86
- it "should return a Chef::Cookbook::Metadata object" do
87
- @meta.should be_a_kind_of(Chef::Cookbook::Metadata)
82
+
83
+ it "has no name" do
84
+ metadata.name.should eq(nil)
88
85
  end
89
86
 
90
- it "should allow a cookbook as the first argument" do
91
- lambda { Chef::Cookbook::Metadata.new(@cookbook) }.should_not raise_error
87
+ it "has an empty description" do
88
+ metadata.description.should eq("")
92
89
  end
93
90
 
94
- it "should allow an maintainer name for the second argument" do
95
- lambda { Chef::Cookbook::Metadata.new(@cookbook, 'Bobo T. Clown') }.should_not raise_error
91
+ it "has an empty long description" do
92
+ metadata.long_description.should eq("")
96
93
  end
97
94
 
98
- it "should set the maintainer name from the second argument" do
99
- md = Chef::Cookbook::Metadata.new(@cookbook, 'Bobo T. Clown')
100
- md.maintainer.should == 'Bobo T. Clown'
95
+ it "defaults to 'all rights reserved' license" do
96
+ metadata.license.should eq("All rights reserved")
101
97
  end
102
98
 
103
- it "should allow an maintainer email for the third argument" do
104
- lambda { Chef::Cookbook::Metadata.new(@cookbook, 'Bobo T. Clown', 'bobo@clown.co') }.should_not raise_error
99
+ it "has an empty maintainer field" do
100
+ metadata.maintainer.should eq(nil)
105
101
  end
106
102
 
107
- it "should set the maintainer email from the third argument" do
108
- md = Chef::Cookbook::Metadata.new(@cookbook, 'Bobo T. Clown', 'bobo@clown.co')
109
- md.maintainer_email.should == 'bobo@clown.co'
103
+ it "has an empty maintainer_email field" do
104
+ metadata.maintainer.should eq(nil)
110
105
  end
111
106
 
112
- it "should allow a license for the fourth argument" do
113
- lambda { Chef::Cookbook::Metadata.new(@cookbook, 'Bobo T. Clown', 'bobo@clown.co', 'Clown License v1') }.should_not raise_error
107
+ it "has an empty platforms list" do
108
+ metadata.platforms.should eq(Mash.new)
114
109
  end
115
110
 
116
- it "should set the license from the fourth argument" do
117
- md = Chef::Cookbook::Metadata.new(@cookbook, 'Bobo T. Clown', 'bobo@clown.co', 'Clown License v1')
118
- md.license.should == 'Clown License v1'
111
+ it "has an empty dependencies list" do
112
+ metadata.dependencies.should eq(Mash.new)
119
113
  end
120
- end
121
114
 
122
- describe "cookbook" do
123
- it "should return the cookbook we were initialized with" do
124
- @meta.cookbook.should eql(@cookbook)
115
+ it "has an empty recommends list" do
116
+ metadata.recommendations.should eq(Mash.new)
125
117
  end
126
- end
127
118
 
128
- describe "name" do
129
- it "should return the name of the cookbook" do
130
- @meta.name.should eql(@cookbook.name)
119
+ it "has an empty suggestions list" do
120
+ metadata.suggestions.should eq(Mash.new)
131
121
  end
122
+
123
+ it "has an empty conflicts list" do
124
+ metadata.conflicting.should eq(Mash.new)
125
+ end
126
+
127
+ it "has an empty replaces list" do
128
+ metadata.replacing.should eq(Mash.new)
129
+ end
130
+
131
+ it "has an empty attributes list" do
132
+ metadata.attributes.should eq(Mash.new)
133
+ end
134
+
135
+ it "has an empty groupings list" do
136
+ metadata.groupings.should eq(Mash.new)
137
+ end
138
+
139
+ it "has an empty recipes list" do
140
+ metadata.recipes.should eq(Mash.new)
141
+ end
142
+
132
143
  end
133
144
 
134
- describe "platforms" do
135
- it "should return the current platform hash" do
136
- @meta.platforms.should be_a_kind_of(Hash)
145
+ describe "validation" do
146
+
147
+ context "when no required fields are set" do
148
+
149
+ it "is not valid" do
150
+ metadata.should_not be_valid
151
+ end
152
+
153
+ it "has a list of validation errors" do
154
+ expected_errors = ["The `name' attribute is required in cookbook metadata"]
155
+ metadata.errors.should eq(expected_errors)
156
+ end
157
+
137
158
  end
159
+
160
+ context "when all required fields are set" do
161
+ before do
162
+ metadata.name "a-valid-name"
163
+ end
164
+
165
+ it "is valid" do
166
+ metadata.should be_valid
167
+ end
168
+
169
+ it "has no validation errors" do
170
+ metadata.errors.should be_empty
171
+ end
172
+
173
+ end
174
+
138
175
  end
139
176
 
140
177
  describe "adding a supported platform" do
141
178
  it "should support adding a supported platform with a single expression" do
142
- @meta.supports("ubuntu", ">= 8.04")
143
- @meta.platforms["ubuntu"].should == '>= 8.04'
179
+ metadata.supports("ubuntu", ">= 8.04")
180
+ metadata.platforms["ubuntu"].should == '>= 8.04'
144
181
  end
145
182
  end
146
183
 
@@ -156,23 +193,23 @@ describe Chef::Cookbook::Metadata do
156
193
  params.sort { |a,b| a.to_s <=> b.to_s }.each do |field, field_value|
157
194
  describe field do
158
195
  it "should be set-able via #{field}" do
159
- @meta.send(field, field_value).should eql(field_value)
196
+ metadata.send(field, field_value).should eql(field_value)
160
197
  end
161
198
  it "should be get-able via #{field}" do
162
- @meta.send(field, field_value)
163
- @meta.send(field).should eql(field_value)
199
+ metadata.send(field, field_value)
200
+ metadata.send(field).should eql(field_value)
164
201
  end
165
202
  end
166
203
  end
167
204
 
168
205
  describe "version transformation" do
169
206
  it "should transform an '0.6' version to '0.6.0'" do
170
- @meta.send(:version, "0.6").should eql("0.6.0")
207
+ metadata.send(:version, "0.6").should eql("0.6.0")
171
208
  end
172
209
 
173
210
  it "should spit out '0.6.0' after transforming '0.6'" do
174
- @meta.send(:version, "0.6")
175
- @meta.send(:version).should eql("0.6.0")
211
+ metadata.send(:version, "0.6")
212
+ metadata.send(:version).should eql("0.6.0")
176
213
  end
177
214
  end
178
215
  end
@@ -191,11 +228,11 @@ describe Chef::Cookbook::Metadata do
191
228
  check_with = dep_args.shift
192
229
  describe dep do
193
230
  it "should be set-able via #{dep}" do
194
- @meta.send(dep, *dep_args).should == dep_args[1]
231
+ metadata.send(dep, *dep_args).should == dep_args[1]
195
232
  end
196
233
  it "should be get-able via #{check_with}" do
197
- @meta.send(dep, *dep_args)
198
- @meta.send(check_with).should == { dep_args[0] => dep_args[1] }
234
+ metadata.send(dep, *dep_args)
235
+ metadata.send(check_with).should == { dep_args[0] => dep_args[1] }
199
236
  end
200
237
  end
201
238
  end
@@ -213,11 +250,11 @@ describe Chef::Cookbook::Metadata do
213
250
  normalized_version = dep_args.pop
214
251
  describe dep do
215
252
  it "should be set-able and normalized via #{dep}" do
216
- @meta.send(dep, *dep_args).should == normalized_version
253
+ metadata.send(dep, *dep_args).should == normalized_version
217
254
  end
218
255
  it "should be get-able and normalized via #{check_with}" do
219
- @meta.send(dep, *dep_args)
220
- @meta.send(check_with).should == { dep_args[0] => normalized_version }
256
+ metadata.send(dep, *dep_args)
257
+ metadata.send(check_with).should == { dep_args[0] => normalized_version }
221
258
  end
222
259
  end
223
260
  end
@@ -235,7 +272,7 @@ describe Chef::Cookbook::Metadata do
235
272
 
236
273
  dep_types.each do |dep, dep_args|
237
274
  it "for #{dep} raises an informative error instead of vomiting on your shoes" do
238
- lambda {@meta.send(dep, *dep_args)}.should raise_error(Chef::Exceptions::ObsoleteDependencySyntax)
275
+ lambda {metadata.send(dep, *dep_args)}.should raise_error(Chef::Exceptions::ObsoleteDependencySyntax)
239
276
  end
240
277
  end
241
278
  end
@@ -253,7 +290,7 @@ describe Chef::Cookbook::Metadata do
253
290
 
254
291
  dep_types.each do |dep, dep_args|
255
292
  it "for #{dep} raises an informative error instead of vomiting on your shoes" do
256
- lambda {@meta.send(dep, *dep_args)}.should raise_error(Chef::Exceptions::InvalidVersionConstraint)
293
+ lambda {metadata.send(dep, *dep_args)}.should raise_error(Chef::Exceptions::InvalidVersionConstraint)
257
294
  end
258
295
  end
259
296
  end
@@ -265,23 +302,23 @@ describe Chef::Cookbook::Metadata do
265
302
  "title" => "MySQL Tuning",
266
303
  "description" => "Setting from the my.cnf file that allow you to tune your mysql server"
267
304
  }
268
- @meta.grouping("/db/mysql/databases/tuning", group).should == group
305
+ metadata.grouping("/db/mysql/databases/tuning", group).should == group
269
306
  end
270
307
  it "should not accept anything but a string for display_name" do
271
308
  lambda {
272
- @meta.grouping("db/mysql/databases", :title => "foo")
309
+ metadata.grouping("db/mysql/databases", :title => "foo")
273
310
  }.should_not raise_error
274
311
  lambda {
275
- @meta.grouping("db/mysql/databases", :title => Hash.new)
312
+ metadata.grouping("db/mysql/databases", :title => Hash.new)
276
313
  }.should raise_error(ArgumentError)
277
314
  end
278
315
 
279
316
  it "should not accept anything but a string for the description" do
280
317
  lambda {
281
- @meta.grouping("db/mysql/databases", :description => "foo")
318
+ metadata.grouping("db/mysql/databases", :description => "foo")
282
319
  }.should_not raise_error
283
320
  lambda {
284
- @meta.grouping("db/mysql/databases", :description => Hash.new)
321
+ metadata.grouping("db/mysql/databases", :description => Hash.new)
285
322
  }.should raise_error(ArgumentError)
286
323
  end
287
324
  end
@@ -298,151 +335,151 @@ describe Chef::Cookbook::Metadata do
298
335
  "recipes" => [ "mysql::server", "mysql::master" ],
299
336
  "default" => [ ]
300
337
  }
301
- @meta.attribute("/db/mysql/databases", attrs).should == attrs
338
+ metadata.attribute("/db/mysql/databases", attrs).should == attrs
302
339
  end
303
340
 
304
341
  it "should not accept anything but a string for display_name" do
305
342
  lambda {
306
- @meta.attribute("db/mysql/databases", :display_name => "foo")
343
+ metadata.attribute("db/mysql/databases", :display_name => "foo")
307
344
  }.should_not raise_error
308
345
  lambda {
309
- @meta.attribute("db/mysql/databases", :display_name => Hash.new)
346
+ metadata.attribute("db/mysql/databases", :display_name => Hash.new)
310
347
  }.should raise_error(ArgumentError)
311
348
  end
312
349
 
313
350
  it "should not accept anything but a string for the description" do
314
351
  lambda {
315
- @meta.attribute("db/mysql/databases", :description => "foo")
352
+ metadata.attribute("db/mysql/databases", :description => "foo")
316
353
  }.should_not raise_error
317
354
  lambda {
318
- @meta.attribute("db/mysql/databases", :description => Hash.new)
355
+ metadata.attribute("db/mysql/databases", :description => Hash.new)
319
356
  }.should raise_error(ArgumentError)
320
357
  end
321
358
 
322
359
  it "should not accept anything but an array of strings for choice" do
323
360
  lambda {
324
- @meta.attribute("db/mysql/databases", :choice => ['dedicated', 'shared'])
361
+ metadata.attribute("db/mysql/databases", :choice => ['dedicated', 'shared'])
325
362
  }.should_not raise_error
326
363
  lambda {
327
- @meta.attribute("db/mysql/databases", :choice => [10, 'shared'])
364
+ metadata.attribute("db/mysql/databases", :choice => [10, 'shared'])
328
365
  }.should raise_error(ArgumentError)
329
366
  lambda {
330
- @meta.attribute("db/mysql/databases", :choice => Hash.new)
367
+ metadata.attribute("db/mysql/databases", :choice => Hash.new)
331
368
  }.should raise_error(ArgumentError)
332
369
  end
333
370
 
334
371
  it "should set choice to empty array by default" do
335
- @meta.attribute("db/mysql/databases", {})
336
- @meta.attributes["db/mysql/databases"][:choice].should == []
372
+ metadata.attribute("db/mysql/databases", {})
373
+ metadata.attributes["db/mysql/databases"][:choice].should == []
337
374
  end
338
375
 
339
376
  it "should let calculated be true or false" do
340
377
  lambda {
341
- @meta.attribute("db/mysql/databases", :calculated => true)
378
+ metadata.attribute("db/mysql/databases", :calculated => true)
342
379
  }.should_not raise_error
343
380
  lambda {
344
- @meta.attribute("db/mysql/databases", :calculated => false)
381
+ metadata.attribute("db/mysql/databases", :calculated => false)
345
382
  }.should_not raise_error
346
383
  lambda {
347
- @meta.attribute("db/mysql/databases", :calculated => Hash.new)
384
+ metadata.attribute("db/mysql/databases", :calculated => Hash.new)
348
385
  }.should raise_error(ArgumentError)
349
386
  end
350
387
 
351
388
  it "should set calculated to false by default" do
352
- @meta.attribute("db/mysql/databases", {})
353
- @meta.attributes["db/mysql/databases"][:calculated].should == false
389
+ metadata.attribute("db/mysql/databases", {})
390
+ metadata.attributes["db/mysql/databases"][:calculated].should == false
354
391
  end
355
392
 
356
393
  it "accepts String for the attribute type" do
357
394
  lambda {
358
- @meta.attribute("db/mysql/databases", :type => "string")
395
+ metadata.attribute("db/mysql/databases", :type => "string")
359
396
  }.should_not raise_error
360
397
  end
361
398
 
362
399
  it "accepts Array for the attribute type" do
363
400
  lambda {
364
- @meta.attribute("db/mysql/databases", :type => "array")
401
+ metadata.attribute("db/mysql/databases", :type => "array")
365
402
  }.should_not raise_error
366
403
  lambda {
367
- @meta.attribute("db/mysql/databases", :type => Array.new)
404
+ metadata.attribute("db/mysql/databases", :type => Array.new)
368
405
  }.should raise_error(ArgumentError)
369
406
  end
370
407
 
371
408
  it "accepts symbol for the attribute type" do
372
409
  lambda {
373
- @meta.attribute("db/mysql/databases", :type => "symbol")
410
+ metadata.attribute("db/mysql/databases", :type => "symbol")
374
411
  }.should_not raise_error
375
412
  end
376
413
 
377
414
  it "should let type be hash (backwards compatability only)" do
378
415
  lambda {
379
- @meta.attribute("db/mysql/databases", :type => "hash")
416
+ metadata.attribute("db/mysql/databases", :type => "hash")
380
417
  }.should_not raise_error
381
418
  end
382
419
 
383
420
  it "should let required be required, recommended or optional" do
384
421
  lambda {
385
- @meta.attribute("db/mysql/databases", :required => 'required')
422
+ metadata.attribute("db/mysql/databases", :required => 'required')
386
423
  }.should_not raise_error
387
424
  lambda {
388
- @meta.attribute("db/mysql/databases", :required => 'recommended')
425
+ metadata.attribute("db/mysql/databases", :required => 'recommended')
389
426
  }.should_not raise_error
390
427
  lambda {
391
- @meta.attribute("db/mysql/databases", :required => 'optional')
428
+ metadata.attribute("db/mysql/databases", :required => 'optional')
392
429
  }.should_not raise_error
393
430
  end
394
431
 
395
432
  it "should convert required true to required" do
396
433
  lambda {
397
- @meta.attribute("db/mysql/databases", :required => true)
434
+ metadata.attribute("db/mysql/databases", :required => true)
398
435
  }.should_not raise_error
399
- #attrib = @meta.attributes["db/mysql/databases"][:required].should == "required"
436
+ #attrib = metadata.attributes["db/mysql/databases"][:required].should == "required"
400
437
  end
401
438
 
402
439
  it "should convert required false to optional" do
403
440
  lambda {
404
- @meta.attribute("db/mysql/databases", :required => false)
441
+ metadata.attribute("db/mysql/databases", :required => false)
405
442
  }.should_not raise_error
406
- #attrib = @meta.attributes["db/mysql/databases"][:required].should == "optional"
443
+ #attrib = metadata.attributes["db/mysql/databases"][:required].should == "optional"
407
444
  end
408
445
 
409
446
  it "should set required to 'optional' by default" do
410
- @meta.attribute("db/mysql/databases", {})
411
- @meta.attributes["db/mysql/databases"][:required].should == 'optional'
447
+ metadata.attribute("db/mysql/databases", {})
448
+ metadata.attributes["db/mysql/databases"][:required].should == 'optional'
412
449
  end
413
450
 
414
451
  it "should make sure recipes is an array" do
415
452
  lambda {
416
- @meta.attribute("db/mysql/databases", :recipes => [])
453
+ metadata.attribute("db/mysql/databases", :recipes => [])
417
454
  }.should_not raise_error
418
455
  lambda {
419
- @meta.attribute("db/mysql/databases", :required => Hash.new)
456
+ metadata.attribute("db/mysql/databases", :required => Hash.new)
420
457
  }.should raise_error(ArgumentError)
421
458
  end
422
459
 
423
460
  it "should set recipes to an empty array by default" do
424
- @meta.attribute("db/mysql/databases", {})
425
- @meta.attributes["db/mysql/databases"][:recipes].should == []
461
+ metadata.attribute("db/mysql/databases", {})
462
+ metadata.attributes["db/mysql/databases"][:recipes].should == []
426
463
  end
427
464
 
428
465
  it "should allow the default value to be a string, array, hash, boolean or numeric" do
429
466
  lambda {
430
- @meta.attribute("db/mysql/databases", :default => [])
467
+ metadata.attribute("db/mysql/databases", :default => [])
431
468
  }.should_not raise_error
432
469
  lambda {
433
- @meta.attribute("db/mysql/databases", :default => {})
470
+ metadata.attribute("db/mysql/databases", :default => {})
434
471
  }.should_not raise_error
435
472
  lambda {
436
- @meta.attribute("db/mysql/databases", :default => "alice in chains")
473
+ metadata.attribute("db/mysql/databases", :default => "alice in chains")
437
474
  }.should_not raise_error
438
475
  lambda {
439
- @meta.attribute("db/mysql/databases", :default => 1337)
476
+ metadata.attribute("db/mysql/databases", :default => 1337)
440
477
  }.should_not raise_error
441
478
  lambda {
442
- @meta.attribute("db/mysql/databases", :default => true)
479
+ metadata.attribute("db/mysql/databases", :default => true)
443
480
  }.should_not raise_error
444
481
  lambda {
445
- @meta.attribute("db/mysql/databases", :required => :not_gonna_do_it)
482
+ metadata.attribute("db/mysql/databases", :required => :not_gonna_do_it)
446
483
  }.should raise_error(ArgumentError)
447
484
  end
448
485
 
@@ -453,16 +490,16 @@ describe Chef::Cookbook::Metadata do
453
490
  :default => "test1"
454
491
  }
455
492
  lambda {
456
- @meta.attribute("test_cookbook/test", options)
493
+ metadata.attribute("test_cookbook/test", options)
457
494
  }.should_not raise_error
458
-
495
+
459
496
  options = {
460
497
  :type => "boolean",
461
498
  :choice => [ true, false ],
462
499
  :default => true
463
500
  }
464
501
  lambda {
465
- @meta.attribute("test_cookbook/test", options)
502
+ metadata.attribute("test_cookbook/test", options)
466
503
  }.should_not raise_error
467
504
 
468
505
  options = {
@@ -471,7 +508,7 @@ describe Chef::Cookbook::Metadata do
471
508
  :default => 1337
472
509
  }
473
510
  lambda {
474
- @meta.attribute("test_cookbook/test", options)
511
+ metadata.attribute("test_cookbook/test", options)
475
512
  }.should_not raise_error
476
513
 
477
514
  options = {
@@ -480,7 +517,7 @@ describe Chef::Cookbook::Metadata do
480
517
  :default => false
481
518
  }
482
519
  lambda {
483
- @meta.attribute("test_cookbook/test", options)
520
+ metadata.attribute("test_cookbook/test", options)
484
521
  }.should raise_error
485
522
  end
486
523
 
@@ -490,14 +527,14 @@ describe Chef::Cookbook::Metadata do
490
527
  :calculated => true,
491
528
  :default => [ "I thought you said calculated" ]
492
529
  }
493
- @meta.attribute("db/mysql/databases", attrs)
530
+ metadata.attribute("db/mysql/databases", attrs)
494
531
  }.should raise_error(ArgumentError)
495
532
  lambda {
496
533
  attrs = {
497
534
  :calculated => true,
498
535
  :default => "I thought you said calculated"
499
536
  }
500
- @meta.attribute("db/mysql/databases", attrs)
537
+ metadata.attribute("db/mysql/databases", attrs)
501
538
  }.should raise_error(ArgumentError)
502
539
  end
503
540
 
@@ -507,14 +544,14 @@ describe Chef::Cookbook::Metadata do
507
544
  :choice => [ "a", "b", "c"],
508
545
  :default => "b"
509
546
  }
510
- @meta.attribute("db/mysql/databases", attrs)
547
+ metadata.attribute("db/mysql/databases", attrs)
511
548
  }.should_not raise_error
512
549
  lambda {
513
550
  attrs = {
514
551
  :choice => [ "a", "b", "c", "d", "e"],
515
552
  :default => ["b", "d"]
516
553
  }
517
- @meta.attribute("db/mysql/databases", attrs)
554
+ metadata.attribute("db/mysql/databases", attrs)
518
555
  }.should_not raise_error
519
556
  end
520
557
 
@@ -524,71 +561,74 @@ describe Chef::Cookbook::Metadata do
524
561
  :choice => [ "a", "b", "c"],
525
562
  :default => "d"
526
563
  }
527
- @meta.attribute("db/mysql/databases", attrs)
564
+ metadata.attribute("db/mysql/databases", attrs)
528
565
  }.should raise_error(ArgumentError)
529
566
  lambda {
530
567
  attrs = {
531
568
  :choice => [ "a", "b", "c", "d", "e"],
532
569
  :default => ["b", "z"]
533
570
  }
534
- @meta.attribute("db/mysql/databases", attrs)
571
+ metadata.attribute("db/mysql/databases", attrs)
535
572
  }.should raise_error(ArgumentError)
536
573
  end
537
574
  end
538
575
 
539
576
  describe "recipes" do
577
+ let(:cookbook) do
578
+ c = Chef::CookbookVersion.new('test_cookbook')
579
+ c.recipe_files = [ "default.rb", "enlighten.rb" ]
580
+ c
581
+ end
582
+
540
583
  before(:each) do
541
- @cookbook.recipe_files = [ "default.rb", "enlighten.rb" ]
542
- @meta = Chef::Cookbook::Metadata.new(@cookbook)
584
+ metadata.name("test_cookbook")
585
+ metadata.recipes_from_cookbook_version(cookbook)
543
586
  end
544
587
 
545
588
  it "should have the names of the recipes" do
546
- @meta.recipes["test_cookbook"].should == ""
547
- @meta.recipes["test_cookbook::enlighten"].should == ""
589
+ metadata.recipes["test_cookbook"].should == ""
590
+ metadata.recipes["test_cookbook::enlighten"].should == ""
548
591
  end
549
592
 
550
593
  it "should let you set the description for a recipe" do
551
- @meta.recipe "test_cookbook", "It, um... tests stuff?"
552
- @meta.recipes["test_cookbook"].should == "It, um... tests stuff?"
594
+ metadata.recipe "test_cookbook", "It, um... tests stuff?"
595
+ metadata.recipes["test_cookbook"].should == "It, um... tests stuff?"
553
596
  end
554
597
 
555
598
  it "should automatically provide each recipe" do
556
- @meta.providing.has_key?("test_cookbook").should == true
557
- @meta.providing.has_key?("test_cookbook::enlighten").should == true
599
+ metadata.providing.has_key?("test_cookbook").should == true
600
+ metadata.providing.has_key?("test_cookbook::enlighten").should == true
558
601
  end
559
602
 
560
603
  end
561
604
 
562
605
  describe "json" do
563
606
  before(:each) do
564
- @cookbook.recipe_files = [ "default.rb", "enlighten.rb" ]
565
- @meta = Chef::Cookbook::Metadata.new(@cookbook)
566
- @meta.version "1.0"
567
- @meta.maintainer "Bobo T. Clown"
568
- @meta.maintainer_email "bobo@example.com"
569
- @meta.long_description "I have a long arm!"
570
- @meta.supports :ubuntu, "> 8.04"
571
- @meta.depends "bobo", "= 1.0"
572
- @meta.depends "bubu", "=1.0"
573
- @meta.depends "bobotclown", "= 1.1"
574
- @meta.recommends "snark", "< 3.0"
575
- @meta.suggests "kindness", "> 2.0"
576
- @meta.conflicts "hatred"
577
- @meta.provides "foo(:bar, :baz)"
578
- @meta.replaces "snarkitron"
579
- @meta.recipe "test_cookbook::enlighten", "is your buddy"
580
- @meta.attribute "bizspark/has_login",
607
+ metadata.version "1.0"
608
+ metadata.maintainer "Bobo T. Clown"
609
+ metadata.maintainer_email "bobo@example.com"
610
+ metadata.long_description "I have a long arm!"
611
+ metadata.supports :ubuntu, "> 8.04"
612
+ metadata.depends "bobo", "= 1.0"
613
+ metadata.depends "bubu", "=1.0"
614
+ metadata.depends "bobotclown", "= 1.1"
615
+ metadata.recommends "snark", "< 3.0"
616
+ metadata.suggests "kindness", "> 2.0"
617
+ metadata.conflicts "hatred"
618
+ metadata.provides "foo(:bar, :baz)"
619
+ metadata.replaces "snarkitron"
620
+ metadata.recipe "test_cookbook::enlighten", "is your buddy"
621
+ metadata.attribute "bizspark/has_login",
581
622
  :display_name => "You have nothing"
582
- @meta.version "1.2.3"
623
+ metadata.version "1.2.3"
583
624
  end
584
625
 
585
626
  describe "serialize" do
586
- before(:each) do
587
- @serial = Chef::JSONCompat.from_json(@meta.to_json)
588
- end
627
+
628
+ let(:deserialized_metadata) { Chef::JSONCompat.from_json(metadata.to_json) }
589
629
 
590
630
  it "should serialize to a json hash" do
591
- Chef::JSONCompat.from_json(@meta.to_json).should be_a_kind_of(Hash)
631
+ deserialized_metadata.should be_a_kind_of(Hash)
592
632
  end
593
633
 
594
634
  %w{
@@ -610,18 +650,18 @@ describe Chef::Cookbook::Metadata do
610
650
  version
611
651
  }.each do |t|
612
652
  it "should include '#{t}'" do
613
- @serial[t].should == @meta.send(t.to_sym)
653
+ deserialized_metadata[t].should == metadata.send(t.to_sym)
614
654
  end
615
655
  end
616
656
  end
617
657
 
618
658
  describe "deserialize" do
619
- before(:each) do
620
- @deserial = Chef::Cookbook::Metadata.from_json(@meta.to_json)
621
- end
659
+
660
+ let(:deserialized_metadata) { Chef::Cookbook::Metadata.from_json(metadata.to_json) }
661
+
622
662
 
623
663
  it "should deserialize to a Chef::Cookbook::Metadata object" do
624
- @deserial.should be_a_kind_of(Chef::Cookbook::Metadata)
664
+ deserialized_metadata.should be_a_kind_of(Chef::Cookbook::Metadata)
625
665
  end
626
666
 
627
667
  %w{
@@ -643,14 +683,14 @@ describe Chef::Cookbook::Metadata do
643
683
  version
644
684
  }.each do |t|
645
685
  it "should match '#{t}'" do
646
- @deserial.send(t.to_sym).should == @meta.send(t.to_sym)
686
+ deserialized_metadata.send(t.to_sym).should == metadata.send(t.to_sym)
647
687
  end
648
688
  end
649
689
  end
650
690
 
651
691
  describe "from_hash" do
652
692
  before(:each) do
653
- @hash = @meta.to_hash
693
+ @hash = metadata.to_hash
654
694
  end
655
695
 
656
696
  [:dependencies,