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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c58f9d004b789d825cc778750855a9aa2e71a661
4
- data.tar.gz: 8fd41e808e4df754f1ca203d8cde61e03bf7b669
3
+ metadata.gz: 9855c65317cdbad908e4b3ce31121b2d92df1ccc
4
+ data.tar.gz: 506884fda82363e731a0042082bf658dc99a5fc7
5
5
  SHA512:
6
- metadata.gz: 161d79a0c32946662eb7114c18b0fdbf0d90433da2a333c527130fc2139e3744ae0dcf8e83744649d3f975753629144f9d26e0ec6ad113aa5d31d917d4baacb3
7
- data.tar.gz: 7ccf603f119bad18cbf7d04232b76724277358ac7873c6b8dbde822a24923a9e05c3cf4f866271ef9e86fa2e58c594a0cccc90bd3bc59ba41f70cb8c4909b7f2
6
+ metadata.gz: a091b003633864e953be4c4e8cafa4fb823c408e1ed1527bbf74783d19558bf24d1383b1d33359f2d711c8eb583241be76c3bb5e8c9fa9878c0a6cd07e9412df
7
+ data.tar.gz: d00fa8ba662a776846225bde8657ee92183be41c3f4525f023c44bdf739d3d3a46b4a0a4d21175f18d2965ef4f4c02effe48024c07ab62025a81d1899b2b34fc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ RSpec::Core::RakeTask.new(:unit) do |t|
5
5
  t.rspec_opts = [].tap do |a|
6
6
  a.push('--color')
7
7
  a.push('--format progress')
8
+ a.push('--require spec_helper')
8
9
  end.join(' ')
9
10
  end
10
11
 
@@ -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
- @cookbook_paths = []
44
- @callbacks = []
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 { |c| c.send(method) }
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.resource, info.action, identity)
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
- DSL.load(file)
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
- 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}
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
- def add_runner(resource_name)
119
- resource = resource_name.to_sym
120
- @runners << resource unless @runners.include?(resource)
121
- end
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
- RSpec.configure do |c|
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
- RSpec.configure do |c|
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,6 +1,6 @@
1
1
 
2
2
  module EcomDev
3
3
  module ChefSpec
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
  end
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe ChefSpec::API::EcomDevHelpersRunner::RunnerProxy do
4
3
  it 'does not create any method unless method of runner is executed' do
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe ChefSpec::API::EcomDevHelpersRunner do
4
3
  it 'returns a chef runner proxy class' do
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe ChefSpec::API::EcomDevMatcherMultilineString do
4
3
  it 'should allow match line starts with' do
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe ChefSpec::API::EcomDevStubsFileSystem do
4
3
  describe '#file_exists' do
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe 'test::test' do
4
3
  let (:instance) { 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 = double('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 = double('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
- it 'does not call a callback method teardown! if it is not defined' do
129
- callback = double('callback')
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
- allow(callback).to receive(:respond_to?).with(:teardown!).and_return(false)
132
- expect(callback).not_to receive(:teardown!)
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.teardown!
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
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe EcomDev::ChefSpec::Resource::Matcher::DSL do
4
2
  let(:instance) { described_class.new }
5
3
  let(:matcher) { EcomDev::ChefSpec::Resource::Matcher }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe EcomDev::ChefSpec::Resource::Matcher::Helper do
4
2
 
5
3
  def create_method_body
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe EcomDev::ChefSpec::Resource::Matcher do
4
3
  before(:each) do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe EcomDev::ChefSpec::Stub::FileSystem do
4
2
  describe '#before_example' do
5
3
  it 'sets current example before' do
@@ -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', :allow_recipe => true do
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.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-18 00:00:00.000000000 Z
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