chefspec 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chefspec.rb +2 -0
- data/lib/chefspec/chef_runner.rb +41 -6
- data/lib/chefspec/monkey_patches/provider.rb +27 -0
- data/lib/chefspec/version.rb +3 -0
- metadata +42 -66
data/lib/chefspec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'chef'
|
2
2
|
require 'rspec'
|
3
3
|
require 'chefspec/chef_runner'
|
4
|
+
require 'chefspec/version'
|
4
5
|
require 'chefspec/matchers/execute'
|
5
6
|
require 'chefspec/matchers/file'
|
6
7
|
require 'chefspec/matchers/log'
|
@@ -8,3 +9,4 @@ require 'chefspec/matchers/package'
|
|
8
9
|
require 'chefspec/matchers/service'
|
9
10
|
require 'chefspec/matchers/shared'
|
10
11
|
require 'chefspec/monkey_patches/hash'
|
12
|
+
require 'chefspec/monkey_patches/provider'
|
data/lib/chefspec/chef_runner.rb
CHANGED
@@ -18,10 +18,18 @@ module ChefSpec
|
|
18
18
|
|
19
19
|
# Instantiate a new runner to run examples with.
|
20
20
|
#
|
21
|
-
# @param [
|
22
|
-
|
21
|
+
# @param [Hash] options The options for the new runner
|
22
|
+
# @option options [String] :cookbook_path The path to the chef cookbook(s) to be tested.
|
23
|
+
# @option options [Symbol] :log_level The log level to use (default is :warn)
|
24
|
+
# @yield [node] Configuration block for Chef::Node
|
25
|
+
def initialize(options={})
|
26
|
+
defaults = {:cookbook_path => default_cookbook_path, :log_level => :warn, :dry_run => false}
|
27
|
+
options = {:cookbook_path => options} unless options.respond_to(:to_hash) # backwards-compatibility
|
28
|
+
options = defaults.merge(options)
|
29
|
+
|
23
30
|
the_runner = self
|
24
31
|
@resources = []
|
32
|
+
@do_dry_run = options[:dry_run]
|
25
33
|
|
26
34
|
Chef::Resource.class_eval do
|
27
35
|
alias :old_run_action :run_action
|
@@ -43,21 +51,27 @@ module ChefSpec
|
|
43
51
|
end
|
44
52
|
|
45
53
|
Chef::Config[:solo] = true
|
46
|
-
Chef::Config[:cookbook_path] = cookbook_path
|
54
|
+
Chef::Config[:cookbook_path] = options[:cookbook_path]
|
47
55
|
Chef::Log.verbose = true if Chef::Log.respond_to?(:verbose)
|
48
|
-
Chef::Log.level(:
|
56
|
+
Chef::Log.level(options[:log_level])
|
49
57
|
@client = Chef::Client.new
|
50
|
-
@client.
|
58
|
+
fake_ohai(@client.ohai)
|
51
59
|
@node = @client.build_node
|
60
|
+
if block_given?
|
61
|
+
yield @node
|
62
|
+
end
|
52
63
|
end
|
53
64
|
|
54
65
|
# Run the specified recipes, but without actually converging the node.
|
55
66
|
#
|
56
67
|
# @param [array] recipe_names The names of the recipes to execute
|
68
|
+
# @return ChefSpec::ChefRunner The runner itself
|
57
69
|
def converge(*recipe_names)
|
70
|
+
@node.run_list.reset!
|
58
71
|
recipe_names.each do |recipe_name|
|
59
72
|
@node.run_list << recipe_name
|
60
73
|
end
|
74
|
+
return self if @do_dry_run
|
61
75
|
|
62
76
|
@client.instance_eval do
|
63
77
|
if defined?(@expanded_run_list_with_versions) # 0.10.x
|
@@ -67,7 +81,6 @@ module ChefSpec
|
|
67
81
|
end
|
68
82
|
|
69
83
|
@resources = []
|
70
|
-
|
71
84
|
if @client.respond_to?(:setup_run_context) # 0.10.x
|
72
85
|
run_context = @client.setup_run_context
|
73
86
|
else
|
@@ -75,6 +88,7 @@ module ChefSpec
|
|
75
88
|
end
|
76
89
|
runner = Chef::Runner.new(run_context)
|
77
90
|
runner.converge
|
91
|
+
self
|
78
92
|
end
|
79
93
|
|
80
94
|
# Find any directory declared with the given path
|
@@ -93,8 +107,29 @@ module ChefSpec
|
|
93
107
|
find_resource('file', path)
|
94
108
|
end
|
95
109
|
|
110
|
+
# This runner as a string.
|
111
|
+
#
|
112
|
+
# @return [String] Currently includes the run_list. Format of the string may change between versions of this gem.
|
113
|
+
def to_s
|
114
|
+
return "chef_run: #{@node.run_list.to_s}" unless @node.run_list.empty?
|
115
|
+
'chef_run'
|
116
|
+
end
|
117
|
+
|
96
118
|
private
|
97
119
|
|
120
|
+
# Populate basic OHAI attributes required to get recipes working. This is a minimal set - if your recipe example
|
121
|
+
# does conditional execution based on these values or additional attributes you can set these via
|
122
|
+
# node.automatic_attrs.
|
123
|
+
#
|
124
|
+
# @param [Ohai::System] ohai The ohai instance to set fake attributes on
|
125
|
+
def fake_ohai(ohai)
|
126
|
+
{:os => 'chefspec', :os_version => ChefSpec::VERSION, :fqdn => 'chefspec.local', :domain => 'local',
|
127
|
+
:ipaddress => '127.0.0.1', :hostname => 'chefspec',
|
128
|
+
:kernel => Mash.new({:machine => 'i386'})}.each_pair do |attribute,value|
|
129
|
+
ohai[attribute] = value
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
98
133
|
# Infer the default cookbook path from the location of the calling spec.
|
99
134
|
#
|
100
135
|
# @return [String] The path to the cookbooks directory
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Override Chef LWRP creation to remove existing class to avoid redefinition warnings.
|
2
|
+
class Chef
|
3
|
+
class Provider
|
4
|
+
class << self
|
5
|
+
alias :old_build_from_file :build_from_file
|
6
|
+
|
7
|
+
def build_from_file(cookbook_name, filename, run_context)
|
8
|
+
remove_existing_lwrp(convert_to_class_name(filename_to_qualified_string(cookbook_name, filename)))
|
9
|
+
old_build_from_file(cookbook_name, filename, run_context)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Remove any existing Chef provider or resource with the specified name.
|
13
|
+
#
|
14
|
+
# @param [String] class_name The class name. Must be a valid constant name.
|
15
|
+
def remove_existing_lwrp(class_name)
|
16
|
+
[Chef::Resource, Chef::Provider].each do |resource_holder|
|
17
|
+
if resource_holder.const_defined? class_name
|
18
|
+
resource_holder.send(:remove_const, class_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
metadata
CHANGED
@@ -1,70 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: chefspec
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Andrew Crump
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2011-09-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: &2156420500 !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 35
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 9
|
30
|
-
- 12
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 0.9.12
|
32
22
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
segments:
|
36
|
-
- 0
|
37
|
-
- 10
|
38
|
-
version: "0.10"
|
39
|
-
name: chef
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0.10'
|
40
25
|
type: :runtime
|
41
26
|
prerelease: false
|
42
|
-
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
|
27
|
+
version_requirements: *2156420500
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: &2156417840 !ruby/object:Gem::Requirement
|
45
31
|
none: false
|
46
|
-
requirements:
|
47
|
-
- -
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
hash: 23
|
50
|
-
segments:
|
51
|
-
- 2
|
52
|
-
- 6
|
53
|
-
- 0
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
54
35
|
version: 2.6.0
|
55
|
-
name: rspec
|
56
36
|
type: :runtime
|
57
37
|
prerelease: false
|
58
|
-
|
38
|
+
version_requirements: *2156417840
|
59
39
|
description: Write RSpec examples for Opscode Chef recipes
|
60
40
|
email:
|
61
41
|
executables: []
|
62
|
-
|
63
42
|
extensions: []
|
64
|
-
|
65
43
|
extra_rdoc_files: []
|
66
|
-
|
67
|
-
files:
|
44
|
+
files:
|
68
45
|
- lib/chefspec/chef_runner.rb
|
69
46
|
- lib/chefspec/matchers/execute.rb
|
70
47
|
- lib/chefspec/matchers/file.rb
|
@@ -73,39 +50,38 @@ files:
|
|
73
50
|
- lib/chefspec/matchers/service.rb
|
74
51
|
- lib/chefspec/matchers/shared.rb
|
75
52
|
- lib/chefspec/monkey_patches/hash.rb
|
53
|
+
- lib/chefspec/monkey_patches/provider.rb
|
54
|
+
- lib/chefspec/version.rb
|
76
55
|
- lib/chefspec.rb
|
77
56
|
homepage: http://acrmp.github.com/chefspec
|
78
|
-
licenses:
|
57
|
+
licenses:
|
79
58
|
- MIT
|
80
59
|
post_install_message:
|
81
60
|
rdoc_options: []
|
82
|
-
|
83
|
-
require_paths:
|
61
|
+
require_paths:
|
84
62
|
- lib
|
85
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
64
|
none: false
|
87
|
-
requirements:
|
88
|
-
- -
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
|
91
|
-
segments:
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
segments:
|
92
70
|
- 0
|
93
|
-
|
94
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
hash: 2232582329296012492
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
73
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
segments:
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
segments:
|
101
79
|
- 0
|
102
|
-
|
80
|
+
hash: 2232582329296012492
|
103
81
|
requirements: []
|
104
|
-
|
105
82
|
rubyforge_project:
|
106
83
|
rubygems_version: 1.8.6
|
107
84
|
signing_key:
|
108
85
|
specification_version: 3
|
109
|
-
summary: chefspec-0.
|
86
|
+
summary: chefspec-0.2.0
|
110
87
|
test_files: []
|
111
|
-
|