cheffish 1.2.1 → 1.3.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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85b4f608f3cf8b32a827f1b538c2cf7ef9185c8c
|
4
|
+
data.tar.gz: 0c382ad53c007730730a591967628e507c8be51c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bed951a0243067a3ada2a3f073d788a4569d17f08f01ac7f76c6c148dca626e6f1b468cad947848ec548bd1ad723e14469bb8261d4be84567c3eb633cc4dc9d
|
7
|
+
data.tar.gz: a8e7ac0b4ac306e32a9ccee854ef09ad71732b9ca8f87840246955b494a76e210c3a66b63f03e14d24881ab5d8a068486dd52b470c3c486314fac23707b83a91
|
@@ -47,23 +47,29 @@ module Cheffish
|
|
47
47
|
{}
|
48
48
|
end
|
49
49
|
|
50
|
-
def expect_recipe(&recipe)
|
51
|
-
r = recipe(&recipe)
|
50
|
+
def expect_recipe(str=nil, file=nil, line=nil, &recipe)
|
51
|
+
r = recipe(str, file, line, &recipe)
|
52
52
|
r.converge
|
53
53
|
expect(r)
|
54
54
|
end
|
55
55
|
|
56
|
-
def expect_converge(&recipe)
|
57
|
-
|
58
|
-
expect { r.converge }
|
56
|
+
def expect_converge(str=nil, file=nil, line=nil, &recipe)
|
57
|
+
expect { converge(str, file, line, &recipe) }
|
59
58
|
end
|
60
59
|
|
61
|
-
def recipe(&recipe)
|
60
|
+
def recipe(str=nil, file=nil, line=nil, &recipe)
|
61
|
+
if !recipe
|
62
|
+
if file && line
|
63
|
+
recipe = proc { eval(str, nil, file, line) }
|
64
|
+
else
|
65
|
+
recipe = proc { eval(str) }
|
66
|
+
end
|
67
|
+
end
|
62
68
|
RecipeRunWrapper.new(chef_config, &recipe)
|
63
69
|
end
|
64
70
|
|
65
|
-
def converge(&recipe)
|
66
|
-
r =
|
71
|
+
def converge(str=nil, file=nil, line=nil, &recipe)
|
72
|
+
r = recipe(str, file, line, &recipe)
|
67
73
|
r.converge
|
68
74
|
r
|
69
75
|
end
|
@@ -3,16 +3,41 @@ require 'cheffish/chef_run'
|
|
3
3
|
module Cheffish
|
4
4
|
module RSpec
|
5
5
|
class RecipeRunWrapper < ChefRun
|
6
|
-
def initialize(chef_config, &recipe)
|
6
|
+
def initialize(chef_config, example: nil, &recipe)
|
7
7
|
super(chef_config)
|
8
8
|
@recipe = recipe
|
9
|
+
@example = example || recipe.binding.eval('self')
|
9
10
|
end
|
10
11
|
|
11
12
|
attr_reader :recipe
|
13
|
+
attr_reader :example
|
12
14
|
|
13
15
|
def client
|
14
16
|
if !@client
|
15
17
|
super
|
18
|
+
example = self.example
|
19
|
+
|
20
|
+
# Call into the rspec example's let variables and other methods
|
21
|
+
@client.define_singleton_method(:method_missing) do |name, *args, &block|
|
22
|
+
if example.respond_to?(name)
|
23
|
+
example.public_send(name, *args, &block)
|
24
|
+
else
|
25
|
+
super(name, *args, &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# This is called by respond_to?, and is required to make sure the
|
29
|
+
# resource knows that we will in fact call the given method.
|
30
|
+
@client.define_singleton_method(:respond_to_missing?) do |name, include_private = false|
|
31
|
+
example.respond_to?(name)
|
32
|
+
end
|
33
|
+
# Respond true to is_a?(Chef::Provider) so that Chef::Recipe::DSL.build_resource
|
34
|
+
# will hook resources up to the example let variables as well (via
|
35
|
+
# enclosing_provider).
|
36
|
+
# Please don't hurt me
|
37
|
+
@client.define_singleton_method(:is_a?) do |klass|
|
38
|
+
klass == Chef::Provider || super
|
39
|
+
end
|
40
|
+
|
16
41
|
@client.load_block(&recipe)
|
17
42
|
end
|
18
43
|
@client
|
data/lib/cheffish/version.rb
CHANGED
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'support/spec_support'
|
2
|
+
require 'cheffish/rspec/chef_run_support'
|
3
|
+
|
4
|
+
describe 'Cheffish::RSpec::ChefRunSupport' do
|
5
|
+
extend Cheffish::RSpec::ChefRunSupport
|
6
|
+
|
7
|
+
let(:tempfile) { Tempfile.new('test') }
|
8
|
+
|
9
|
+
context "#recipe" do
|
10
|
+
it "recipe { file ... } updates the file" do
|
11
|
+
result = recipe {
|
12
|
+
file tempfile.path do
|
13
|
+
content 'test'
|
14
|
+
end
|
15
|
+
}
|
16
|
+
expect(result.updated?).to be_falsey
|
17
|
+
expect(IO.read(tempfile.path)).to eq ''
|
18
|
+
end
|
19
|
+
|
20
|
+
it "recipe 'file ...' updates the file" do
|
21
|
+
result = recipe <<-EOM
|
22
|
+
file tempfile.path do
|
23
|
+
content 'test'
|
24
|
+
end
|
25
|
+
EOM
|
26
|
+
expect(result.updated?).to be_falsey
|
27
|
+
expect(IO.read(tempfile.path)).to eq ''
|
28
|
+
end
|
29
|
+
|
30
|
+
it "recipe 'file ...' with file and line number updates the file" do
|
31
|
+
result = recipe(<<-EOM, __FILE__, __LINE__+1)
|
32
|
+
file tempfile.path do
|
33
|
+
content 'test'
|
34
|
+
end
|
35
|
+
EOM
|
36
|
+
expect(result.updated?).to be_falsey
|
37
|
+
expect(IO.read(tempfile.path)).to eq ''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "#converge" do
|
42
|
+
it "converge { file ... } updates the file" do
|
43
|
+
result = converge {
|
44
|
+
file tempfile.path do
|
45
|
+
content 'test'
|
46
|
+
end
|
47
|
+
}
|
48
|
+
expect(result.updated?).to be_truthy
|
49
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "converge 'file ...' updates the file" do
|
53
|
+
result = converge <<-EOM
|
54
|
+
file tempfile.path do
|
55
|
+
content 'test'
|
56
|
+
end
|
57
|
+
EOM
|
58
|
+
expect(result.updated?).to be_truthy
|
59
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "converge 'file ...' with file and line number updates the file" do
|
63
|
+
result = converge(<<-EOM, __FILE__, __LINE__+1)
|
64
|
+
file tempfile.path do
|
65
|
+
content 'test'
|
66
|
+
end
|
67
|
+
EOM
|
68
|
+
expect(result.updated?).to be_truthy
|
69
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "#expect_recipe" do
|
74
|
+
it "expect_recipe { file ... }.to be_updated updates the file, and be_idempotent does not fail" do
|
75
|
+
expect_recipe {
|
76
|
+
file tempfile.path do
|
77
|
+
content 'test'
|
78
|
+
end
|
79
|
+
}.to be_updated.and be_idempotent
|
80
|
+
|
81
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
82
|
+
end
|
83
|
+
|
84
|
+
it "expect_recipe 'file ...'.to be_updated updates the file, and be_idempotent does not fail" do
|
85
|
+
expect_recipe(<<-EOM).to be_updated.and be_idempotent
|
86
|
+
file tempfile.path do
|
87
|
+
content 'test'
|
88
|
+
end
|
89
|
+
EOM
|
90
|
+
|
91
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "expect_recipe('file ...', file, line).to be_updated updates the file, and be_idempotent does not fail" do
|
95
|
+
expect_recipe(<<-EOM, __FILE__, __LINE__+1).to be_updated.and be_idempotent
|
96
|
+
file tempfile.path do
|
97
|
+
content 'test'
|
98
|
+
end
|
99
|
+
EOM
|
100
|
+
|
101
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "expect_recipe { file ... }.to be_up_to_date fails" do
|
105
|
+
expect {
|
106
|
+
expect_recipe {
|
107
|
+
file tempfile.path do
|
108
|
+
content 'test'
|
109
|
+
end
|
110
|
+
}.to be_up_to_date
|
111
|
+
}.to raise_error
|
112
|
+
end
|
113
|
+
|
114
|
+
it "expect_recipe { }.to be_updated fails" do
|
115
|
+
expect {
|
116
|
+
expect_recipe { }.to be_updated
|
117
|
+
}.to raise_error
|
118
|
+
end
|
119
|
+
|
120
|
+
it "expect_recipe { }.to be_up_to_date succeeds" do
|
121
|
+
expect_recipe { }.to be_up_to_date
|
122
|
+
end
|
123
|
+
|
124
|
+
it "expect_recipe { }.to be_idempotent succeeds" do
|
125
|
+
expect_recipe { }.to be_idempotent
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "#expect_converge" do
|
130
|
+
it "expect_converge { file ... }.not_to raise_error updates the file" do
|
131
|
+
expect_converge {
|
132
|
+
file tempfile.path do
|
133
|
+
content 'test'
|
134
|
+
end
|
135
|
+
}.not_to raise_error
|
136
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "expect_converge('file ...').not_to raise_error updates the file" do
|
140
|
+
expect_converge(<<-EOM).not_to raise_error
|
141
|
+
file tempfile.path do
|
142
|
+
content 'test'
|
143
|
+
end
|
144
|
+
EOM
|
145
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
146
|
+
end
|
147
|
+
|
148
|
+
it "expect_converge('file ...', file, line).not_to raise_error updates the file" do
|
149
|
+
expect_converge(<<-EOM, __FILE__, __LINE__+1).not_to raise_error
|
150
|
+
file tempfile.path do
|
151
|
+
content 'test'
|
152
|
+
end
|
153
|
+
EOM
|
154
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
155
|
+
end
|
156
|
+
|
157
|
+
it "expect_converge { raise 'oh no' }.to raise_error passes" do
|
158
|
+
expect_converge {
|
159
|
+
raise 'oh no'
|
160
|
+
}.to raise_error
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when there is a let variable" do
|
165
|
+
let(:let_variable) { "test" }
|
166
|
+
|
167
|
+
it "converge { let_variable } accesses it" do
|
168
|
+
# Capture the variable outside
|
169
|
+
x = nil
|
170
|
+
converge { x = let_variable }
|
171
|
+
expect(x).to eq 'test'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "converge with a file resource referencing let_variable accesses let_variable" do
|
175
|
+
converge {
|
176
|
+
file tempfile.path do
|
177
|
+
content let_variable
|
178
|
+
end
|
179
|
+
}
|
180
|
+
expect(IO.read(tempfile.path)).to eq 'test'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheffish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-zero
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- spec/integration/chef_user_spec.rb
|
142
142
|
- spec/integration/private_key_spec.rb
|
143
143
|
- spec/integration/recipe_dsl_spec.rb
|
144
|
+
- spec/integration/rspec/converge_spec.rb
|
144
145
|
- spec/support/key_support.rb
|
145
146
|
- spec/support/spec_support.rb
|
146
147
|
- spec/unit/get_private_key_spec.rb
|
@@ -163,8 +164,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
166
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.4.
|
167
|
+
rubygems_version: 2.4.5
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: A library to manipulate Chef in Chef.
|
170
171
|
test_files: []
|
172
|
+
has_rdoc:
|