berkshelf 0.6.0.beta2 → 0.6.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +1 -2
  2. data/.travis.yml +7 -0
  3. data/Gemfile +1 -1
  4. data/README.md +1 -0
  5. data/Thorfile +7 -0
  6. data/berkshelf.gemspec +4 -1
  7. data/features/config.feature +97 -0
  8. data/features/config_command.feature +10 -0
  9. data/features/cookbook_command.feature +12 -12
  10. data/features/default_locations.feature +5 -0
  11. data/features/install.feature +16 -0
  12. data/features/json_formatter.feature +1 -1
  13. data/features/step_definitions/cli_steps.rb +5 -1
  14. data/features/step_definitions/filesystem_steps.rb +45 -23
  15. data/features/upload_command.feature +4 -4
  16. data/generator_files/Gemfile.erb +2 -2
  17. data/generator_files/Vagrantfile.erb +34 -13
  18. data/generator_files/config.json +22 -0
  19. data/lib/berkshelf/cli.rb +24 -9
  20. data/lib/berkshelf/config.rb +51 -0
  21. data/lib/berkshelf/config_generator.rb +8 -0
  22. data/lib/berkshelf/config_validator.rb +78 -0
  23. data/lib/berkshelf/cookbook_generator.rb +2 -2
  24. data/lib/berkshelf/core_ext/file_utils.rb +36 -0
  25. data/lib/berkshelf/downloader.rb +41 -14
  26. data/lib/berkshelf/errors.rb +20 -0
  27. data/lib/berkshelf/formatters/human_readable.rb +7 -0
  28. data/lib/berkshelf/git.rb +13 -3
  29. data/lib/berkshelf/init_generator.rb +17 -4
  30. data/lib/berkshelf/locations/chef_api_location.rb +1 -1
  31. data/lib/berkshelf/locations/git_location.rb +1 -1
  32. data/lib/berkshelf/locations/site_location.rb +1 -1
  33. data/lib/berkshelf/version.rb +1 -1
  34. data/lib/berkshelf.rb +17 -10
  35. data/spec/support/knife.rb +1 -1
  36. data/spec/support/matchers/file_system_matchers.rb +16 -1
  37. data/spec/unit/berkshelf/config_spec.rb +91 -0
  38. data/spec/unit/berkshelf/config_validator_spec.rb +68 -0
  39. data/spec/unit/berkshelf/cookbook_source_spec.rb +4 -4
  40. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +23 -0
  41. data/spec/unit/berkshelf/init_generator_spec.rb +34 -32
  42. data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +1 -1
  43. data/spec/unit/berkshelf/lockfile_spec.rb +2 -2
  44. data/spec/unit/berkshelf/resolver_spec.rb +1 -1
  45. data/spec/unit/berkshelf/uploader_spec.rb +1 -1
  46. metadata +68 -5
  47. data/lib/vagrant_init.rb +0 -2
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Berkshelf::ConfigValidator do
4
+ let(:config) { Berkshelf::Config.from_json json }
5
+ let(:config_validator) { klass.new Hash.new }
6
+ let(:json) { '{}' }
7
+ let(:klass) { described_class }
8
+ let(:structure) { Hash.new }
9
+
10
+ before :each do
11
+ klass.any_instance.stub structure: structure
12
+ end
13
+
14
+ describe "#validate" do
15
+ subject { config_validator.validate config }
16
+
17
+ it { should be_true }
18
+ it { config.should be_valid }
19
+
20
+ context "with a top-level key" do
21
+ let(:json) { '{ "a": 1 }' }
22
+ let(:structure) { { a: Object } }
23
+
24
+ it { should be_true }
25
+ it { config.should be_valid }
26
+ end
27
+
28
+ context "with a nested key" do
29
+ let(:json) { '{ "a": { "b": 1 } }' }
30
+ let(:structure) { { a: { b: Object } } }
31
+
32
+ it { should be_true }
33
+ it { config.should be_valid }
34
+ end
35
+
36
+ context "with a top-level nonsense key" do
37
+ let(:json) { '{ "nonsense": null }' }
38
+ let(:structure) { { a: Object } }
39
+
40
+ it { should be_false }
41
+ it { config.should_not be_valid }
42
+ end
43
+
44
+ context "with a nested nonsense key" do
45
+ let(:json) { '{ "a": { "nonsense": 1 } }' }
46
+ let(:structure) { { a: { b: Object } } }
47
+
48
+ it { should be_false }
49
+ it { config.should_not be_valid }
50
+ end
51
+
52
+ context "with a top-level key that doesn't match the expected type" do
53
+ let(:json) { '{ "a": 1 }' }
54
+ let(:structure) { { a: String } }
55
+
56
+ it { should be_false }
57
+ it { config.should_not be_valid }
58
+ end
59
+
60
+ context "with a nested key that doesn't match the expected type" do
61
+ let(:json) { '{ "a": { "b": 1 } }' }
62
+ let(:structure) { { a: { b: String } } }
63
+
64
+ it { should be_false }
65
+ it { config.should_not be_valid }
66
+ end
67
+ end
68
+ end
@@ -190,24 +190,24 @@ module Berkshelf
190
190
  describe '#add_group' do
191
191
  it "should store strings as symbols" do
192
192
  subject.add_group "foo"
193
- subject.groups.should == [:default, :foo]
193
+ subject.groups.should =~ [:default, :foo]
194
194
  end
195
195
 
196
196
  it "should not store duplicate groups" do
197
197
  subject.add_group "bar"
198
198
  subject.add_group "bar"
199
199
  subject.add_group :bar
200
- subject.groups.should == [:default, :bar]
200
+ subject.groups.should =~ [:default, :bar]
201
201
  end
202
202
 
203
203
  it "should add multiple groups" do
204
204
  subject.add_group "baz", "quux"
205
- subject.groups.should == [:default, :baz, :quux]
205
+ subject.groups.should =~ [:default, :baz, :quux]
206
206
  end
207
207
 
208
208
  it "should handle multiple groups as an array" do
209
209
  subject.add_group ["baz", "quux"]
210
- subject.groups.should == [:default, :baz, :quux]
210
+ subject.groups.should =~ [:default, :baz, :quux]
211
211
  end
212
212
  end
213
213
 
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe FileUtils do
4
+ describe "#mv" do
5
+ let(:src) { double('src') }
6
+ let(:dest) { double('dest') }
7
+ let(:options) { double('options') }
8
+
9
+ it "delegates to #safe_mv if on Windows" do
10
+ subject.stub(:windows?) { true }
11
+ FileUtils.should_receive(:safe_mv).with(src, dest, options)
12
+
13
+ FileUtils.mv(src, dest, options)
14
+ end
15
+
16
+ it "delegates to #old_mv if not on Windows" do
17
+ subject.stub(:windows?) { false }
18
+ FileUtils.should_receive(:old_mv).with(src, dest, options)
19
+
20
+ FileUtils.mv(src, dest, options)
21
+ end
22
+ end
23
+ end
@@ -14,9 +14,15 @@ module Berkshelf
14
14
 
15
15
  specify do
16
16
  target.should have_structure {
17
+ file ".gitignore"
17
18
  file "Berksfile"
18
19
  file "Gemfile" do
19
20
  contains "gem 'berkshelf'"
21
+ contains "gem 'vagrant'"
22
+ end
23
+ file "Vagrantfile" do
24
+ contains "require 'berkshelf/vagrant'"
25
+ contains "recipe[some_cookbook::default]"
20
26
  end
21
27
  no_file "chefignore"
22
28
  }
@@ -39,6 +45,8 @@ module Berkshelf
39
45
 
40
46
  context "with a metadata entry in the Berksfile" do
41
47
  before do
48
+ Dir.mkdir target
49
+ File.write target.join("metadata.rb"), ""
42
50
  generator = subject.new([target], metadata_entry: true)
43
51
  capture(:stdout) { generator.invoke_all }
44
52
  end
@@ -52,38 +60,6 @@ module Berkshelf
52
60
  end
53
61
  end
54
62
 
55
- context "with the vagrant option true" do
56
- before do
57
- generator = subject.new([target], vagrant: true)
58
- quietly { generator.invoke_all }
59
- end
60
-
61
- specify do
62
- target.should have_structure {
63
- file "Vagrantfile" do
64
- contains "require 'berkshelf/vagrant'"
65
- contains "recipe[some_cookbook::default]"
66
- end
67
- file "Gemfile" do
68
- contains "gem 'vagrant'"
69
- end
70
- }
71
- end
72
- end
73
-
74
- context "with the git option true" do
75
- before do
76
- generator = subject.new([target], git: true)
77
- capture(:stdout) { generator.invoke_all }
78
- end
79
-
80
- specify do
81
- target.should have_structure {
82
- file ".gitignore"
83
- }
84
- end
85
- end
86
-
87
63
  context "with the foodcritic option true" do
88
64
  before do
89
65
  generator = subject.new([target], foodcritic: true)
@@ -148,5 +124,31 @@ module Berkshelf
148
124
  generator.send(:cookbook_name).should eql("some_cookbook")
149
125
  end
150
126
  end
127
+
128
+ context "when skipping git" do
129
+ before do
130
+ generator = subject.new([target], skip_git: true)
131
+ capture(:stdout) { generator.invoke_all }
132
+ end
133
+
134
+ it "should not have a .git directory" do
135
+ target.should_not have_structure {
136
+ directory ".git"
137
+ }
138
+ end
139
+ end
140
+
141
+ context "when skipping vagrant" do
142
+ before do
143
+ generator = subject.new([target], skip_vagrant: true)
144
+ capture(:stdout) { generator.invoke_all }
145
+ end
146
+
147
+ it "should not have a Vagrantfile" do
148
+ target.should have_structure {
149
+ no_file "Vagrantfile"
150
+ }
151
+ end
152
+ end
151
153
  end
152
154
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Berkshelf
4
- describe ChefAPILocation do
4
+ describe ChefAPILocation, :chef_server do
5
5
  let(:test_chef_api) { "https://chefserver:8081" }
6
6
 
7
7
  describe "ClassMethods" do
@@ -21,9 +21,9 @@ module Berkshelf
21
21
 
22
22
  Lockfile.new(resolver.sources).write
23
23
 
24
- File.read('Berksfile.lock').split(/\r?\n/).sort.should == [
24
+ File.read('Berksfile.lock').split(/\r?\n/).should =~ [
25
25
  "cookbook 'bluepill', :locked_version => '1.1.0'",
26
- "cookbook 'build-essential', :locked_version => '1.1.0'",
26
+ "cookbook 'build-essential', :locked_version => '1.1.2'",
27
27
  "cookbook 'nginx', :locked_version => '0.101.0'",
28
28
  "cookbook 'ohai', :locked_version => '1.0.2'",
29
29
  "cookbook 'runit', :locked_version => '0.15.0'"
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Berkshelf
4
- describe Resolver do
4
+ describe Resolver, :chef_server do
5
5
  let(:source) do
6
6
  double('source',
7
7
  name: 'mysql',
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Berkshelf
4
- describe Uploader do
4
+ describe Uploader, :chef_server do
5
5
  subject { Uploader.new(server_url: Chef::Config[:chef_server_url], client_key: Chef::Config[:client_key], client_name: Chef::Config[:node_name]) }
6
6
 
7
7
  describe "#upload" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.beta2
4
+ version: 0.6.0.beta3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -12,8 +12,24 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-09-28 00:00:00.000000000 Z
15
+ date: 2012-10-29 00:00:00.000000000 Z
16
16
  dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: chozo
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 0.1.0
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.0
17
33
  - !ruby/object:Gem::Dependency
18
34
  name: ridley
19
35
  requirement: !ruby/object:Gem::Requirement
@@ -37,7 +53,7 @@ dependencies:
37
53
  requirements:
38
54
  - - ! '>='
39
55
  - !ruby/object:Gem::Version
40
- version: 0.3.0
56
+ version: 0.4.0.rc1
41
57
  type: :runtime
42
58
  prerelease: false
43
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -45,7 +61,7 @@ dependencies:
45
61
  requirements:
46
62
  - - ! '>='
47
63
  - !ruby/object:Gem::Version
48
- version: 0.3.0
64
+ version: 0.4.0.rc1
49
65
  - !ruby/object:Gem::Dependency
50
66
  name: chef
51
67
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +158,38 @@ dependencies:
142
158
  - - ! '>='
143
159
  - !ruby/object:Gem::Version
144
160
  version: '0'
161
+ - !ruby/object:Gem::Dependency
162
+ name: hashie
163
+ requirement: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ type: :runtime
170
+ prerelease: false
171
+ version_requirements: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ - !ruby/object:Gem::Dependency
178
+ name: activemodel
179
+ requirement: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ type: :runtime
186
+ prerelease: false
187
+ version_requirements: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
145
193
  - !ruby/object:Gem::Dependency
146
194
  name: redcarpet
147
195
  requirement: !ruby/object:Gem::Requirement
@@ -443,6 +491,7 @@ extra_rdoc_files: []
443
491
  files:
444
492
  - .gitignore
445
493
  - .rbenv-version
494
+ - .travis.yml
446
495
  - Gemfile
447
496
  - Guardfile
448
497
  - LICENSE
@@ -450,6 +499,8 @@ files:
450
499
  - Thorfile
451
500
  - berkshelf.gemspec
452
501
  - bin/berks
502
+ - features/config.feature
503
+ - features/config_command.feature
453
504
  - features/cookbook_command.feature
454
505
  - features/default_locations.feature
455
506
  - features/groups_install.feature
@@ -472,6 +523,7 @@ files:
472
523
  - generator_files/Thorfile.erb
473
524
  - generator_files/Vagrantfile.erb
474
525
  - generator_files/chefignore
526
+ - generator_files/config.json
475
527
  - generator_files/default_recipe.erb
476
528
  - generator_files/gitignore.erb
477
529
  - generator_files/licenses/apachev2.erb
@@ -485,11 +537,15 @@ files:
485
537
  - lib/berkshelf/berksfile.rb
486
538
  - lib/berkshelf/cached_cookbook.rb
487
539
  - lib/berkshelf/cli.rb
540
+ - lib/berkshelf/config.rb
541
+ - lib/berkshelf/config_generator.rb
542
+ - lib/berkshelf/config_validator.rb
488
543
  - lib/berkshelf/cookbook_generator.rb
489
544
  - lib/berkshelf/cookbook_source.rb
490
545
  - lib/berkshelf/cookbook_store.rb
491
546
  - lib/berkshelf/core_ext.rb
492
547
  - lib/berkshelf/core_ext/file.rb
548
+ - lib/berkshelf/core_ext/file_utils.rb
493
549
  - lib/berkshelf/core_ext/pathname.rb
494
550
  - lib/berkshelf/core_ext/string.rb
495
551
  - lib/berkshelf/downloader.rb
@@ -520,7 +576,6 @@ files:
520
576
  - lib/berkshelf/version.rb
521
577
  - lib/thor/monkies.rb
522
578
  - lib/thor/monkies/hash_with_indifferent_access.rb
523
- - lib/vagrant_init.rb
524
579
  - spec/fixtures/Berksfile
525
580
  - spec/fixtures/cookbooks/example_cookbook-0.5.0/README.md
526
581
  - spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb
@@ -555,9 +610,12 @@ files:
555
610
  - spec/support/matchers/filepath_matchers.rb
556
611
  - spec/unit/berkshelf/berksfile_spec.rb
557
612
  - spec/unit/berkshelf/cached_cookbook_spec.rb
613
+ - spec/unit/berkshelf/config_spec.rb
614
+ - spec/unit/berkshelf/config_validator_spec.rb
558
615
  - spec/unit/berkshelf/cookbook_generator_spec.rb
559
616
  - spec/unit/berkshelf/cookbook_source_spec.rb
560
617
  - spec/unit/berkshelf/cookbook_store_spec.rb
618
+ - spec/unit/berkshelf/core_ext/file_utils_spec.rb
561
619
  - spec/unit/berkshelf/downloader_spec.rb
562
620
  - spec/unit/berkshelf/formatters_spec.rb
563
621
  - spec/unit/berkshelf/git_spec.rb
@@ -596,6 +654,8 @@ signing_key:
596
654
  specification_version: 3
597
655
  summary: Manages a Cookbook's, or an Application's, Cookbook dependencies
598
656
  test_files:
657
+ - features/config.feature
658
+ - features/config_command.feature
599
659
  - features/cookbook_command.feature
600
660
  - features/default_locations.feature
601
661
  - features/groups_install.feature
@@ -646,9 +706,12 @@ test_files:
646
706
  - spec/support/matchers/filepath_matchers.rb
647
707
  - spec/unit/berkshelf/berksfile_spec.rb
648
708
  - spec/unit/berkshelf/cached_cookbook_spec.rb
709
+ - spec/unit/berkshelf/config_spec.rb
710
+ - spec/unit/berkshelf/config_validator_spec.rb
649
711
  - spec/unit/berkshelf/cookbook_generator_spec.rb
650
712
  - spec/unit/berkshelf/cookbook_source_spec.rb
651
713
  - spec/unit/berkshelf/cookbook_store_spec.rb
714
+ - spec/unit/berkshelf/core_ext/file_utils_spec.rb
652
715
  - spec/unit/berkshelf/downloader_spec.rb
653
716
  - spec/unit/berkshelf/formatters_spec.rb
654
717
  - spec/unit/berkshelf/git_spec.rb
data/lib/vagrant_init.rb DELETED
@@ -1,2 +0,0 @@
1
- # This file is automatically loaded by Vagrant
2
- require 'berkshelf/vagrant'