chef-sugar 1.1.0 → 1.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/LICENSE +1 -1
  4. data/README.md +91 -1
  5. data/Rakefile +6 -0
  6. data/chef-extensions.gemspec +3 -6
  7. data/lib/chef/sugar.rb +5 -1
  8. data/lib/chef/sugar/architecture.rb +1 -1
  9. data/lib/chef/sugar/cloud.rb +1 -1
  10. data/lib/chef/sugar/constraints.rb +161 -0
  11. data/lib/chef/sugar/core_extensions.rb +18 -0
  12. data/lib/chef/sugar/core_extensions/array.rb +34 -0
  13. data/lib/chef/sugar/core_extensions/string.rb +49 -0
  14. data/lib/chef/sugar/data_bag.rb +34 -9
  15. data/lib/chef/sugar/ip.rb +1 -1
  16. data/lib/chef/sugar/kernel.rb +49 -0
  17. data/lib/chef/sugar/node.rb +157 -1
  18. data/lib/chef/sugar/platform.rb +1 -1
  19. data/lib/chef/sugar/platform_family.rb +1 -1
  20. data/lib/chef/sugar/ruby.rb +1 -1
  21. data/lib/chef/sugar/shell.rb +1 -1
  22. data/lib/chef/sugar/vagrant.rb +1 -1
  23. data/lib/chef/sugar/version.rb +2 -2
  24. data/metadata.rb +1 -1
  25. data/recipes/default.rb +2 -2
  26. data/spec/spec_helper.rb +3 -0
  27. data/spec/support/shared_examples.rb +1 -1
  28. data/spec/unit/chef/{extensions → sugar}/architecture_spec.rb +0 -0
  29. data/spec/unit/chef/{extensions → sugar}/cloud_spec.rb +0 -0
  30. data/spec/unit/chef/sugar/constraints_spec.rb +43 -0
  31. data/spec/unit/chef/sugar/core_extensions/array_spec.rb +10 -0
  32. data/spec/unit/chef/sugar/core_extensions/string_spec.rb +16 -0
  33. data/spec/unit/chef/{extensions → sugar}/data_bag_spec.rb +23 -4
  34. data/spec/unit/chef/{extensions → sugar}/ip_spec.rb +0 -0
  35. data/spec/unit/chef/sugar/kernel_spec.rb +16 -0
  36. data/spec/unit/chef/sugar/node_spec.rb +117 -0
  37. data/spec/unit/chef/{extensions → sugar}/platform_family_spec.rb +0 -0
  38. data/spec/unit/chef/{extensions → sugar}/platform_spec.rb +0 -0
  39. data/spec/unit/chef/{extensions → sugar}/ruby_spec.rb +0 -0
  40. data/spec/unit/chef/{extensions → sugar}/shell_spec.rb +0 -0
  41. data/spec/unit/chef/{extensions → sugar}/vagrant_spec.rb +0 -0
  42. metadata +45 -61
  43. data/.kitchen.yml +0 -16
  44. data/recipes/development.rb +0 -65
  45. data/spec/unit/chef/extensions/node_spec.rb +0 -30
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'rspec'
2
5
  require 'chefspec'
3
6
  require 'chef/sugar'
@@ -8,7 +8,7 @@ module RSpec
8
8
 
9
9
  described_class.instance_methods.each do |name|
10
10
  it "defines a `#{name}` DSL method" do
11
- expect(Chef::Sugar::DSL.instance_methods).to include(name)
11
+ expect(Chef::Sugar::DSL).to be_method_defined(name)
12
12
  end
13
13
 
14
14
  it 'has n-1 arity from the parent method' do
File without changes
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Constraints do
4
+ # it_behaves_like 'a chef sugar'
5
+
6
+ describe '#version' do
7
+ let(:version) { described_class.version('1.2.3') }
8
+
9
+ it 'returns a new version object' do
10
+ expect(version).to be_a(Chef::Sugar::Constraints::Version)
11
+ end
12
+
13
+ it 'returns true with the version is satisifed' do
14
+ expect(version).to be_satisfies('~> 1.2.0')
15
+ end
16
+
17
+ it 'returns false when the version is not satisfed' do
18
+ expect(version).to_not be_satisfies('~> 2.0.0')
19
+ end
20
+ end
21
+
22
+ describe '#constraint' do
23
+ let(:constraint) { described_class.constraint('~> 1.2.0') }
24
+
25
+ it 'returns a new constraint object' do
26
+ expect(constraint).to be_a(Chef::Sugar::Constraints::Constraint)
27
+ end
28
+
29
+ it 'returns true when the constraint is satisfied' do
30
+ expect(constraint).to be_satisfied_by('1.2.3')
31
+ end
32
+
33
+ it 'returns false when the constraint is not satisfied' do
34
+ expect(constraint).to_not be_satisfied_by('2.0.0')
35
+ end
36
+ end
37
+
38
+ describe '#chef_version' do
39
+ it 'is a DSL method' do
40
+ expect(Chef::Sugar::DSL).to be_method_defined(:chef_version)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'chef/sugar/core_extensions'
3
+
4
+ describe Array do
5
+ describe '#satisfied_by?' do
6
+ it 'includes the method' do
7
+ expect(described_class).to be_method_defined(:satisfied_by?)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'chef/sugar/core_extensions'
3
+
4
+ describe String do
5
+ describe '#satisfies?' do
6
+ it 'includes the method' do
7
+ expect(described_class).to be_method_defined(:satisfies?)
8
+ end
9
+ end
10
+
11
+ describe '#satisfied_by?' do
12
+ it 'includes the method' do
13
+ expect(described_class).to be_method_defined(:satisfied_by?)
14
+ end
15
+ end
16
+ end
@@ -6,9 +6,28 @@ describe Chef::Sugar::DataBag do
6
6
 
7
7
  it 'loads the encrypted data bag item' do
8
8
  expect(Chef::EncryptedDataBagItem).to receive(:load)
9
- .with('accounts', 'github')
9
+ .with('accounts', 'github', 'secret_key')
10
10
 
11
- described_class.encrypted_data_bag_item('accounts', 'github')
11
+ described_class.encrypted_data_bag_item('accounts', 'github', 'secret_key')
12
+ end
13
+
14
+ context 'when Chef::Config is set' do
15
+ it 'loads the secret key from the Chef::Config' do
16
+ Chef::Config.stub(:[]).with(:encrypted_data_bag_secret).and_return('B@c0n')
17
+
18
+ expect(Chef::EncryptedDataBagItem).to receive(:load)
19
+ .with('accounts', 'github', 'B@c0n')
20
+
21
+ described_class.encrypted_data_bag_item('accounts', 'github')
22
+ end
23
+ end
24
+
25
+ context 'when Chef::Config is not set and no value is given' do
26
+ it 'raises an exception' do
27
+ expect {
28
+ described_class.encrypted_data_bag_item('accounts', 'github')
29
+ }.to raise_error(Chef::Sugar::DataBag::EncryptedDataBagSecretNotGiven)
30
+ end
12
31
  end
13
32
  end
14
33
 
@@ -24,7 +43,7 @@ describe Chef::Sugar::DataBag do
24
43
  }
25
44
  )
26
45
 
27
- expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
46
+ expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github', 'secret_key')).to eq(
28
47
  'password' => 'bacon',
29
48
  'username' => 'sethvargo',
30
49
  )
@@ -44,7 +63,7 @@ describe Chef::Sugar::DataBag do
44
63
  }
45
64
  )
46
65
 
47
- expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
66
+ expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github', 'secret_key')).to eq(
48
67
  'password' => 'ham',
49
68
  'username' => 'schisamo',
50
69
  )
File without changes
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Sugar::Kernel do
4
+ describe '.require_chef_gem' do
5
+ it 'raises an exception when the gem is not installed' do
6
+ expect {
7
+ described_class.require_chef_gem('bacon')
8
+ }.to raise_error(Chef::Sugar::Kernel::ChefGemLoadError)
9
+ end
10
+
11
+ it 'loads the gem' do
12
+ Chef::Sugar::Kernel.stub(:require).and_return(true)
13
+ expect(described_class.require_chef_gem('bacon')).to be_true
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chef::Node do
4
+ describe '#in?' do
5
+ it 'returns true when the node is in the environment' do
6
+ subject.stub(:chef_environment).and_return('production')
7
+ expect(subject.in?('production')).to be_true
8
+ expect(subject.in?(/production$/)).to be_true
9
+ end
10
+
11
+ it 'returns false when the node is not in the environment' do
12
+ subject.stub(:chef_environment).and_return('staging')
13
+ expect(subject.in?('production')).to be_false
14
+ expect(subject.in?(/production$/)).to be_false
15
+ end
16
+ end
17
+
18
+ describe '#includes_recipe?' do
19
+ it 'returns true when the recipe exists' do
20
+ subject.stub(:run_list).and_return(['recipe[magic::recipe]'])
21
+ expect(subject.includes_recipe?('recipe[magic::recipe]')).to be_true
22
+ end
23
+
24
+ it 'returns false when the recipe does
25
+ not exist' do
26
+ subject.stub(:run_list).and_return([])
27
+ expect(subject.includes_recipe?('recipe[magic::recipe]')).to be_false
28
+ end
29
+ end
30
+
31
+ describe '#deep_fetch' do
32
+ let(:node) { described_class.new }
33
+ before { node.default['apache2']['config']['root'] = '/var/www' }
34
+
35
+ it 'fetches a deeply nested attribute' do
36
+ expect(node.deep_fetch('apache2', 'config', 'root')).to eq('/var/www')
37
+ end
38
+
39
+ it 'ignores symbols, strings, etc' do
40
+ expect(node.deep_fetch(:apache2, :config, :root)).to eq('/var/www')
41
+ end
42
+
43
+ it 'safely returns nil if a key does not exist' do
44
+ expect(node.deep_fetch(:apache2, :not_real, :nested, :yup)).to be_nil
45
+ end
46
+ end
47
+
48
+ describe '#deep_fetch!' do
49
+ let(:node) { described_class.new }
50
+ before { node.default['apache2']['config']['root'] = '/var/www' }
51
+
52
+ it 'fetches a deeply nested attribute' do
53
+ expect(node.deep_fetch!('apache2', 'config', 'root')).to eq('/var/www')
54
+ end
55
+
56
+ it 'ignores symbols, strings, etc' do
57
+ expect(node.deep_fetch!(:apache2, :config, :root)).to eq('/var/www')
58
+ end
59
+
60
+ it 'raises an error if a key does not exist' do
61
+ expect {
62
+ node.deep_fetch!(:apache2, :not_real, :nested, :yup)
63
+ }.to raise_error(Chef::Node::AttributeDoesNotExistError)
64
+ end
65
+ end
66
+
67
+ describe '#namespace' do
68
+ let(:node) { described_class.new }
69
+
70
+ it 'defines the attributes' do
71
+ node.instance_eval do
72
+ namespace 'apache2' do
73
+ namespace 'config' do
74
+ root '/var/www'
75
+ end
76
+ end
77
+ end
78
+
79
+ expect(node.default).to eq({
80
+ 'apache2' => {
81
+ 'config' => { 'root' => '/var/www' }
82
+ }
83
+ })
84
+ end
85
+
86
+ it 'accepts multiple attributes' do
87
+ node.instance_eval do
88
+ namespace 'apache2', 'config' do
89
+ root '/var/www'
90
+ end
91
+ end
92
+
93
+ expect(node.default).to eq({
94
+ 'apache2' => {
95
+ 'config' => { 'root' => '/var/www' }
96
+ }
97
+ })
98
+ end
99
+
100
+ it 'accepts attribute precedence levels' do
101
+ node.instance_eval do
102
+ namespace 'apache2', precedence: normal do
103
+ namespace 'config', precedence: override do
104
+ root '/var/www'
105
+ end
106
+ end
107
+ end
108
+
109
+ expect(node.override).to eq({
110
+ 'apache2' => {
111
+ 'config' => { 'root' => '/var/www' }
112
+ }
113
+ })
114
+ end
115
+ end
116
+
117
+ end
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-sugar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,33 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: chef
42
+ name: stove
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '11.0'
47
+ version: 2.0.0.beta
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '11.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.11'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '2.11'
54
+ version: 2.0.0.beta
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: chefspec
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -81,33 +67,19 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '3.0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: test-kitchen
70
+ name: coveralls
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ~>
88
74
  - !ruby/object:Gem::Version
89
- version: '1.0'
75
+ version: '0.7'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - ~>
95
81
  - !ruby/object:Gem::Version
96
- version: '1.0'
97
- - !ruby/object:Gem::Dependency
98
- name: kitchen-vagrant
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: '0.14'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: '0.14'
82
+ version: '0.7'
111
83
  description: A series of helpful sugar of the Chef core and other resources to make
112
84
  a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes
113
85
  an awesome experience!
@@ -118,7 +90,6 @@ extensions: []
118
90
  extra_rdoc_files: []
119
91
  files:
120
92
  - .gitignore
121
- - .kitchen.yml
122
93
  - .travis.yml
123
94
  - CHANGELOG.md
124
95
  - CONTRIBUTING.md
@@ -130,9 +101,14 @@ files:
130
101
  - lib/chef/sugar.rb
131
102
  - lib/chef/sugar/architecture.rb
132
103
  - lib/chef/sugar/cloud.rb
104
+ - lib/chef/sugar/constraints.rb
105
+ - lib/chef/sugar/core_extensions.rb
106
+ - lib/chef/sugar/core_extensions/array.rb
107
+ - lib/chef/sugar/core_extensions/string.rb
133
108
  - lib/chef/sugar/data_bag.rb
134
109
  - lib/chef/sugar/filters.rb
135
110
  - lib/chef/sugar/ip.rb
111
+ - lib/chef/sugar/kernel.rb
136
112
  - lib/chef/sugar/node.rb
137
113
  - lib/chef/sugar/platform.rb
138
114
  - lib/chef/sugar/platform_family.rb
@@ -142,19 +118,22 @@ files:
142
118
  - lib/chef/sugar/version.rb
143
119
  - metadata.rb
144
120
  - recipes/default.rb
145
- - recipes/development.rb
146
121
  - spec/spec_helper.rb
147
122
  - spec/support/shared_examples.rb
148
- - spec/unit/chef/extensions/architecture_spec.rb
149
- - spec/unit/chef/extensions/cloud_spec.rb
150
- - spec/unit/chef/extensions/data_bag_spec.rb
151
- - spec/unit/chef/extensions/ip_spec.rb
152
- - spec/unit/chef/extensions/node_spec.rb
153
- - spec/unit/chef/extensions/platform_family_spec.rb
154
- - spec/unit/chef/extensions/platform_spec.rb
155
- - spec/unit/chef/extensions/ruby_spec.rb
156
- - spec/unit/chef/extensions/shell_spec.rb
157
- - spec/unit/chef/extensions/vagrant_spec.rb
123
+ - spec/unit/chef/sugar/architecture_spec.rb
124
+ - spec/unit/chef/sugar/cloud_spec.rb
125
+ - spec/unit/chef/sugar/constraints_spec.rb
126
+ - spec/unit/chef/sugar/core_extensions/array_spec.rb
127
+ - spec/unit/chef/sugar/core_extensions/string_spec.rb
128
+ - spec/unit/chef/sugar/data_bag_spec.rb
129
+ - spec/unit/chef/sugar/ip_spec.rb
130
+ - spec/unit/chef/sugar/kernel_spec.rb
131
+ - spec/unit/chef/sugar/node_spec.rb
132
+ - spec/unit/chef/sugar/platform_family_spec.rb
133
+ - spec/unit/chef/sugar/platform_spec.rb
134
+ - spec/unit/chef/sugar/ruby_spec.rb
135
+ - spec/unit/chef/sugar/shell_spec.rb
136
+ - spec/unit/chef/sugar/vagrant_spec.rb
158
137
  - spec/unit/recipes/default_spec.rb
159
138
  homepage: https://github.com/sethvargo/chef-sugar
160
139
  licenses:
@@ -171,12 +150,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
150
  version: '1.9'
172
151
  required_rubygems_version: !ruby/object:Gem::Requirement
173
152
  requirements:
174
- - - '>='
153
+ - - '>'
175
154
  - !ruby/object:Gem::Version
176
- version: '0'
155
+ version: 1.3.1
177
156
  requirements: []
178
157
  rubyforge_project:
179
- rubygems_version: 2.0.14
158
+ rubygems_version: 2.2.1
180
159
  signing_key:
181
160
  specification_version: 4
182
161
  summary: A collection of helper methods and modules that make working with Chef recipes
@@ -184,14 +163,19 @@ summary: A collection of helper methods and modules that make working with Chef
184
163
  test_files:
185
164
  - spec/spec_helper.rb
186
165
  - spec/support/shared_examples.rb
187
- - spec/unit/chef/extensions/architecture_spec.rb
188
- - spec/unit/chef/extensions/cloud_spec.rb
189
- - spec/unit/chef/extensions/data_bag_spec.rb
190
- - spec/unit/chef/extensions/ip_spec.rb
191
- - spec/unit/chef/extensions/node_spec.rb
192
- - spec/unit/chef/extensions/platform_family_spec.rb
193
- - spec/unit/chef/extensions/platform_spec.rb
194
- - spec/unit/chef/extensions/ruby_spec.rb
195
- - spec/unit/chef/extensions/shell_spec.rb
196
- - spec/unit/chef/extensions/vagrant_spec.rb
166
+ - spec/unit/chef/sugar/architecture_spec.rb
167
+ - spec/unit/chef/sugar/cloud_spec.rb
168
+ - spec/unit/chef/sugar/constraints_spec.rb
169
+ - spec/unit/chef/sugar/core_extensions/array_spec.rb
170
+ - spec/unit/chef/sugar/core_extensions/string_spec.rb
171
+ - spec/unit/chef/sugar/data_bag_spec.rb
172
+ - spec/unit/chef/sugar/ip_spec.rb
173
+ - spec/unit/chef/sugar/kernel_spec.rb
174
+ - spec/unit/chef/sugar/node_spec.rb
175
+ - spec/unit/chef/sugar/platform_family_spec.rb
176
+ - spec/unit/chef/sugar/platform_spec.rb
177
+ - spec/unit/chef/sugar/ruby_spec.rb
178
+ - spec/unit/chef/sugar/shell_spec.rb
179
+ - spec/unit/chef/sugar/vagrant_spec.rb
197
180
  - spec/unit/recipes/default_spec.rb
181
+ has_rdoc: