84
84
end
85
85
86
86
describe '.fixtures' do
87
+ subject ( :helper ) { described_class }
88
+
87
89
before :each do
88
90
# Unstub the fixtures "helpers"
89
91
PuppetlabsSpec ::Fixtures . instance_methods . each do |m |
98
100
99
101
context 'when file is missing' do
100
102
it 'returns basic directories per category' do
101
- expect ( subject . fixtures ( 'forge_modules' ) ) . to eq ( { } )
102
- expect ( subject . fixtures ( 'repositories' ) ) . to eq ( { } )
103
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to eq ( { } )
104
+ expect ( helper . fixtures ( 'repositories' ) ) . to eq ( { } )
103
105
end
104
106
end
105
107
106
108
context 'when file is empty' do
107
109
it 'returns basic directories per category' do
108
110
allow ( File ) . to receive ( :exist? ) . with ( '.fixtures.yml' ) . and_return true
109
111
allow ( YAML ) . to receive ( :load_file ) . with ( '.fixtures.yml' ) . and_return false
110
- expect ( subject . fixtures ( 'forge_modules' ) ) . to eq ( { } )
111
- expect ( subject . fixtures ( 'repositories' ) ) . to eq ( { } )
112
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to eq ( { } )
113
+ expect ( helper . fixtures ( 'repositories' ) ) . to eq ( { } )
112
114
end
113
115
end
114
116
115
117
context 'when file is malformed' do
116
118
it 'raises an error' do
117
119
expect ( File ) . to receive ( :exist? ) . with ( '.fixtures.yml' ) . and_return true
118
120
expect ( YAML ) . to receive ( :load_file ) . with ( '.fixtures.yml' ) . and_raise ( Psych ::SyntaxError . new ( '/file' , '123' , '0' , '0' , 'spec message' , 'spec context' ) )
119
- expect { subject . fixtures ( 'forge_modules' ) } . to raise_error ( RuntimeError , %r{malformed YAML} )
121
+ expect { helper . fixtures ( 'forge_modules' ) } . to raise_error ( RuntimeError , %r{malformed YAML} )
120
122
end
121
123
end
122
124
123
125
context 'when file contains no fixtures' do
124
126
it 'raises an error' do
125
127
allow ( File ) . to receive ( :exist? ) . with ( '.fixtures.yml' ) . and_return true
126
128
allow ( YAML ) . to receive ( :load_file ) . with ( '.fixtures.yml' ) . and_return ( 'some' => 'key' )
127
- expect { subject . fixtures ( 'forge_modules' ) } . to raise_error ( RuntimeError , %r{No 'fixtures'} )
129
+ expect { helper . fixtures ( 'forge_modules' ) } . to raise_error ( RuntimeError , %r{No 'fixtures'} )
128
130
end
129
131
end
130
132
131
133
context 'when file specifies fixtures' do
132
134
it 'returns the hash' do
133
135
allow ( File ) . to receive ( :exist? ) . with ( '.fixtures.yml' ) . and_return true
134
136
allow ( YAML ) . to receive ( :load_file ) . with ( '.fixtures.yml' ) . and_return ( 'fixtures' => { 'forge_modules' => { 'stdlib' => 'puppetlabs-stdlib' } } )
135
- expect ( subject . fixtures ( 'forge_modules' ) ) . to eq ( 'puppetlabs-stdlib' => {
136
- 'target' => 'spec/fixtures/modules/stdlib' ,
137
- 'ref' => nil ,
138
- 'branch' => nil ,
139
- 'scm' => nil ,
140
- 'flags' => nil ,
141
- 'subdir' => nil ,
142
- } )
137
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to eq (
138
+ 'puppetlabs-stdlib' => {
139
+ 'target' => 'spec/fixtures/modules/stdlib' ,
140
+ 'ref' => nil ,
141
+ 'branch' => nil ,
142
+ 'scm' => nil ,
143
+ 'flags' => nil ,
144
+ 'subdir' => nil ,
145
+ } ,
146
+ )
143
147
end
144
148
end
145
149
148
152
allow ( File ) . to receive ( :exist? ) . with ( '.fixtures.yml' ) . and_return true
149
153
allow ( YAML ) . to receive ( :load_file ) . with ( '.fixtures.yml' ) . and_return ( 'defaults' => { 'forge_modules' => { 'flags' => '--module_repository=https://myforge.example.com/' } } ,
150
154
'fixtures' => { 'forge_modules' => { 'stdlib' => 'puppetlabs-stdlib' } } )
151
- expect ( subject . fixtures ( 'forge_modules' ) ) . to eq ( 'puppetlabs-stdlib' => {
152
- 'target' => 'spec/fixtures/modules/stdlib' ,
153
- 'ref' => nil ,
154
- 'branch' => nil ,
155
- 'scm' => nil ,
156
- 'flags' => '--module_repository=https://myforge.example.com/' ,
157
- 'subdir' => nil ,
158
- } )
155
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to eq (
156
+ 'puppetlabs-stdlib' => {
157
+ 'target' => 'spec/fixtures/modules/stdlib' ,
158
+ 'ref' => nil ,
159
+ 'branch' => nil ,
160
+ 'scm' => nil ,
161
+ 'flags' => '--module_repository=https://myforge.example.com/' ,
162
+ 'subdir' => nil ,
163
+ } ,
164
+ )
159
165
end
160
166
end
161
167
170
176
end
171
177
172
178
it 'returns the hash' do
173
- expect ( subject . repositories ) . to eq ( 'https://github.com/puppetlabs/puppetlabs-stdlib.git' => {
174
- 'target' => 'spec/fixtures/modules/stdlib' ,
175
- 'ref' => nil ,
176
- 'branch' => nil ,
177
- 'scm' => nil ,
178
- 'flags' => nil ,
179
- 'subdir' => nil ,
180
- } )
179
+ expect ( helper . repositories ) . to eq (
180
+ 'https://github.com/puppetlabs/puppetlabs-stdlib.git' => {
181
+ 'target' => 'spec/fixtures/modules/stdlib' ,
182
+ 'ref' => nil ,
183
+ 'branch' => nil ,
184
+ 'scm' => nil ,
185
+ 'flags' => nil ,
186
+ 'subdir' => nil ,
187
+ } ,
188
+ )
181
189
end
182
190
end
183
191
198
206
end
199
207
200
208
it 'raises an ArgumentError' do
201
- expect { subject . fixtures ( 'repositories' ) } . to raise_error ( ArgumentError )
209
+ expect { helper . fixtures ( 'repositories' ) } . to raise_error ( ArgumentError )
202
210
end
203
211
end
204
212
@@ -219,7 +227,7 @@ def stub_fixtures(data)
219
227
} ,
220
228
} ,
221
229
)
222
- expect ( subject . fixtures ( 'forge_modules' ) ) . to include ( 'puppetlabs-stdlib' )
230
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to include ( 'puppetlabs-stdlib' )
223
231
end
224
232
225
233
it 'excludes the fixture if the puppet version does not match' , if : Gem ::Version . new ( Puppet ::PUPPETVERSION ) > Gem ::Version . new ( '4' ) do
@@ -233,7 +241,7 @@ def stub_fixtures(data)
233
241
} ,
234
242
} ,
235
243
)
236
- expect ( subject . fixtures ( 'forge_modules' ) ) . to eq ( { } )
244
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to eq ( { } )
237
245
end
238
246
239
247
it 'includes the fixture on obsolete puppet versions' , if : Gem ::Version . new ( Puppet ::PUPPETVERSION ) <= Gem ::Version . new ( '4' ) do
@@ -247,7 +255,7 @@ def stub_fixtures(data)
247
255
} ,
248
256
} ,
249
257
)
250
- expect ( subject . fixtures ( 'forge_modules' ) ) . to include ( 'puppetlabs-stdlib' )
258
+ expect ( helper . fixtures ( 'forge_modules' ) ) . to include ( 'puppetlabs-stdlib' )
251
259
end
252
260
end
253
261
end
0 commit comments