chefspec 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/chefspec.rb
CHANGED
data/lib/chefspec/chef_runner.rb
CHANGED
@@ -13,7 +13,7 @@ module ChefSpec
|
|
13
13
|
@step_into = []
|
14
14
|
@resources = []
|
15
15
|
|
16
|
-
|
16
|
+
attr_accessor :resources
|
17
17
|
attr_reader :node
|
18
18
|
|
19
19
|
# Instantiate a new runner to run examples with.
|
@@ -21,44 +21,58 @@ module ChefSpec
|
|
21
21
|
# @param [string] cookbook_path The path to the chef cookbook(s) to be tested
|
22
22
|
def initialize(cookbook_path=default_cookbook_path)
|
23
23
|
the_runner = self
|
24
|
+
@resources = []
|
24
25
|
|
25
26
|
Chef::Resource.class_eval do
|
26
27
|
alias :old_run_action :run_action
|
27
28
|
|
28
|
-
|
29
|
+
if self.class.method_defined?(:class_variable_set)
|
30
|
+
class_variable_set :@@runner, the_runner
|
31
|
+
else
|
32
|
+
@@runner = the_runner
|
33
|
+
end
|
29
34
|
|
30
35
|
def run_action(action)
|
31
|
-
|
36
|
+
Chef::Log.info("Processing #{self} action #{action} (#{defined_at})") if self.respond_to? :defined_at
|
37
|
+
if self.class.method_defined?(:class_variable_get)
|
38
|
+
self.class_variable_get(:@@runner).resources << self
|
39
|
+
else
|
40
|
+
@@runner.resources << self
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
35
45
|
Chef::Config[:solo] = true
|
36
46
|
Chef::Config[:cookbook_path] = cookbook_path
|
37
|
-
Chef::Log.verbose = true
|
47
|
+
Chef::Log.verbose = true if Chef::Log.respond_to?(:verbose)
|
38
48
|
Chef::Log.level(:debug)
|
39
49
|
@client = Chef::Client.new
|
40
50
|
@client.run_ohai
|
41
51
|
@node = @client.build_node
|
42
52
|
end
|
43
53
|
|
44
|
-
# Infer the default cookbook path from the location of the calling spec.
|
45
|
-
#
|
46
|
-
# @return [String] The path to the cookbooks directory
|
47
|
-
def default_cookbook_path
|
48
|
-
File.join(caller(2).first.split(':').slice(0..-3).to_s, "..", "..", "..")
|
49
|
-
end
|
50
|
-
|
51
54
|
# Run the specified recipes, but without actually converging the node.
|
52
55
|
#
|
53
56
|
# @param [array] recipe_names The names of the recipes to execute
|
54
57
|
def converge(*recipe_names)
|
55
58
|
recipe_names.each do |recipe_name|
|
56
|
-
@
|
59
|
+
@node.run_list << recipe_name
|
60
|
+
end
|
61
|
+
|
62
|
+
@client.instance_eval do
|
63
|
+
if defined?(@expanded_run_list_with_versions) # 0.10.x
|
64
|
+
@run_list_expansion = @node.expand!('disk')
|
65
|
+
@expanded_run_list_with_versions = @run_list_expansion.recipes.with_version_constraints_strings
|
66
|
+
end
|
57
67
|
end
|
58
68
|
|
59
69
|
@resources = []
|
60
|
-
run_context = Chef::RunContext.new(@client.node, Chef::CookbookCollection.new(Chef::CookbookLoader.new))
|
61
70
|
|
71
|
+
if @client.respond_to?(:setup_run_context) # 0.10.x
|
72
|
+
run_context = @client.setup_run_context
|
73
|
+
else
|
74
|
+
run_context = Chef::RunContext.new(@client.node, Chef::CookbookCollection.new(Chef::CookbookLoader.new)) # 0.9.x
|
75
|
+
end
|
62
76
|
runner = Chef::Runner.new(run_context)
|
63
77
|
runner.converge
|
64
78
|
end
|
@@ -81,6 +95,13 @@ module ChefSpec
|
|
81
95
|
|
82
96
|
private
|
83
97
|
|
98
|
+
# Infer the default cookbook path from the location of the calling spec.
|
99
|
+
#
|
100
|
+
# @return [String] The path to the cookbooks directory
|
101
|
+
def default_cookbook_path
|
102
|
+
Pathname.new(File.join(caller(2).first.split(':').slice(0..-3).first, "..", "..", "..")).cleanpath
|
103
|
+
end
|
104
|
+
|
84
105
|
# Find the resource with the declared type and name
|
85
106
|
#
|
86
107
|
# @param [String] type The type of resource - e.g. 'file' or 'directory'
|
@@ -7,8 +7,8 @@ module ChefSpec
|
|
7
7
|
|
8
8
|
RSpec::Matchers.define :install_package_at_version do |package_name, version|
|
9
9
|
match do |chef_run|
|
10
|
-
|
11
|
-
resource_type(resource) == 'package' and resource.package_name == package_name and resource.action.
|
10
|
+
chef_run.resources.any? do |resource|
|
11
|
+
resource_type(resource) == 'package' and resource.package_name == package_name and resource.action.include? :install and resource.version == version
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# @param [String] resource A Chef Resource
|
4
4
|
# @return [String] The resource type
|
5
5
|
def resource_type(resource)
|
6
|
-
resource.
|
6
|
+
resource.resource_name.to_s
|
7
7
|
end
|
8
8
|
|
9
9
|
# Define simple RSpec matchers for the product of resource types and actions
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Ruby stdlib Hash class
|
2
2
|
class Hash
|
3
3
|
|
4
|
-
# Monkey-patch to stdlib Hash to give us
|
4
|
+
# Monkey-patch to stdlib Hash to give us Mash style lookup
|
5
5
|
# @param [Symbol] method_id The method name
|
6
6
|
def method_missing(method_id)
|
7
7
|
key = method_id.id2name
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Crump
|
@@ -15,15 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: chef
|
22
|
-
prerelease: false
|
23
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
26
|
-
- - "
|
24
|
+
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
hash: 35
|
29
27
|
segments:
|
@@ -31,11 +29,18 @@ dependencies:
|
|
31
29
|
- 9
|
32
30
|
- 12
|
33
31
|
version: 0.9.12
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
hash: 31
|
35
|
+
segments:
|
36
|
+
- 0
|
37
|
+
- 10
|
38
|
+
version: "0.10"
|
39
|
+
name: chef
|
34
40
|
type: :runtime
|
41
|
+
prerelease: false
|
35
42
|
requirement: *id001
|
36
43
|
- !ruby/object:Gem::Dependency
|
37
|
-
name: rspec
|
38
|
-
prerelease: false
|
39
44
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
45
|
none: false
|
41
46
|
requirements:
|
@@ -47,7 +52,9 @@ dependencies:
|
|
47
52
|
- 6
|
48
53
|
- 0
|
49
54
|
version: 2.6.0
|
55
|
+
name: rspec
|
50
56
|
type: :runtime
|
57
|
+
prerelease: false
|
51
58
|
requirement: *id002
|
52
59
|
description: Write RSpec examples for Opscode Chef recipes
|
53
60
|
email:
|
@@ -99,6 +106,6 @@ rubyforge_project:
|
|
99
106
|
rubygems_version: 1.8.6
|
100
107
|
signing_key:
|
101
108
|
specification_version: 3
|
102
|
-
summary: chefspec-0.0
|
109
|
+
summary: chefspec-0.1.0
|
103
110
|
test_files: []
|
104
111
|
|