ridley 0.7.0.rc4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ require 'pathname'
2
+
3
+ RSpec::Matchers.define :be_relative_path do
4
+ match do |given|
5
+ if given.nil?
6
+ false
7
+ else
8
+ Pathname.new(given).relative?
9
+ end
10
+ end
11
+
12
+ failure_message_for_should do |given|
13
+ "Expected '#{given}' to be a relative path but got an absolute path."
14
+ end
15
+
16
+ failure_message_for_should_not do |given|
17
+ "Expected '#{given}' to not be a relative path but got an absolute path."
18
+ end
19
+ end
@@ -0,0 +1,412 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ridley::Chef::Cookbook do
4
+ describe "ClassMethods" do
5
+ subject { described_class }
6
+
7
+ describe "#from_path" do
8
+ let(:cookbook_path) { fixtures_path.join("example_cookbook") }
9
+
10
+ it "returns an instance of Ridley::Chef::Cookbook" do
11
+ subject.from_path(cookbook_path).should be_a(described_class)
12
+ end
13
+
14
+ it "has a cookbook_name attribute set to the value of the 'name' attribute in the metadata" do
15
+ subject.from_path(cookbook_path).cookbook_name.should eql("example_cookbook")
16
+ end
17
+
18
+ it "sets the cookbook_name attribute to the value of the :name option if given" do
19
+ subject.from_path(cookbook_path, name: "rspec_tester").cookbook_name.should eql("rspec_tester")
20
+ end
21
+
22
+ context "given a path that does not contain a metadata file" do
23
+ it "raises an IOError" do
24
+ lambda {
25
+ subject.from_path(Dir.mktmpdir)
26
+ }.should raise_error(IOError)
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#checksum" do
32
+ it "delegates to Ridley::Chef::Digester.md5_checksum_for_file" do
33
+ path = fixtures_path.join("example_cookbook", "metadata.rb")
34
+ Ridley::Chef::Digester.should_receive(:md5_checksum_for_file).with(path)
35
+
36
+ subject.checksum(path)
37
+ end
38
+ end
39
+ end
40
+
41
+ let(:cookbook) do
42
+ described_class.from_path(fixtures_path.join('example_cookbook'))
43
+ end
44
+
45
+ subject { cookbook }
46
+
47
+ describe "#checksums" do
48
+ it "returns a Hash" do
49
+ subject.checksums.should be_a(Hash)
50
+ end
51
+
52
+ it "has a key value for every cookbook file" do
53
+ subject.checksums.should have(subject.send(:files).length).items
54
+ end
55
+ end
56
+
57
+ describe "#manifest" do
58
+ it "returns a Mash with a key for each cookbook file category" do
59
+ [
60
+ :recipes,
61
+ :definitions,
62
+ :libraries,
63
+ :attributes,
64
+ :files,
65
+ :templates,
66
+ :resources,
67
+ :providers,
68
+ :root_files
69
+ ].each do |category|
70
+ subject.manifest.should have_key(category)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "#validate" do
76
+ let(:syntax_checker) { double('syntax_checker') }
77
+
78
+ before(:each) do
79
+ subject.stub(:syntax_checker) { syntax_checker }
80
+ end
81
+
82
+ it "asks the syntax_checker to validate the ruby and template files of the cookbook" do
83
+ syntax_checker.should_receive(:validate_ruby_files).and_return(true)
84
+ syntax_checker.should_receive(:validate_templates).and_return(true)
85
+
86
+ subject.validate
87
+ end
88
+
89
+ it "raises CookbookSyntaxError if the cookbook contains invalid ruby files" do
90
+ syntax_checker.should_receive(:validate_ruby_files).and_return(false)
91
+
92
+ lambda {
93
+ subject.validate
94
+ }.should raise_error(Ridley::Errors::CookbookSyntaxError)
95
+ end
96
+
97
+ it "raises CookbookSyntaxError if the cookbook contains invalid template files" do
98
+ syntax_checker.should_receive(:validate_ruby_files).and_return(true)
99
+ syntax_checker.should_receive(:validate_templates).and_return(false)
100
+
101
+ lambda {
102
+ subject.validate
103
+ }.should raise_error(Ridley::Errors::CookbookSyntaxError)
104
+ end
105
+ end
106
+
107
+ describe "#file_metadata" do
108
+ let(:file) { subject.path.join("files", "default", "file.h") }
109
+ before(:each) { @metadata = subject.file_metadata(:file, file) }
110
+
111
+ it "has a :path key whose value is a relative path from the CachedCookbook's path" do
112
+ @metadata.should have_key(:path)
113
+ @metadata[:path].should be_relative_path
114
+ @metadata[:path].should eql("files/default/file.h")
115
+ end
116
+
117
+ it "has a :name key whose value is the basename of the target file" do
118
+ @metadata.should have_key(:name)
119
+ @metadata[:name].should eql("file.h")
120
+ end
121
+
122
+ it "has a :checksum key whose value is the checksum of the target file" do
123
+ @metadata.should have_key(:checksum)
124
+ @metadata[:checksum].should eql("7b1ebd2ff580ca9dc46fb27ec1653bf2")
125
+ end
126
+
127
+ it "has a :specificity key" do
128
+ @metadata.should have_key(:specificity)
129
+ end
130
+
131
+ context "given a file or template in a 'default' directory" do
132
+ let(:file) { subject.path.join("files", "default", "file.h") }
133
+ before(:each) { @metadata = subject.file_metadata(:files, file) }
134
+
135
+ it "has a specificity of 'default'" do
136
+ @metadata[:specificity].should eql("default")
137
+ end
138
+ end
139
+
140
+ context "given a file or template in a 'ubuntu' directory" do
141
+ let(:file) { subject.path.join("files", "ubuntu", "file.h") }
142
+ before(:each) { @metadata = subject.file_metadata(:files, file) }
143
+
144
+ it "has a specificity of 'ubuntu'" do
145
+ @metadata[:specificity].should eql("ubuntu")
146
+ end
147
+ end
148
+ end
149
+
150
+ describe "#to_hash" do
151
+ subject { cookbook.to_hash }
152
+
153
+ it "has a :recipes key with a value of an Array Hashes" do
154
+ subject.should have_key(:recipes)
155
+ subject[:recipes].should be_a(Array)
156
+ subject[:recipes].each do |item|
157
+ item.should be_a(Hash)
158
+ end
159
+ end
160
+
161
+ it "has a :name key value pair in a Hash of the :recipes Array of Hashes" do
162
+ subject[:recipes].first.should have_key(:name)
163
+ end
164
+
165
+ it "has a :path key value pair in a Hash of the :recipes Array of Hashes" do
166
+ subject[:recipes].first.should have_key(:path)
167
+ end
168
+
169
+ it "has a :checksum key value pair in a Hash of the :recipes Array of Hashes" do
170
+ subject[:recipes].first.should have_key(:checksum)
171
+ end
172
+
173
+ it "has a :specificity key value pair in a Hash of the :recipes Array of Hashes" do
174
+ subject[:recipes].first.should have_key(:specificity)
175
+ end
176
+
177
+ it "has a :definitions key with a value of an Array Hashes" do
178
+ subject.should have_key(:definitions)
179
+ subject[:definitions].should be_a(Array)
180
+ subject[:definitions].each do |item|
181
+ item.should be_a(Hash)
182
+ end
183
+ end
184
+
185
+ it "has a :name key value pair in a Hash of the :definitions Array of Hashes" do
186
+ subject[:definitions].first.should have_key(:name)
187
+ end
188
+
189
+ it "has a :path key value pair in a Hash of the :definitions Array of Hashes" do
190
+ subject[:definitions].first.should have_key(:path)
191
+ end
192
+
193
+ it "has a :checksum key value pair in a Hash of the :definitions Array of Hashes" do
194
+ subject[:definitions].first.should have_key(:checksum)
195
+ end
196
+
197
+ it "has a :specificity key value pair in a Hash of the :definitions Array of Hashes" do
198
+ subject[:definitions].first.should have_key(:specificity)
199
+ end
200
+
201
+ it "has a :libraries key with a value of an Array Hashes" do
202
+ subject.should have_key(:libraries)
203
+ subject[:libraries].should be_a(Array)
204
+ subject[:libraries].each do |item|
205
+ item.should be_a(Hash)
206
+ end
207
+ end
208
+
209
+ it "has a :name key value pair in a Hash of the :libraries Array of Hashes" do
210
+ subject[:libraries].first.should have_key(:name)
211
+ end
212
+
213
+ it "has a :path key value pair in a Hash of the :libraries Array of Hashes" do
214
+ subject[:libraries].first.should have_key(:path)
215
+ end
216
+
217
+ it "has a :checksum key value pair in a Hash of the :libraries Array of Hashes" do
218
+ subject[:libraries].first.should have_key(:checksum)
219
+ end
220
+
221
+ it "has a :specificity key value pair in a Hash of the :libraries Array of Hashes" do
222
+ subject[:libraries].first.should have_key(:specificity)
223
+ end
224
+
225
+ it "has a :attributes key with a value of an Array Hashes" do
226
+ subject.should have_key(:attributes)
227
+ subject[:attributes].should be_a(Array)
228
+ subject[:attributes].each do |item|
229
+ item.should be_a(Hash)
230
+ end
231
+ end
232
+
233
+ it "has a :name key value pair in a Hash of the :attributes Array of Hashes" do
234
+ subject[:attributes].first.should have_key(:name)
235
+ end
236
+
237
+ it "has a :path key value pair in a Hash of the :attributes Array of Hashes" do
238
+ subject[:attributes].first.should have_key(:path)
239
+ end
240
+
241
+ it "has a :checksum key value pair in a Hash of the :attributes Array of Hashes" do
242
+ subject[:attributes].first.should have_key(:checksum)
243
+ end
244
+
245
+ it "has a :specificity key value pair in a Hash of the :attributes Array of Hashes" do
246
+ subject[:attributes].first.should have_key(:specificity)
247
+ end
248
+
249
+ it "has a :files key with a value of an Array Hashes" do
250
+ subject.should have_key(:files)
251
+ subject[:files].should be_a(Array)
252
+ subject[:files].each do |item|
253
+ item.should be_a(Hash)
254
+ end
255
+ end
256
+
257
+ it "has a :name key value pair in a Hash of the :files Array of Hashes" do
258
+ subject[:files].first.should have_key(:name)
259
+ end
260
+
261
+ it "has a :path key value pair in a Hash of the :files Array of Hashes" do
262
+ subject[:files].first.should have_key(:path)
263
+ end
264
+
265
+ it "has a :checksum key value pair in a Hash of the :files Array of Hashes" do
266
+ subject[:files].first.should have_key(:checksum)
267
+ end
268
+
269
+ it "has a :specificity key value pair in a Hash of the :files Array of Hashes" do
270
+ subject[:files].first.should have_key(:specificity)
271
+ end
272
+
273
+ it "has a :templates key with a value of an Array Hashes" do
274
+ subject.should have_key(:templates)
275
+ subject[:templates].should be_a(Array)
276
+ subject[:templates].each do |item|
277
+ item.should be_a(Hash)
278
+ end
279
+ end
280
+
281
+ it "has a :name key value pair in a Hash of the :templates Array of Hashes" do
282
+ subject[:templates].first.should have_key(:name)
283
+ end
284
+
285
+ it "has a :path key value pair in a Hash of the :templates Array of Hashes" do
286
+ subject[:templates].first.should have_key(:path)
287
+ end
288
+
289
+ it "has a :checksum key value pair in a Hash of the :templates Array of Hashes" do
290
+ subject[:templates].first.should have_key(:checksum)
291
+ end
292
+
293
+ it "has a :specificity key value pair in a Hash of the :templates Array of Hashes" do
294
+ subject[:templates].first.should have_key(:specificity)
295
+ end
296
+
297
+ it "has a :resources key with a value of an Array Hashes" do
298
+ subject.should have_key(:resources)
299
+ subject[:resources].should be_a(Array)
300
+ subject[:resources].each do |item|
301
+ item.should be_a(Hash)
302
+ end
303
+ end
304
+
305
+ it "has a :name key value pair in a Hash of the :resources Array of Hashes" do
306
+ subject[:resources].first.should have_key(:name)
307
+ end
308
+
309
+ it "has a :path key value pair in a Hash of the :resources Array of Hashes" do
310
+ subject[:resources].first.should have_key(:path)
311
+ end
312
+
313
+ it "has a :checksum key value pair in a Hash of the :resources Array of Hashes" do
314
+ subject[:resources].first.should have_key(:checksum)
315
+ end
316
+
317
+ it "has a :specificity key value pair in a Hash of the :resources Array of Hashes" do
318
+ subject[:resources].first.should have_key(:specificity)
319
+ end
320
+
321
+ it "has a :providers key with a value of an Array Hashes" do
322
+ subject.should have_key(:providers)
323
+ subject[:providers].should be_a(Array)
324
+ subject[:providers].each do |item|
325
+ item.should be_a(Hash)
326
+ end
327
+ end
328
+
329
+ it "has a :name key value pair in a Hash of the :providers Array of Hashes" do
330
+ subject[:providers].first.should have_key(:name)
331
+ end
332
+
333
+ it "has a :path key value pair in a Hash of the :providers Array of Hashes" do
334
+ subject[:providers].first.should have_key(:path)
335
+ end
336
+
337
+ it "has a :checksum key value pair in a Hash of the :providers Array of Hashes" do
338
+ subject[:providers].first.should have_key(:checksum)
339
+ end
340
+
341
+ it "has a :specificity key value pair in a Hash of the :providers Array of Hashes" do
342
+ subject[:providers].first.should have_key(:specificity)
343
+ end
344
+
345
+ it "has a :root_files key with a value of an Array Hashes" do
346
+ subject.should have_key(:root_files)
347
+ subject[:root_files].should be_a(Array)
348
+ subject[:root_files].each do |item|
349
+ item.should be_a(Hash)
350
+ end
351
+ end
352
+
353
+ it "has a :name key value pair in a Hash of the :root_files Array of Hashes" do
354
+ subject[:root_files].first.should have_key(:name)
355
+ end
356
+
357
+ it "has a :path key value pair in a Hash of the :root_files Array of Hashes" do
358
+ subject[:root_files].first.should have_key(:path)
359
+ end
360
+
361
+ it "has a :checksum key value pair in a Hash of the :root_files Array of Hashes" do
362
+ subject[:root_files].first.should have_key(:checksum)
363
+ end
364
+
365
+ it "has a :specificity key value pair in a Hash of the :root_files Array of Hashes" do
366
+ subject[:root_files].first.should have_key(:specificity)
367
+ end
368
+
369
+ it "has a :cookbook_name key with a String value" do
370
+ subject.should have_key(:cookbook_name)
371
+ subject[:cookbook_name].should be_a(String)
372
+ end
373
+
374
+ it "has a :metadata key with a Cookbook::Metadata value" do
375
+ subject.should have_key(:metadata)
376
+ subject[:metadata].should be_a(Ridley::Chef::Cookbook::Metadata)
377
+ end
378
+
379
+ it "has a :version key with a String value" do
380
+ subject.should have_key(:version)
381
+ subject[:version].should be_a(String)
382
+ end
383
+
384
+ it "has a :name key with a String value" do
385
+ subject.should have_key(:name)
386
+ subject[:name].should be_a(String)
387
+ end
388
+
389
+ it "has a value containing the cookbook name and version separated by a dash for :name" do
390
+ name, version = subject[:name].split('-')
391
+
392
+ name.should eql(cookbook.cookbook_name)
393
+ version.should eql(cookbook.version)
394
+ end
395
+
396
+ it "has a :chef_type key with Cookbook::CHEF_TYPE as the value" do
397
+ subject.should have_key(:chef_type)
398
+ subject[:chef_type].should eql(Ridley::Chef::Cookbook::CHEF_TYPE)
399
+ end
400
+ end
401
+
402
+ describe "#to_json" do
403
+ before(:each) do
404
+ @json = subject.to_json
405
+ end
406
+
407
+ it "has a 'json_class' key with Cookbook::CHEF_JSON_CLASS as the value" do
408
+ @json.should have_json_path('json_class')
409
+ parse_json(@json)['json_class'].should eql(Ridley::Chef::Cookbook::CHEF_JSON_CLASS)
410
+ end
411
+ end
412
+ end
@@ -8,7 +8,7 @@ describe Ridley::Resource do
8
8
  Class.new(Ridley::Resource)
9
9
  end
10
10
 
11
- it_behaves_like "a Ridley Resource", subject.call
11
+ it_behaves_like "a Ridley Resource", Class.new(Ridley::Resource)
12
12
 
13
13
  describe "::initialize" do
14
14
  it "mass assigns the given attributes" do
@@ -211,7 +211,7 @@ describe Ridley::CookbookResource do
211
211
  end
212
212
 
213
213
  describe "#download_file" do
214
- let(:destination) { tmp_path.join('fake.file') }
214
+ let(:destination) { tmp_path.join('fake.file').to_s }
215
215
 
216
216
  before(:each) do
217
217
  subject.stub(:root_files) { [ { name: 'metadata.rb', url: "http://test.it/file" } ] }