chefspec-bootstrap 0.0.5 → 0.1.0
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.
- data/.rubocop.yml +0 -3
- data/README.md +13 -12
- data/chefspec-bootstrap.gemspec +2 -2
- data/lib/chefspec_bootstrap.rb +19 -13
- data/spec/chefspec_bootstrap_spec.rb +9 -5
- data/spec/cookbooks/spec/recipes/compile_time.rb +3 -0
- data/spec/cookbooks/spec/recipes/guard.rb +9 -0
- data/spec/cookbooks/spec/recipes/multiple_actions.rb +7 -0
- data/spec/cookbooks/spec/recipes/nothing.rb +7 -0
- data/spec/meta/compile_time_spec.rb +10 -0
- data/spec/meta/directory_spec.rb +22 -0
- data/spec/{templates/failure.txt → meta/failure_spec.rb} +1 -1
- data/spec/meta/guard_spec.rb +14 -0
- data/spec/meta/multiple_actions_spec.rb +30 -0
- data/spec/meta/nothing_spec.rb +14 -0
- data/spec/meta/package_spec.rb +34 -0
- data/templates/default.erb +4 -3
- metadata +13 -5
- data/spec/templates/directory.txt +0 -22
- data/spec/templates/package.txt +0 -34
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -9,18 +9,18 @@ chefspec-bootstrap
|
|
9
9
|
[travis]: http://travis-ci.org/AMeng/chefspec-bootstrap
|
10
10
|
[codeclimate]: https://codeclimate.com/github/AMeng/chefspec-bootstrap
|
11
11
|
|
12
|
-
A command line tool to get started with ChefSpec. Generates spec files for your untested recipes.
|
12
|
+
A command line tool to get started with [ChefSpec](https://github.com/sethvargo/chefspec). Generates spec files for your untested recipes.
|
13
13
|
|
14
14
|
Given a cookbook called `my_cookbook` with a recipe called `my_recipe.rb`:
|
15
15
|
```ruby
|
16
|
-
package
|
16
|
+
package 'apache2'
|
17
17
|
|
18
|
-
file
|
18
|
+
file '/etc/apache2/sites-available/default' do
|
19
19
|
action :delete
|
20
20
|
end
|
21
21
|
|
22
|
-
template
|
23
|
-
source
|
22
|
+
template '/etc/apache2/sites-available/mysite' do
|
23
|
+
source 'mysite.conf.erb'
|
24
24
|
end
|
25
25
|
```
|
26
26
|
|
@@ -31,16 +31,16 @@ require 'chefspec'
|
|
31
31
|
describe 'my_cookbook::my_recipe' do
|
32
32
|
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
33
33
|
|
34
|
-
it
|
35
|
-
expect(chef_run).to install_package(
|
34
|
+
it 'installs the apache2 package' do
|
35
|
+
expect(chef_run).to install_package('apache2')
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
expect(chef_run).to delete_file(
|
38
|
+
it 'deletes the /etc/apache2/conf.d/python.conf file' do
|
39
|
+
expect(chef_run).to delete_file('/etc/apache2/conf.d/python.conf')
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
43
|
-
expect(chef_run).to create_template(
|
42
|
+
it 'creates the /etc/apache2/sites-available/mysite template' do
|
43
|
+
expect(chef_run).to create_template('/etc/apache2/sites-available/mysite')
|
44
44
|
end
|
45
45
|
end
|
46
46
|
```
|
@@ -62,8 +62,9 @@ Options
|
|
62
62
|
```
|
63
63
|
Usage: chefspec-bootstrap <recipe.rb> [options]
|
64
64
|
-t, --template <file> ERB template file used to generate specs
|
65
|
-
-s, --
|
65
|
+
-s, --spec-helper <file> spec_helper.rb file. By default, looks in spec/spec_helper.rb
|
66
66
|
-o, --output <file> File to output spec. Prints to stdout if not specified.
|
67
|
+
-c, --cookbook-path <dir> Cookbook path (directory). Your spec_helper file can override this.
|
67
68
|
```
|
68
69
|
|
69
70
|
Creating a custom template
|
data/chefspec-bootstrap.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'chefspec-bootstrap'
|
3
|
-
s.version = '0.0
|
4
|
-
s.date = '2014-12-
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = '2014-12-23'
|
5
5
|
s.summary = 'Bootstrap your ChefSpec tests.'
|
6
6
|
s.description = 'Automatically generate ChefSpec tests based on your recipes.'
|
7
7
|
s.authors = ['Alexander Meng']
|
data/lib/chefspec_bootstrap.rb
CHANGED
@@ -96,13 +96,8 @@ module ChefSpec
|
|
96
96
|
|
97
97
|
def get_resources(chef_run, cookbook, recipe)
|
98
98
|
if chef_run
|
99
|
-
|
100
|
-
|
101
|
-
return resources
|
102
|
-
else
|
103
|
-
return resources.select do |resource|
|
104
|
-
resource.cookbook_name == cookbook.to_sym && resource.recipe_name == recipe
|
105
|
-
end
|
99
|
+
return get_all_resources(chef_run).select do |resource|
|
100
|
+
resource.cookbook_name == cookbook.to_sym && resource.recipe_name == recipe
|
106
101
|
end
|
107
102
|
else
|
108
103
|
return []
|
@@ -112,19 +107,29 @@ module ChefSpec
|
|
112
107
|
def generate_test_cases(resources)
|
113
108
|
test_cases = []
|
114
109
|
resources.each do |resource|
|
115
|
-
verbs = resource.
|
116
|
-
|
110
|
+
verbs = resource.instance_variable_get(:@performed_actions)
|
111
|
+
if verbs.empty?
|
112
|
+
if resource.action != [:nothing]
|
113
|
+
verbs = { resource.action.to_s => {} }
|
114
|
+
else
|
115
|
+
verbs = { nothing: {} }
|
116
|
+
end
|
117
|
+
end
|
117
118
|
|
118
119
|
noun = resource.resource_name
|
119
120
|
adjective = resource.name
|
121
|
+
guarded = resource.performed_actions.empty?
|
120
122
|
|
121
|
-
verbs.each do |verb|
|
122
|
-
next if verb == :nothing
|
123
|
-
|
123
|
+
verbs.each do |verb, time|
|
124
124
|
test_cases.push(
|
125
125
|
it: get_it_block(noun, verb, adjective),
|
126
126
|
expect: get_expect_block(noun, verb),
|
127
|
-
name: adjective
|
127
|
+
name: adjective,
|
128
|
+
guarded: guarded,
|
129
|
+
nothing: verb == :nothing,
|
130
|
+
noun: noun,
|
131
|
+
adjective: adjective,
|
132
|
+
compile_time: time[:compile_time]
|
128
133
|
)
|
129
134
|
end
|
130
135
|
end
|
@@ -132,6 +137,7 @@ module ChefSpec
|
|
132
137
|
end
|
133
138
|
|
134
139
|
def get_it_block(noun, verb, adjective)
|
140
|
+
verb = 'ignore' if verb == :nothing
|
135
141
|
it = '%{verb}s the %{adjective} %{noun}'
|
136
142
|
noun_readable = noun.to_s.gsub('_', ' ')
|
137
143
|
verb_readable = verb.to_s.gsub('_', ' ')
|
@@ -2,12 +2,16 @@ require_relative '../lib/chefspec_bootstrap'
|
|
2
2
|
require_relative 'spec_helper'
|
3
3
|
|
4
4
|
describe 'Bootstrap' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
template = File.open("spec/templates/#{resource}.txt", 'rb').read
|
5
|
+
recipes = Dir.entries('spec/cookbooks/spec/recipes').map do |file|
|
6
|
+
file.scan(/(.*).rb/).last.first if file.end_with?('.rb')
|
7
|
+
end.compact
|
9
8
|
|
10
|
-
|
9
|
+
recipes.each do |recipe|
|
10
|
+
it "creates the expected spec file for #{recipe}" do
|
11
|
+
bootstrap = ChefSpec::Bootstrap.new("spec/cookbooks/spec/recipes/#{recipe}.rb", nil, nil, nil, nil)
|
12
|
+
spec = File.open("spec/meta/#{recipe}_spec.rb", 'rb').read
|
13
|
+
|
14
|
+
expect { bootstrap.generate }.to output(spec).to_stdout
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe 'spec::compile_time' do
|
5
|
+
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
+
|
7
|
+
it 'installs the compileable package' do
|
8
|
+
expect(chef_run).to install_package('compileable').at_compile_time
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe 'spec::directory' do
|
5
|
+
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
+
|
7
|
+
it 'creates the defaultable directory' do
|
8
|
+
expect(chef_run).to create_directory('defaultable')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'creates the identifiable directory' do
|
12
|
+
expect(chef_run).to create_directory('identifiable')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'creates the creatable directory' do
|
16
|
+
expect(chef_run).to create_directory('creatable')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'deletes the deletable directory' do
|
20
|
+
expect(chef_run).to delete_directory('deletable')
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe 'spec::guard' do
|
5
|
+
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
+
|
7
|
+
it 'installs the guardable package' do
|
8
|
+
expect(chef_run).to_not install_package('guardable')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'installs the unguardable package' do
|
12
|
+
expect(chef_run).to install_package('unguardable')
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe 'spec::multiple_actions' do
|
5
|
+
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
+
|
7
|
+
it 'installs the multiactionable package' do
|
8
|
+
expect(chef_run).to install_package('multiactionable')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'upgrades the multiactionable package' do
|
12
|
+
expect(chef_run).to upgrade_package('multiactionable')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'purges the multiactionable package' do
|
16
|
+
expect(chef_run).to purge_package('multiactionable')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'installs the mixactionable package' do
|
20
|
+
expect(chef_run).to install_package('mixactionable').at_compile_time
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'upgrades the mixactionable package' do
|
24
|
+
expect(chef_run).to upgrade_package('mixactionable')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'purges the mixactionable package' do
|
28
|
+
expect(chef_run).to purge_package('mixactionable')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe 'spec::nothing' do
|
5
|
+
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
+
|
7
|
+
it 'installs the actionable package' do
|
8
|
+
expect(chef_run).to install_package('actionable')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'ignores the unactionable package' do
|
12
|
+
expect(chef_run.package('unactionable')).to do_nothing
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'chefspec'
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
|
4
|
+
describe 'spec::package' do
|
5
|
+
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
+
|
7
|
+
it 'installs the defaultable package' do
|
8
|
+
expect(chef_run).to install_package('defaultable')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'installs the identifiable package' do
|
12
|
+
expect(chef_run).to install_package('identifiable')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'installs the installable package' do
|
16
|
+
expect(chef_run).to install_package('installable')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'purges the purgeable package' do
|
20
|
+
expect(chef_run).to purge_package('purgeable')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'reconfigs the reconfigurable package' do
|
24
|
+
expect(chef_run).to reconfig_package('reconfigurable')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'removes the removeable package' do
|
28
|
+
expect(chef_run).to remove_package('removeable')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'upgrades the upgradable package' do
|
32
|
+
expect(chef_run).to upgrade_package('upgradable')
|
33
|
+
end
|
34
|
+
end
|
data/templates/default.erb
CHANGED
@@ -4,10 +4,11 @@ require_relative '../spec_helper'<% end %>
|
|
4
4
|
describe '<%= cookbook %>::<%= recipe %>' do
|
5
5
|
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }<% if not test_cases.empty? %><% test_cases.each do |test_case| %>
|
6
6
|
|
7
|
-
it
|
8
|
-
expect(chef_run
|
7
|
+
it '<%= test_case[:it] %>' do<% if test_case[:nothing] %>
|
8
|
+
expect(chef_run.<%= test_case[:noun] %>('<%= test_case[:adjective] %>')).to do_nothing<% else %>
|
9
|
+
expect(chef_run).to<% if test_case[:guarded] %>_not<% end %> <%= test_case[:expect] %>('<%= test_case[:name] %>')<% if test_case[:compile_time] %>.at_compile_time<% end %><% end %>
|
9
10
|
end<% end %><% else %>
|
10
11
|
it 'runs successfully' do
|
11
|
-
expect{chef_run}.
|
12
|
+
expect { chef_run }.to raise_error
|
12
13
|
end<% end %>
|
13
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chefspec-bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chefspec
|
@@ -94,13 +94,21 @@ files:
|
|
94
94
|
- lib/api_map.rb
|
95
95
|
- lib/chefspec_bootstrap.rb
|
96
96
|
- spec/chefspec_bootstrap_spec.rb
|
97
|
+
- spec/cookbooks/spec/recipes/compile_time.rb
|
97
98
|
- spec/cookbooks/spec/recipes/directory.rb
|
98
99
|
- spec/cookbooks/spec/recipes/failure.rb
|
100
|
+
- spec/cookbooks/spec/recipes/guard.rb
|
101
|
+
- spec/cookbooks/spec/recipes/multiple_actions.rb
|
102
|
+
- spec/cookbooks/spec/recipes/nothing.rb
|
99
103
|
- spec/cookbooks/spec/recipes/package.rb
|
104
|
+
- spec/meta/compile_time_spec.rb
|
105
|
+
- spec/meta/directory_spec.rb
|
106
|
+
- spec/meta/failure_spec.rb
|
107
|
+
- spec/meta/guard_spec.rb
|
108
|
+
- spec/meta/multiple_actions_spec.rb
|
109
|
+
- spec/meta/nothing_spec.rb
|
110
|
+
- spec/meta/package_spec.rb
|
100
111
|
- spec/spec_helper.rb
|
101
|
-
- spec/templates/directory.txt
|
102
|
-
- spec/templates/failure.txt
|
103
|
-
- spec/templates/package.txt
|
104
112
|
- templates/default.erb
|
105
113
|
homepage: http://rubygems.org/gems/chefspec-bootstrap
|
106
114
|
licenses:
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'chefspec'
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
describe 'spec::directory' do
|
5
|
-
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
-
|
7
|
-
it "creates the defaultable directory" do
|
8
|
-
expect(chef_run).to create_directory("defaultable")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "creates the identifiable directory" do
|
12
|
-
expect(chef_run).to create_directory("identifiable")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "creates the creatable directory" do
|
16
|
-
expect(chef_run).to create_directory("creatable")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "deletes the deletable directory" do
|
20
|
-
expect(chef_run).to delete_directory("deletable")
|
21
|
-
end
|
22
|
-
end
|
data/spec/templates/package.txt
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'chefspec'
|
2
|
-
require_relative '../spec_helper'
|
3
|
-
|
4
|
-
describe 'spec::package' do
|
5
|
-
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
|
6
|
-
|
7
|
-
it "installs the defaultable package" do
|
8
|
-
expect(chef_run).to install_package("defaultable")
|
9
|
-
end
|
10
|
-
|
11
|
-
it "installs the identifiable package" do
|
12
|
-
expect(chef_run).to install_package("identifiable")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "installs the installable package" do
|
16
|
-
expect(chef_run).to install_package("installable")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "purges the purgeable package" do
|
20
|
-
expect(chef_run).to purge_package("purgeable")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "reconfigs the reconfigurable package" do
|
24
|
-
expect(chef_run).to reconfig_package("reconfigurable")
|
25
|
-
end
|
26
|
-
|
27
|
-
it "removes the removeable package" do
|
28
|
-
expect(chef_run).to remove_package("removeable")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "upgrades the upgradable package" do
|
32
|
-
expect(chef_run).to upgrade_package("upgradable")
|
33
|
-
end
|
34
|
-
end
|