ecomdev-chefspec 0.1.1 → 0.1.2
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 +4 -4
- data/.rspec +1 -0
- data/Rakefile +1 -0
- data/lib/ecomdev/chefspec.rb +1 -4
- data/lib/ecomdev/chefspec/configuration.rb +39 -8
- data/lib/ecomdev/chefspec/resource/matcher.rb +15 -14
- data/lib/ecomdev/chefspec/stub/file_system.rb +1 -9
- data/lib/ecomdev/chefspec/stub/include_recipe.rb +5 -12
- data/lib/ecomdev/chefspec/version.rb +1 -1
- data/spec/unit/api/helpers/runner/proxy_spec.rb +0 -1
- data/spec/unit/api/helpers/runner_spec.rb +0 -1
- data/spec/unit/api/matchers/multiline_string_spec.rb +0 -1
- data/spec/unit/api/stubs/file_system_spec.rb +0 -1
- data/spec/unit/api/stubs/include_recipe_spec.rb +0 -1
- data/spec/unit/configuration_spec.rb +87 -21
- data/spec/unit/matcher/dsl_spec.rb +0 -2
- data/spec/unit/matcher/helper_spec.rb +0 -2
- data/spec/unit/matcher_spec.rb +0 -1
- data/spec/unit/stub/file_system_spec.rb +0 -2
- data/spec/unit/stub/include_recipe_spec.rb +1 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9855c65317cdbad908e4b3ce31121b2d92df1ccc
|
4
|
+
data.tar.gz: 506884fda82363e731a0042082bf658dc99a5fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a091b003633864e953be4c4e8cafa4fb823c408e1ed1527bbf74783d19558bf24d1383b1d33359f2d711c8eb583241be76c3bb5e8c9fa9878c0a6cd07e9412df
|
7
|
+
data.tar.gz: d00fa8ba662a776846225bde8657ee92183be41c3f4525f023c44bdf739d3d3a46b4a0a4d21175f18d2965ef4f4c02effe48024c07ab62025a81d1899b2b34fc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Rakefile
CHANGED
data/lib/ecomdev/chefspec.rb
CHANGED
@@ -3,7 +3,4 @@ require 'chefspec' unless defined?(ChefSpec) # Require chef spec only if it is n
|
|
3
3
|
require_relative 'chefspec/version'
|
4
4
|
require_relative 'chefspec/configuration'
|
5
5
|
require_relative 'chefspec/resource/matcher'
|
6
|
-
require_relative 'chefspec/api'
|
7
|
-
|
8
|
-
# Registers Resource Matchers callbacks for RSpec
|
9
|
-
EcomDev::ChefSpec::Resource::Matcher.register
|
6
|
+
require_relative 'chefspec/api'
|
@@ -3,7 +3,7 @@ module EcomDev
|
|
3
3
|
class Configuration
|
4
4
|
class << self
|
5
5
|
extend Forwardable
|
6
|
-
def_delegators :instance, :reset, :setup!, :teardown!, :cookbook_path, :callback
|
6
|
+
def_delegators :instance, :reset, :setup!, :teardown!, :before_example, :after_example, :cookbook_path, :callback
|
7
7
|
end
|
8
8
|
|
9
9
|
include Singleton
|
@@ -39,9 +39,17 @@ module EcomDev
|
|
39
39
|
invoke_callbacks(__method__)
|
40
40
|
end
|
41
41
|
|
42
|
+
def before_example(example)
|
43
|
+
invoke_callbacks(__method__, example)
|
44
|
+
end
|
45
|
+
|
46
|
+
def after_example(example)
|
47
|
+
invoke_callbacks(__method__, example)
|
48
|
+
end
|
49
|
+
|
42
50
|
def reset
|
43
|
-
|
44
|
-
|
51
|
+
@cookbook_paths = []
|
52
|
+
@callbacks = []
|
45
53
|
end
|
46
54
|
|
47
55
|
def cookbook_path(path)
|
@@ -64,23 +72,46 @@ module EcomDev
|
|
64
72
|
if klass
|
65
73
|
klass.class_exec do
|
66
74
|
alias_method :old_setup!, :setup!
|
75
|
+
alias_method :old_teardown!, :teardown!
|
67
76
|
|
68
77
|
def setup!
|
69
78
|
old_setup!
|
70
79
|
EcomDev::ChefSpec::Configuration.setup!
|
71
80
|
end
|
81
|
+
|
82
|
+
def teardown!
|
83
|
+
old_teardown!
|
84
|
+
EcomDev::ChefSpec::Configuration.teardown!
|
85
|
+
end
|
72
86
|
end
|
73
87
|
else
|
74
|
-
RSpec.configure do
|
75
|
-
before(:suite) { EcomDev::ChefSpec::Configuration.setup! }
|
88
|
+
RSpec.configure do |config|
|
89
|
+
config.before(:suite) { EcomDev::ChefSpec::Configuration.setup! }
|
90
|
+
config.after(:suite) { EcomDev::ChefSpec::Configuration.teardown! }
|
76
91
|
end
|
77
92
|
end
|
93
|
+
|
94
|
+
RSpec.configure do |config|
|
95
|
+
config.before(:each) { EcomDev::ChefSpec::Configuration.before_example(self) }
|
96
|
+
config.after(:each) { EcomDev::ChefSpec::Configuration.after_example(self) }
|
97
|
+
end
|
78
98
|
end
|
79
99
|
|
80
100
|
private
|
81
|
-
def invoke_callbacks(method)
|
82
|
-
callbacks.select { |c| c.respond_to?(method) }.each
|
101
|
+
def invoke_callbacks(method, *args)
|
102
|
+
callbacks.select { |c| c.respond_to?(method) }.each do |c|
|
103
|
+
method_instance = c.class.instance_method(method)
|
104
|
+
number_of_args = method_instance.arity < 0 ? (method_instance.arity + 1).abs : method_instance.arity
|
105
|
+
if args.length > number_of_args
|
106
|
+
pass_args = args.slice(0, number_of_args)
|
107
|
+
else
|
108
|
+
pass_args = args
|
109
|
+
end
|
110
|
+
c.send(method, *pass_args)
|
111
|
+
end
|
83
112
|
end
|
84
113
|
end
|
85
114
|
end
|
86
|
-
end
|
115
|
+
end
|
116
|
+
|
117
|
+
EcomDev::ChefSpec::Configuration.register
|
@@ -40,7 +40,7 @@ module EcomDev
|
|
40
40
|
def extend_api
|
41
41
|
matchers.each do |method, info|
|
42
42
|
Helper.add(method) do |identity|
|
43
|
-
ChefSpec::Matchers::ResourceMatcher.new(info
|
43
|
+
::ChefSpec::Matchers::ResourceMatcher.new(info[:resource], info[:action], identity)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -75,7 +75,7 @@ module EcomDev
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def load_matcher_file(file)
|
78
|
-
|
78
|
+
DSL.load(file)
|
79
79
|
end
|
80
80
|
|
81
81
|
def search_patterns
|
@@ -105,22 +105,23 @@ module EcomDev
|
|
105
105
|
end
|
106
106
|
|
107
107
|
private
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
108
|
+
def add_matcher(resource, action)
|
109
|
+
resource_name = resource.to_s
|
110
|
+
action_name = action.to_s
|
111
|
+
matcher_name = action_name + '_' + resource_name
|
112
|
+
matcher = matcher_name.to_sym
|
113
|
+
unless @matchers.key?(matcher)
|
114
|
+
@matchers[matcher] = {action: action_name.to_sym, resource: resource_name.to_sym}
|
116
115
|
end
|
116
|
+
end
|
117
117
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
def add_runner(resource_name)
|
119
|
+
resource = resource_name.to_sym
|
120
|
+
@runners << resource unless @runners.include?(resource)
|
121
|
+
end
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
EcomDev::ChefSpec::Resource::Matcher.register
|
@@ -64,12 +64,4 @@ module EcomDev::ChefSpec::Stub
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
|
68
|
-
c.before(:each) do
|
69
|
-
EcomDev::ChefSpec::Stub::FileSystem.instance.before_example(self)
|
70
|
-
end
|
71
|
-
|
72
|
-
c.after(:each) do
|
73
|
-
EcomDev::ChefSpec::Stub::FileSystem.instance.after_example
|
74
|
-
end
|
75
|
-
end
|
67
|
+
EcomDev::ChefSpec::Configuration.callback(EcomDev::ChefSpec::Stub::FileSystem.instance)
|
@@ -24,6 +24,10 @@ module EcomDev::ChefSpec::Stub
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def before_example(object)
|
27
|
+
if object.respond_to?(:described_recipe) && object.described_recipe.match(/^[a-z_0-9]+::[a-z_0-9]+$/)
|
28
|
+
allow_recipe(object.described_recipe)
|
29
|
+
end
|
30
|
+
|
27
31
|
stub_include(object) unless allowed_recipes.empty?
|
28
32
|
end
|
29
33
|
|
@@ -57,15 +61,4 @@ module EcomDev::ChefSpec::Stub
|
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
|
-
|
61
|
-
c.before(:each) do
|
62
|
-
if respond_to?(:described_recipe) && described_recipe.match(/^[a-z_0-9]+::[a-z_0-9]+$/)
|
63
|
-
EcomDev::ChefSpec::Stub::IncludeRecipe.allow_recipe described_recipe
|
64
|
-
end
|
65
|
-
EcomDev::ChefSpec::Stub::IncludeRecipe.instance.before_example(self)
|
66
|
-
end
|
67
|
-
|
68
|
-
c.after(:each) do
|
69
|
-
EcomDev::ChefSpec::Stub::IncludeRecipe.instance.after_example(self)
|
70
|
-
end
|
71
|
-
end
|
64
|
+
EcomDev::ChefSpec::Configuration.callback(EcomDev::ChefSpec::Stub::IncludeRecipe.instance)
|
@@ -1,10 +1,15 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe EcomDev::ChefSpec::Configuration do
|
4
2
|
before(:each) do
|
3
|
+
@_instance = described_class.instance
|
5
4
|
Singleton.__init__(described_class)
|
6
5
|
end
|
7
6
|
|
7
|
+
after(:each) do
|
8
|
+
described_class.instance_variable_set(:@singleton__instance__, @_instance)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
|
8
13
|
def callback_klass
|
9
14
|
Class.new
|
10
15
|
end
|
@@ -96,43 +101,104 @@ describe EcomDev::ChefSpec::Configuration do
|
|
96
101
|
end
|
97
102
|
|
98
103
|
it 'calls a callback method setup! if it exists' do
|
99
|
-
callback =
|
104
|
+
callback = Class.new do
|
105
|
+
def setup!
|
106
|
+
'test'
|
107
|
+
end
|
108
|
+
end.new
|
100
109
|
|
101
|
-
allow(callback).to receive(:respond_to?).with(:setup!).and_return(true)
|
102
110
|
expect(callback).to receive(:setup!)
|
103
111
|
described_class.callback(callback)
|
104
112
|
described_class.setup!
|
105
113
|
end
|
106
|
-
|
107
|
-
it 'does not call a callback method setup! if it is not defined' do
|
108
|
-
callback = double('callback')
|
109
|
-
|
110
|
-
allow(callback).to receive(:respond_to?).with(:setup!).and_return(false)
|
111
|
-
expect(callback).not_to receive(:setup!)
|
112
|
-
|
113
|
-
described_class.callback(callback)
|
114
|
-
described_class.setup!
|
115
|
-
end
|
116
114
|
end
|
117
115
|
|
118
116
|
describe '#teardown!' do
|
119
117
|
it 'calls a callback method teardown! if it exists' do
|
120
|
-
callback =
|
118
|
+
callback = Class.new do
|
119
|
+
def teardown!
|
120
|
+
'test'
|
121
|
+
end
|
122
|
+
end.new
|
121
123
|
|
122
|
-
allow(callback).to receive(:respond_to?).with(:teardown!).and_return(true)
|
123
124
|
expect(callback).to receive(:teardown!)
|
124
125
|
described_class.callback(callback)
|
125
126
|
described_class.teardown!
|
126
127
|
end
|
128
|
+
end
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
+
describe '#before_example' do
|
131
|
+
it 'calls a callback method before_example if it exists with self as an argument' do
|
132
|
+
callback = Class.new do
|
133
|
+
def before_example(example)
|
134
|
+
example
|
135
|
+
end
|
136
|
+
end.new
|
130
137
|
|
131
|
-
|
132
|
-
|
138
|
+
expect(callback).to receive(:before_example).with(self)
|
139
|
+
described_class.callback(callback)
|
140
|
+
described_class.before_example(self)
|
141
|
+
end
|
133
142
|
|
143
|
+
it 'calls a callback method before_example without arguments, if it does not take any' do
|
144
|
+
callback = Class.new do
|
145
|
+
def before_example
|
146
|
+
'test'
|
147
|
+
end
|
148
|
+
end.new
|
149
|
+
|
150
|
+
expect(callback).to receive(:before_example).with(no_args)
|
134
151
|
described_class.callback(callback)
|
135
|
-
described_class.
|
152
|
+
described_class.before_example(self)
|
136
153
|
end
|
154
|
+
|
155
|
+
|
137
156
|
end
|
157
|
+
|
158
|
+
describe '#after_example' do
|
159
|
+
it 'calls a callback method before_example if it exists with self as an argument' do
|
160
|
+
callback = Class.new do
|
161
|
+
def after_example(example)
|
162
|
+
example
|
163
|
+
end
|
164
|
+
end.new
|
165
|
+
|
166
|
+
expect(callback).to receive(:after_example).with(self)
|
167
|
+
described_class.callback(callback)
|
168
|
+
described_class.after_example(self)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'calls a callback method before_example without arguments, if it does not take any' do
|
172
|
+
callback = Class.new do
|
173
|
+
def after_example
|
174
|
+
'test'
|
175
|
+
end
|
176
|
+
end.new
|
177
|
+
|
178
|
+
expect(callback).to receive(:after_example).with(no_args)
|
179
|
+
described_class.callback(callback)
|
180
|
+
described_class.after_example(self)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when callbacks are not having defined methods' do
|
185
|
+
[:setup!, :teardown!, :before_example, :after_example].each do |method|
|
186
|
+
describe '#' + method.to_s do
|
187
|
+
it 'does not call a callback method '+ method.to_s + ' if it is not defined' do
|
188
|
+
callback = double('callback')
|
189
|
+
|
190
|
+
allow(callback).to receive(:respond_to?).with(anything).and_return(false)
|
191
|
+
expect(callback).not_to receive(method)
|
192
|
+
|
193
|
+
described_class.callback(callback)
|
194
|
+
if described_class.instance_method(method).arity == 1
|
195
|
+
described_class.send(method, self)
|
196
|
+
else
|
197
|
+
described_class.send(method)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
138
204
|
end
|
data/spec/unit/matcher_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe EcomDev::ChefSpec::Stub::IncludeRecipe do
|
4
2
|
describe '#allow_recipe' do
|
5
3
|
it 'should add recipe to the list of allowed' do
|
@@ -16,7 +14,7 @@ describe EcomDev::ChefSpec::Stub::IncludeRecipe do
|
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
|
-
context 'when there is a described recipe'
|
17
|
+
context 'when there is a described recipe' do
|
20
18
|
let (:runner) { ChefSpec::Runner.new }
|
21
19
|
let (:described_recipe) { 'test::test' }
|
22
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecomdev-chefspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Chepurnyi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chefspec
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- ".rspec"
|
64
65
|
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|