spectre-core 1.12.3 → 1.14.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 +4 -4
- data/exe/spectre +134 -107
- data/lib/spectre/assertion.rb +77 -69
- data/lib/spectre/async.rb +31 -0
- data/lib/spectre/bag.rb +1 -1
- data/lib/spectre/curl.rb +4 -6
- data/lib/spectre/helpers.rb +4 -0
- data/lib/spectre/http/keystone.rb +0 -2
- data/lib/spectre/http.rb +23 -9
- data/lib/spectre/logger/console.rb +9 -3
- data/lib/spectre/logger/file.rb +26 -20
- data/lib/spectre/logger.rb +39 -12
- data/lib/spectre/mixin.rb +3 -3
- data/lib/spectre/reporter/console.rb +19 -22
- data/lib/spectre.rb +88 -58
- metadata +10 -11
- data/lib/spectre/reporter/junit.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4bf64674e85ed8358b24a20cb06d453531cb4af450c1670dee4712bcc51fd18
|
4
|
+
data.tar.gz: 8647deb255849902fc577c846e14c3e03636dde92619915b1d216d78eef9c73c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab929ce12105b08fb0e0f3180040233c2f748ec6037e71c3b59281083a8a9156b152cb07c0713e56e8d723d2c836671f37a505c6497fae48d7717eeca6008f34
|
7
|
+
data.tar.gz: acc709c87e6f5d5132f5a5ad01c4478b893479e847a5f38c2edc8fc793d411390bde9173edde3e2712e95258de5056f24511b5a2a67c51378fe39f78f4721e29
|
data/exe/spectre
CHANGED
@@ -9,8 +9,14 @@ require 'ectoplasm'
|
|
9
9
|
|
10
10
|
require_relative '../lib/spectre'
|
11
11
|
|
12
|
+
def load_yaml file_path
|
13
|
+
yaml = File.read(file_path)
|
14
|
+
YAML.safe_load(yaml, aliases: true)
|
15
|
+
end
|
16
|
+
|
12
17
|
|
13
18
|
DEFAULT_CONFIG = {
|
19
|
+
'project' => nil,
|
14
20
|
'config_file' => './spectre.yml',
|
15
21
|
'environment' => 'default',
|
16
22
|
'specs' => [],
|
@@ -21,8 +27,8 @@ DEFAULT_CONFIG = {
|
|
21
27
|
'Spectre::Reporter::Console',
|
22
28
|
],
|
23
29
|
'loggers' => [
|
24
|
-
'Spectre::
|
25
|
-
'Spectre::
|
30
|
+
'Spectre::Logging::Console',
|
31
|
+
'Spectre::Logging::File',
|
26
32
|
],
|
27
33
|
'log_file' => './logs/spectre_<date>.log',
|
28
34
|
'log_format' => {
|
@@ -49,7 +55,6 @@ DEFAULT_CONFIG = {
|
|
49
55
|
'modules' => [
|
50
56
|
'spectre/helpers',
|
51
57
|
'spectre/reporter/console',
|
52
|
-
'spectre/reporter/junit',
|
53
58
|
'spectre/logger/console',
|
54
59
|
'spectre/logger/file',
|
55
60
|
'spectre/assertion',
|
@@ -61,6 +66,7 @@ DEFAULT_CONFIG = {
|
|
61
66
|
'spectre/http/basic_auth',
|
62
67
|
'spectre/http/keystone',
|
63
68
|
'spectre/resources',
|
69
|
+
'spectre/async',
|
64
70
|
],
|
65
71
|
'include' => [
|
66
72
|
|
@@ -74,20 +80,24 @@ DEFAULT_CONFIG = {
|
|
74
80
|
cmd_options = {}
|
75
81
|
property_overrides = {}
|
76
82
|
|
77
|
-
|
78
|
-
|
83
|
+
$COMMAND = ['spectre'].concat(ARGV.clone).join(' ')
|
84
|
+
|
85
|
+
OptionParser.new do |opts|
|
86
|
+
opts.banner = <<~BANNER
|
87
|
+
Spectre #{Spectre::VERSION}
|
79
88
|
|
80
|
-
Usage: spectre [command] [options]
|
89
|
+
Usage: spectre [command] [options]
|
81
90
|
|
82
|
-
Commands:
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
91
|
+
Commands:
|
92
|
+
list List specs
|
93
|
+
run Run specs (default)
|
94
|
+
show Print current environment settings
|
95
|
+
dump Dumps the given environment in YAML format to console
|
96
|
+
cleanup Will remove all generated files (e.g. logs and reports)
|
97
|
+
init Initializes a new spectre project
|
89
98
|
|
90
|
-
Specific options:
|
99
|
+
Specific options:
|
100
|
+
BANNER
|
91
101
|
|
92
102
|
opts.on('-s SPEC,SPEC', '--specs SPEC,SPEC', Array, 'The specs to run') do |specs|
|
93
103
|
cmd_options['specs'] = specs
|
@@ -125,11 +135,17 @@ Specific options:}
|
|
125
135
|
cmd_options['out_path'] = File.absolute_path(path)
|
126
136
|
end
|
127
137
|
|
128
|
-
opts.on('-r NAME', '--reporters NAME', Array, "A list of reporters to use") do |reporters|
|
138
|
+
opts.on('-r NAME,NAME', '--reporters NAME,NAME', Array, "A list of reporters to use") do |reporters|
|
129
139
|
cmd_options['reporters'] = reporters
|
130
140
|
end
|
131
141
|
|
132
|
-
opts.on('-
|
142
|
+
opts.on('-m MODULE,MODULE', '--modules MODULE,MODULE', Array, "Load the given modules") do |modules|
|
143
|
+
modules.each do |mod|
|
144
|
+
require mod
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
opts.on('-d', '--debug', "Run in debug mode. Do not use in production!") do
|
133
149
|
cmd_options['debug'] = true
|
134
150
|
end
|
135
151
|
|
@@ -154,9 +170,9 @@ Specific options:}
|
|
154
170
|
end
|
155
171
|
end
|
156
172
|
|
157
|
-
opts.separator "\
|
173
|
+
opts.separator "\n Common options:"
|
158
174
|
|
159
|
-
opts.on_tail('--version', 'Print current installed version') do
|
175
|
+
opts.on_tail('-v', '--version', 'Print current installed version') do
|
160
176
|
puts Spectre::VERSION
|
161
177
|
exit
|
162
178
|
end
|
@@ -182,30 +198,36 @@ cfg.deep_merge! DEFAULT_CONFIG
|
|
182
198
|
global_config_file = File.join File.expand_path('~'), '.spectre'
|
183
199
|
|
184
200
|
if File.exists? global_config_file
|
185
|
-
global_options =
|
201
|
+
global_options = load_yaml(global_config_file)
|
186
202
|
cfg.deep_merge! global_options if global_options
|
187
203
|
end
|
188
204
|
|
189
205
|
config_file = cmd_options['config_file'] || cfg['config_file']
|
190
206
|
|
191
207
|
if File.exists? config_file
|
192
|
-
file_options =
|
208
|
+
file_options = load_yaml(config_file)
|
193
209
|
cfg.deep_merge! file_options
|
194
210
|
Dir.chdir File.dirname(config_file)
|
195
211
|
end
|
196
212
|
|
213
|
+
# Set config options, which are only allowed to be overriden by command options
|
214
|
+
cfg['debug'] = DEFAULT_CONFIG['debug']
|
215
|
+
|
216
|
+
# Set project name
|
217
|
+
cfg['project'] = File.basename(Dir.pwd) unless cfg['project']
|
218
|
+
|
197
219
|
cfg.deep_merge! cmd_options
|
198
220
|
|
221
|
+
|
199
222
|
###########################################
|
200
223
|
# Load Environment
|
201
224
|
###########################################
|
202
225
|
|
203
|
-
|
204
226
|
envs = {}
|
205
227
|
read_env_files = {}
|
206
228
|
cfg['env_patterns'].each do |pattern|
|
207
229
|
Dir.glob(pattern).each do|f|
|
208
|
-
spec_env =
|
230
|
+
spec_env = load_yaml(f) || {}
|
209
231
|
|
210
232
|
name = spec_env['name'] || 'default'
|
211
233
|
|
@@ -223,7 +245,7 @@ end
|
|
223
245
|
# Merge partial environment configs with existing environments
|
224
246
|
cfg['env_partial_patterns'].each do |pattern|
|
225
247
|
Dir.glob(pattern).each do|f|
|
226
|
-
partial_env =
|
248
|
+
partial_env = load_yaml(f)
|
227
249
|
name = partial_env.delete('name') || 'default'
|
228
250
|
next unless envs.key? name
|
229
251
|
|
@@ -245,128 +267,131 @@ require_relative '../lib/spectre/environment' unless cfg['exclude'].include? 'sp
|
|
245
267
|
Spectre.configure(cfg)
|
246
268
|
|
247
269
|
|
248
|
-
|
249
|
-
|
250
|
-
###########################################
|
270
|
+
# Load specs only, when listing or running specs
|
271
|
+
if ['list', 'run'].include? action
|
251
272
|
|
273
|
+
###########################################
|
274
|
+
# Load Specs
|
275
|
+
###########################################
|
252
276
|
|
253
|
-
|
254
|
-
|
255
|
-
|
277
|
+
|
278
|
+
cfg['spec_patterns'].each do |pattern|
|
279
|
+
Dir.glob(pattern).each do|f|
|
280
|
+
require_relative File.join(Dir.pwd, f)
|
281
|
+
end
|
256
282
|
end
|
257
|
-
end
|
258
283
|
|
259
284
|
|
260
|
-
###########################################
|
261
|
-
# List specs
|
262
|
-
###########################################
|
285
|
+
###########################################
|
286
|
+
# List specs
|
287
|
+
###########################################
|
263
288
|
|
264
289
|
|
265
|
-
if 'list' == action
|
266
|
-
|
267
|
-
|
290
|
+
if 'list' == action
|
291
|
+
colors = [:blue, :magenta, :yellow, :green]
|
292
|
+
specs = Spectre.specs(cfg['specs'], cfg['tags'])
|
268
293
|
|
269
|
-
|
294
|
+
exit 1 unless specs.any?
|
270
295
|
|
271
|
-
|
296
|
+
counter = 0
|
272
297
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
298
|
+
specs.group_by { |x| x.subject }.each do |subject, spec_group|
|
299
|
+
spec_group.each do |spec|
|
300
|
+
tags = spec.tags.map { |x| '#' + x.to_s }.join ' '
|
301
|
+
desc = subject.desc
|
302
|
+
desc += ' - ' + spec.context.__desc + ' -' if spec.context.__desc
|
303
|
+
desc += ' ' + spec.desc
|
304
|
+
puts "[#{spec.name}]".send(colors[counter % colors.length]) + " #{desc} #{tags.cyan}"
|
305
|
+
end
|
306
|
+
|
307
|
+
counter += 1
|
280
308
|
end
|
281
309
|
|
282
|
-
|
310
|
+
exit 0
|
283
311
|
end
|
284
312
|
|
285
|
-
exit 0
|
286
|
-
end
|
287
313
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
###########################################
|
314
|
+
###########################################
|
315
|
+
# Run
|
316
|
+
###########################################
|
292
317
|
|
293
318
|
|
294
|
-
if 'run' == action
|
295
|
-
|
296
|
-
|
319
|
+
if 'run' == action
|
320
|
+
# Initialize logger
|
321
|
+
now = Time.now
|
297
322
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
})
|
323
|
+
cfg['log_file'] = cfg['log_file'].frmt({
|
324
|
+
shortdate: now.strftime('%Y-%m-%d'),
|
325
|
+
date: now.strftime('%Y-%m-%d_%H%M%S'),
|
326
|
+
timestamp: now.strftime('%s'),
|
327
|
+
subject: 'spectre',
|
328
|
+
})
|
305
329
|
|
306
|
-
|
307
|
-
|
330
|
+
log_dir = File.dirname(cfg['log_file'])
|
331
|
+
FileUtils.makedirs(log_dir)
|
308
332
|
|
309
|
-
|
333
|
+
# Load Modules
|
310
334
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
335
|
+
cfg['modules']
|
336
|
+
.concat(cfg['include'])
|
337
|
+
.select { |mod| !cfg['exclude'].include? mod }
|
338
|
+
.each do |mod|
|
339
|
+
begin
|
340
|
+
mod_file = mod + '.rb'
|
341
|
+
spectre_lib_mod = File.join(File.dirname(__dir__), 'lib', mod_file)
|
318
342
|
|
319
|
-
|
320
|
-
|
343
|
+
if File.exists? mod_file
|
344
|
+
require_relative mod_file
|
321
345
|
|
322
|
-
|
323
|
-
|
346
|
+
elsif File.exists? spectre_lib_mod
|
347
|
+
require_relative spectre_lib_mod
|
324
348
|
|
325
|
-
|
326
|
-
|
349
|
+
else
|
350
|
+
require mod
|
351
|
+
end
|
352
|
+
rescue LoadError => e
|
353
|
+
puts "Unable to load module #{mod}. Check if the module exists or remove it from your spectre config:\n#{e.message}"
|
354
|
+
exit 1
|
327
355
|
end
|
328
|
-
rescue LoadError => e
|
329
|
-
puts "Unable to load module #{mod}. Check if the module exists or remove it from your spectre config:\n#{e.message}"
|
330
|
-
exit 1
|
331
356
|
end
|
332
|
-
end
|
333
357
|
|
334
|
-
|
358
|
+
# Load mixins
|
335
359
|
|
336
|
-
|
337
|
-
|
338
|
-
|
360
|
+
cfg['mixin_patterns'].each do |pattern|
|
361
|
+
Dir.glob(pattern).each do|f|
|
362
|
+
require_relative File.join(Dir.pwd, f)
|
363
|
+
end
|
339
364
|
end
|
340
|
-
end
|
341
365
|
|
342
|
-
|
366
|
+
Spectre.configure(cfg)
|
343
367
|
|
344
|
-
|
368
|
+
Spectre::Logging.debug! if cfg['debug']
|
345
369
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
370
|
+
cfg['loggers'].each do |logger_name|
|
371
|
+
logger = Kernel.const_get(logger_name).new(cfg)
|
372
|
+
Spectre::Logging.add(logger)
|
373
|
+
end if cfg['loggers']
|
350
374
|
|
351
|
-
|
375
|
+
specs = Spectre.specs(cfg['specs'], cfg['tags'])
|
352
376
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
377
|
+
unless specs.any?
|
378
|
+
puts "No specs found in #{Dir.pwd}"
|
379
|
+
exit 1
|
380
|
+
end
|
357
381
|
|
358
|
-
|
382
|
+
run_infos = Spectre::Runner.new.run(specs)
|
359
383
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
384
|
+
cfg['reporters'].each do |reporter|
|
385
|
+
reporter = Kernel.const_get(reporter).new(cfg)
|
386
|
+
reporter.report(run_infos)
|
387
|
+
end
|
364
388
|
|
365
|
-
|
389
|
+
errors = run_infos.select { |x| nil != x.error or nil != x.failure }
|
366
390
|
|
367
|
-
|
391
|
+
exit 0 if cfg['ignore_failure'] or not errors.any?
|
368
392
|
|
369
|
-
|
393
|
+
exit 1
|
394
|
+
end
|
370
395
|
end
|
371
396
|
|
372
397
|
|
@@ -413,10 +438,12 @@ if 'cleanup' == action
|
|
413
438
|
|
414
439
|
Dir.glob(log_file_pattern).each do |log_file|
|
415
440
|
File.delete(log_file)
|
441
|
+
puts "#{log_file} deleted"
|
416
442
|
end
|
417
443
|
|
418
444
|
Dir.glob(File.join cfg['out_path'], '/*').each do |out_file|
|
419
445
|
File.delete(out_file)
|
446
|
+
puts "#{out_file} deleted"
|
420
447
|
end
|
421
448
|
end
|
422
449
|
|
@@ -499,7 +526,7 @@ SAMPLE_SPEC = %[describe '<subject>' do
|
|
499
526
|
end
|
500
527
|
|
501
528
|
expect 'a message to exist' do
|
502
|
-
response.json.message.
|
529
|
+
response.json.message.should_not_be_empty
|
503
530
|
end
|
504
531
|
end
|
505
532
|
end
|