knife-skeleton 0.0.1

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.
@@ -0,0 +1,279 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'chef/knife/skeleton_create'
4
+ require 'fakefs/spec_helpers'
5
+
6
+ describe Knife::SkeletonCreate do
7
+ include FakeFS::SpecHelpers
8
+
9
+ before(:each) do
10
+ @knife = Knife::SkeletonCreate.new
11
+ @knife.config = {}
12
+ @knife.name_args = ['foobar']
13
+ @stdout = StringIO.new
14
+ @knife.stub(:stdout).and_return(@stdout)
15
+ end
16
+
17
+ describe 'run' do
18
+ it 'should show usage if there is no cookbook name' do
19
+ @knife.config = {}
20
+ @knife.name_args = []
21
+ @knife.ui.should_receive(:fatal).with('You must specify a cookbook name')
22
+ -> { @knife.run }.should raise_error SystemExit
23
+ end
24
+
25
+ it 'should raise ArgumentError if there is no cookbook path' do
26
+ @knife.config = { cookbook_path: '' }
27
+ -> { @knife.run }.should raise_error ArgumentError
28
+ end
29
+
30
+ it 'should expand the path of the cookbook directory' do
31
+ File.should_receive(:expand_path).with('~/tmp/cookbooks')
32
+ @knife.config = { cookbook_path: '~/tmp/cookbooks' }
33
+ @knife.stub(:create_cookbook_directories)
34
+ @knife.stub(:create_cookbook_files)
35
+ @knife.stub(:create_cookbook_templates)
36
+ @knife.run
37
+ end
38
+
39
+ it 'should create a new cookbook' do
40
+ @dir = Dir.tmpdir
41
+ @knife.config = { cookbook_path: @dir }
42
+ @knife.should_receive(:create_cookbook_directories).with(
43
+ @dir,
44
+ @knife.name_args.first
45
+ )
46
+ @knife.should_receive(:create_cookbook_files).with(
47
+ @dir,
48
+ @knife.name_args.first
49
+ )
50
+ params = {
51
+ cookbook_path: @dir,
52
+ cookbook_name: @knife.name_args.first,
53
+ copyright: 'YOUR_COMPANY_NAME',
54
+ email: 'YOUR_EMAIL',
55
+ license: 'none',
56
+ license_name: 'All rights reserved',
57
+ readme_format: 'md'
58
+ }
59
+ @knife.should_receive(:create_cookbook_templates).with(params)
60
+ @knife.run
61
+ end
62
+
63
+ it 'should create a new cookbook with all parameters' do
64
+ @dir = Dir.tmpdir
65
+ @knife.config = {
66
+ cookbook_path: @dir,
67
+ cookbook_copyright: 'Got',
68
+ cookbook_email: 'pierre.rambaud86@gmail.com',
69
+ cookbook_license: 'gplv3'
70
+ }
71
+ @knife.should_receive(:create_cookbook_directories).with(
72
+ @dir,
73
+ @knife.name_args.first
74
+ )
75
+ @knife.should_receive(:create_cookbook_files).with(
76
+ @dir,
77
+ @knife.name_args.first
78
+ )
79
+ params = {
80
+ cookbook_path: @dir,
81
+ cookbook_name: @knife.name_args.first,
82
+ copyright: 'Got',
83
+ email: 'pierre.rambaud86@gmail.com',
84
+ license: 'gplv3',
85
+ license_name: 'GNU Public License 3.0',
86
+ readme_format: 'md'
87
+ }
88
+ @knife.should_receive(:create_cookbook_templates).with(params)
89
+ @knife.run
90
+ end
91
+
92
+ it 'should set license to none if value is false (boolean)' do
93
+ @dir = Dir.tmpdir
94
+ @knife.config = {
95
+ cookbook_path: @dir,
96
+ cookbook_copyright: 'Got',
97
+ cookbook_email: 'pierre.rambaud86@gmail.com',
98
+ cookbook_license: false
99
+ }
100
+ @knife.should_receive(:create_cookbook_directories).with(
101
+ @dir,
102
+ @knife.name_args.first
103
+ )
104
+ @knife.should_receive(:create_cookbook_files).with(
105
+ @dir,
106
+ @knife.name_args.first
107
+ )
108
+ params = {
109
+ cookbook_path: @dir,
110
+ cookbook_name: @knife.name_args.first,
111
+ copyright: 'Got',
112
+ email: 'pierre.rambaud86@gmail.com',
113
+ license: 'none',
114
+ license_name: 'All rights reserved',
115
+ readme_format: 'md'
116
+ }
117
+ @knife.should_receive(:create_cookbook_templates).with(params)
118
+ @knife.run
119
+ end
120
+
121
+ it 'should set license to none if value is false (string)' do
122
+ @dir = Dir.tmpdir
123
+ @knife.config = {
124
+ cookbook_path: @dir,
125
+ cookbook_copyright: 'Got',
126
+ cookbook_email: 'pierre.rambaud86@gmail.com',
127
+ cookbook_license: 'false'
128
+ }
129
+ @knife.should_receive(:create_cookbook_directories).with(
130
+ @dir,
131
+ @knife.name_args.first
132
+ )
133
+ @knife.should_receive(:create_cookbook_files).with(
134
+ @dir,
135
+ @knife.name_args.first
136
+ )
137
+ params = {
138
+ cookbook_path: @dir,
139
+ cookbook_name: @knife.name_args.first,
140
+ copyright: 'Got',
141
+ email: 'pierre.rambaud86@gmail.com',
142
+ license: 'none',
143
+ license_name: 'All rights reserved',
144
+ readme_format: 'md'
145
+ }
146
+ @knife.should_receive(:create_cookbook_templates).with(params)
147
+ @knife.run
148
+ end
149
+
150
+ it 'should create cookbook directories with all files and templates' do
151
+ @dir = Dir.tmpdir
152
+ @knife.config = {
153
+ cookbook_path: @dir,
154
+ cookbook_copyright: 'Got',
155
+ cookbook_email: 'pierre.rambaud86@gmail.com',
156
+ cookbook_license: 'gplv3'
157
+ }
158
+
159
+ FakeFS::FileSystem.clone(
160
+ File.expand_path(
161
+ '../../../../',
162
+ Pathname.new(__FILE__).realpath
163
+ )
164
+ )
165
+
166
+ @knife.ui.should_receive(:msg).with('** Create cookbook foobar into /tmp')
167
+ @knife.ui.should_receive(:msg).with("** Create 'Berksfile'")
168
+ @knife.ui.should_receive(:msg).with("** Create 'Gemfile'")
169
+ @knife.ui.should_receive(:msg).with("** Create '.gitignore'")
170
+ @knife.ui.should_receive(:msg).with("** Create '.travis.yml'")
171
+ @knife.ui.should_receive(:msg).with("** Create '.rubocop.yml'")
172
+ @knife.ui.should_receive(:msg).with("** Create '.kitchen.yml'")
173
+ @knife.ui.should_receive(:msg).with("** Create 'Strainerfile'")
174
+ @knife.ui.should_receive(:msg).with("** Create 'CHANGELOG.md'")
175
+ @knife.ui.should_receive(:msg).with("** Create 'metadata.rb'")
176
+ @knife.ui.should_receive(:msg).with("** Create 'README.md'")
177
+ @knife.ui.should_receive(:msg).with("** Create 'recipes/default.rb'")
178
+ @knife.ui.should_receive(:msg).with("** Create 'spec/default_spec.rb'")
179
+ @knife.ui.should_receive(:msg).with("** Create 'spec/spec_helper.rb'")
180
+ @knife.ui.should_receive(:msg).with(
181
+ "** Create 'test/integration/default/serverspec/spec_helper.rb'")
182
+ @knife.ui.should_receive(:msg).with(
183
+ "** Create 'test/integration/default/serverspec/default_spec.rb'")
184
+ @knife.run
185
+ # Run txice to tests warn
186
+ @knife.ui.should_receive(:msg).with('** Create cookbook foobar into /tmp')
187
+ @knife.ui.should_receive(:warn).with("'Berksfile' already exists")
188
+ @knife.ui.should_receive(:warn).with("'Gemfile' already exists")
189
+ @knife.ui.should_receive(:warn).with("'.gitignore' already exists")
190
+ @knife.ui.should_receive(:warn).with("'.rubocop.yml' already exists")
191
+ @knife.ui.should_receive(:warn).with("'.kitchen.yml' already exists")
192
+ @knife.ui.should_receive(:warn).with("'.travis.yml' already exists")
193
+ @knife.ui.should_receive(:warn).with("'Strainerfile' already exists")
194
+ @knife.ui.should_receive(:warn).with("'metadata.rb' already exists")
195
+ @knife.ui.should_receive(:warn).with("'CHANGELOG.md' already exists")
196
+ @knife.ui.should_receive(:warn).with("'README.md' already exists")
197
+ @knife.ui.should_receive(:warn).with(
198
+ "'recipes/default.rb' already exists")
199
+ @knife.ui.should_receive(:warn).with(
200
+ "'spec/default_spec.rb' already exists")
201
+ @knife.ui.should_receive(:warn).with(
202
+ "'spec/spec_helper.rb' already exists")
203
+ @knife.ui.should_receive(:warn).with(
204
+ "'test/integration/default/serverspec/spec_helper.rb' already exists")
205
+ @knife.ui.should_receive(:warn).with(
206
+ "'test/integration/default/serverspec/default_spec.rb' already exists")
207
+ @knife.run
208
+
209
+ %w(
210
+ definitions
211
+ libraries
212
+ providers
213
+ recipes
214
+ resources
215
+ spec
216
+ files/default
217
+ templates/default
218
+ test/integration/default/serverspec).each do |dir_name|
219
+ assert_file_exists(@dir, @knife.name_args.first, dir_name)
220
+ end
221
+
222
+ %w(
223
+ metadata.rb
224
+ Berksfile
225
+ Gemfile
226
+ .gitignore
227
+ .rubocop.yml
228
+ .travis.yml
229
+ .kitchen.yml
230
+ Strainerfile
231
+ CHANGELOG.md
232
+ README.md
233
+ recipes/default.rb
234
+ spec/default_spec.rb
235
+ spec/spec_helper.rb
236
+ test/integration/default/serverspec/spec_helper.rb
237
+ test/integration/default/serverspec/default_spec.rb
238
+ ).each do |file_name|
239
+ assert_file_exists(@dir, @knife.name_args.first, file_name)
240
+ end
241
+ end
242
+
243
+ def assert_file_exists(cookbook_path, cookbook_name, file_name)
244
+ file_path = File.join(
245
+ cookbook_path,
246
+ cookbook_name,
247
+ file_name
248
+ )
249
+ expect(File.exist?(file_path)).to be_truthy
250
+ end
251
+ end
252
+
253
+ describe 'cookbook_license_name' do
254
+ it 'should test with apache2 license' do
255
+ @knife.config = { cookbook_license: 'apachev2' }
256
+ expect(@knife.cookbook_license_name).to eq('Apache 2.0')
257
+ end
258
+
259
+ it 'should test with gplv2 license' do
260
+ @knife.config = { cookbook_license: 'gplv2' }
261
+ expect(@knife.cookbook_license_name).to eq('GNU Public License 2.0')
262
+ end
263
+
264
+ it 'should test with gplv3 license' do
265
+ @knife.config = { cookbook_license: 'gplv3' }
266
+ expect(@knife.cookbook_license_name).to eq('GNU Public License 3.0')
267
+ end
268
+
269
+ it 'should test with mit license' do
270
+ @knife.config = { cookbook_license: 'mit' }
271
+ expect(@knife.cookbook_license_name).to eq('MIT')
272
+ end
273
+
274
+ it 'should test with none license' do
275
+ @knife.config = { cookbook_license: 'none' }
276
+ expect(@knife.cookbook_license_name).to eq('All rights reserved')
277
+ end
278
+ end
279
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'knife_skeleton/template'
4
+
5
+ # Template tests
6
+ module KnifeSkeleton
7
+ describe 'Template.render' do
8
+ it 'renders ERB template' do
9
+ template = 'May the force be with <%= name %>.'
10
+ data = { name: 'you' }
11
+ output = Template.render(template, data)
12
+ output.should == 'May the force be with you.'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_filter '/spec/'
8
+ add_group 'Knife Skeleton', 'lib/chef'
9
+ add_group 'Skeleton library', 'lib/knife_skeleton'
10
+ end
@@ -0,0 +1,15 @@
1
+ ---
2
+ driver_plugin: vagrant
3
+ driver_config:
4
+ require_chef_omnibus: true
5
+
6
+ platforms:
7
+ - name: ubuntu-12.04
8
+ driver_config:
9
+ box: opscode-ubuntu-12.04
10
+ box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
11
+
12
+ suites:
13
+ - name: 'default'
14
+ run_list:
15
+ - recipe[<%= cookbook_name %>]
@@ -0,0 +1,8 @@
1
+ <%= cookbook_name %> CHANGELOG
2
+ #{'='*"<%= cookbook_name %> CHANGELOG".length}
3
+
4
+ This file is used to list changes made in each version of the <%= cookbook_name %> cookbook.
5
+
6
+ 0.1.0
7
+ -----
8
+ - [your_name] - Initial release of <%= cookbook_name %>
@@ -0,0 +1,8 @@
1
+ = <%= cookbook_name %> CHANGELOG
2
+ <%= '-'*" #{cookbook_name} CHANGELOG".length %>
3
+
4
+ This file is used to list changes made in each version of the <%= cookbook_name %> cookbook.
5
+
6
+ == 0.1.0
7
+
8
+ - [your_name] - Initial release of <%= cookbook_name %>
@@ -0,0 +1,7 @@
1
+ <%= cookbook_name %> CHANGELOG
2
+
3
+ This file is used to list changes made in each version of the <%= cookbook_name %> cookbook.
4
+
5
+ 0.1.0
6
+
7
+ - [your_name] - Initial release of <%= cookbook_name %>
@@ -0,0 +1,68 @@
1
+ <%= cookbook_name %> Cookbook
2
+ <%= '='*"cookbook_name Cookbook".length %>
3
+ TODO: Enter the cookbook description here.
4
+
5
+ e.g.
6
+ This cookbook makes your favorite breakfast sandwich.
7
+
8
+ Requirements
9
+ ------------
10
+ TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
11
+
12
+ e.g.
13
+ #### packages
14
+ - `toaster` - <%= cookbook_name %> needs toaster to brown your bagel.
15
+
16
+ Attributes
17
+ ----------
18
+ TODO: List your cookbook attributes here.
19
+
20
+ e.g.
21
+ #### <%= cookbook_name %>::default
22
+ <table>
23
+ <tr>
24
+ <th>Key</th>
25
+ <th>Type</th>
26
+ <th>Description</th>
27
+ <th>Default</th>
28
+ </tr>
29
+ <tr>
30
+ <td><tt>['<%= cookbook_name %>']['bacon']</tt></td>
31
+ <td>Boolean</td>
32
+ <td>whether to include bacon</td>
33
+ <td><tt>true</tt></td>
34
+ </tr>
35
+ </table>
36
+
37
+ Usage
38
+ -----
39
+ #### <%= cookbook_name %>::default
40
+ TODO: Write usage instructions for each cookbook.
41
+
42
+ e.g.
43
+ Just include `<%= cookbook_name %>` in your node's `run_list`:
44
+
45
+ ```json
46
+ {
47
+ "name":"my_node",
48
+ "run_list": [
49
+ "recipe[<%= cookbook_name %>]"
50
+ ]
51
+ }
52
+ ```
53
+
54
+ Contributing
55
+ ------------
56
+ TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
57
+
58
+ e.g.
59
+ 1. Fork the repository on Github
60
+ 2. Create a named feature branch (like `add_component_x`)
61
+ 3. Write your change
62
+ 4. Write tests for your change (if applicable)
63
+ 5. Run the tests, ensuring they all pass
64
+ 6. Submit a Pull Request using Github
65
+
66
+ License and Authors
67
+ -------------------
68
+ Authors: TODO: List authors
@@ -0,0 +1,67 @@
1
+ = <%= cookbook_name %> Cookbook
2
+ <%= '-'*" #{cookbook_name} Cookbook".length %>
3
+ TODO: Enter the cookbook description here.
4
+
5
+ e.g.
6
+ This cookbook makes your favorite breakfast sandwich.
7
+
8
+ == Requirements
9
+ ---------------
10
+ TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
11
+
12
+ e.g.
13
+ === packages
14
+ - `toaster` - <%= cookbook_name %> needs toaster to brown your bage1.
15
+
16
+ == Attributes
17
+ -------------
18
+ TODO: List your cookbook attributes here.
19
+
20
+ e.g.
21
+ === <%= cookbook_name %>::default
22
+ <table>
23
+ <tr>
24
+ <th>Key</th>
25
+ <th>Type</th>
26
+ <th>Description</th>
27
+ <th>Default</th>
28
+ </tr>
29
+ <tr>
30
+ <td><tt>['<%= cookbook_name %>']['bacon']</tt></td>
31
+ <td>Boolean</td>
32
+ <td>whether to include bacon</td>
33
+ <td><tt>true</tt></td>
34
+ </tr>
35
+ </table>
36
+
37
+ == Usage
38
+ --------
39
+ === <%= cookbook_name %>::default
40
+ TODO: Write usage instructions for each cookbook.
41
+
42
+ e.g.
43
+ Just include `<%= cookbook_name %>` in your node's `run_list`:
44
+
45
+ {
46
+ "name":"my_node",
47
+ "run_list": [
48
+ "recipe[<%= cookbook_name %>]"
49
+ ]
50
+ }
51
+
52
+
53
+ == Contributing
54
+ ---------------
55
+ TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
56
+
57
+ e.g.
58
+ 1. Fork the repository on Github
59
+ 1. Create a named feature branch (like `add_component_x`)
60
+ 1. Write your change
61
+ 1. Write tests for your change (if applicable)
62
+ 1. Run the tests, ensuring they all pass
63
+ 1. Submit a Pull Request using Github
64
+
65
+ == License and Authors
66
+ ----------------------
67
+ Authors: TODO: List authors