spectre-core 1.12.3 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c90860f8fafa6a00e51d72bfe917ea12b6ccf5d040d0696ab2701d0222375930
4
- data.tar.gz: 40b26f956b3b9f363b2e87eb913542f1c57ef6cf9981035fcd54b42b765f5d42
3
+ metadata.gz: a4bf64674e85ed8358b24a20cb06d453531cb4af450c1670dee4712bcc51fd18
4
+ data.tar.gz: 8647deb255849902fc577c846e14c3e03636dde92619915b1d216d78eef9c73c
5
5
  SHA512:
6
- metadata.gz: 93f9d8f9cd6266c53e6f91aab1d80faf3d1ae07550bf97a489e25e2597e57d8fea05b2c26637513bd80fd5824bad145f5121d25bd5a53c3c02302895a7cf9f33
7
- data.tar.gz: 32f36474db3f486a6f36ea02ec0c2291e300be67f5f6eb13ce40e73ae0af19db56cd7a34b22ec3c18cae07f3de14f4f90ccbda03f61eed3a3a1a0ff51dfb789e
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::Logger::Console',
25
- 'Spectre::Logger::File',
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
- opt_parser = OptionParser.new do |opts|
78
- opts.banner = %{Spectre #{Spectre::VERSION}
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
- list List specs
84
- run Run specs (default)
85
- show Print current environment settings
86
- dump Dumps the given environment in YAML format to console
87
- cleanup Will remove all generated files (e.g. logs and reports)
88
- init Initializes a new spectre project
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('-d', '--debug', "Run in debug mode") do
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 "\nCommon options:"
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 = YAML.load_file(global_config_file)
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 = YAML.load_file(config_file)
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 = YAML.load_file(f) || {}
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 = YAML.load_file(f)
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
- # Load Specs
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
- cfg['spec_patterns'].each do |pattern|
254
- Dir.glob(pattern).each do|f|
255
- require_relative File.join(Dir.pwd, f)
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
- colors = [:blue, :magenta, :yellow, :green]
267
- specs = Spectre.specs(cfg['specs'], cfg['tags'])
290
+ if 'list' == action
291
+ colors = [:blue, :magenta, :yellow, :green]
292
+ specs = Spectre.specs(cfg['specs'], cfg['tags'])
268
293
 
269
- exit 1 unless specs.any?
294
+ exit 1 unless specs.any?
270
295
 
271
- counter = 0
296
+ counter = 0
272
297
 
273
- specs.group_by { |x| x.subject }.each do |subject, spec_group|
274
- spec_group.each do |spec|
275
- tags = spec.tags.map { |x| '#' + x.to_s }.join ' '
276
- desc = subject.desc
277
- desc += ' - ' + spec.context.__desc + ' -' if spec.context.__desc
278
- desc += ' ' + spec.desc
279
- puts "[#{spec.name}]".send(colors[counter % colors.length]) + " #{desc} #{tags.cyan}"
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
- counter += 1
310
+ exit 0
283
311
  end
284
312
 
285
- exit 0
286
- end
287
313
 
288
-
289
- ###########################################
290
- # Run
291
- ###########################################
314
+ ###########################################
315
+ # Run
316
+ ###########################################
292
317
 
293
318
 
294
- if 'run' == action
295
- # Initialize logger
296
- now = Time.now
319
+ if 'run' == action
320
+ # Initialize logger
321
+ now = Time.now
297
322
 
298
- cfg['log_file'] = cfg['log_file'].frmt(
299
- {
300
- shortdate: now.strftime('%Y-%m-%d'),
301
- date: now.strftime('%Y-%m-%d_%H%M%S'),
302
- timestamp: now.strftime('%s'),
303
- subject: 'spectre',
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
- log_dir = File.dirname cfg['log_file']
307
- FileUtils.makedirs log_dir unless Dir.exists? log_dir
330
+ log_dir = File.dirname(cfg['log_file'])
331
+ FileUtils.makedirs(log_dir)
308
332
 
309
- # Load Modules
333
+ # Load Modules
310
334
 
311
- cfg['modules']
312
- .concat(cfg['include'])
313
- .select { |mod| !cfg['exclude'].include? mod }
314
- .each do |mod|
315
- begin
316
- mod_file = mod + '.rb'
317
- spectre_lib_mod = File.join(File.dirname(__dir__), 'lib', mod_file)
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
- if File.exists? mod_file
320
- require_relative mod_file
343
+ if File.exists? mod_file
344
+ require_relative mod_file
321
345
 
322
- elsif File.exists? spectre_lib_mod
323
- require_relative spectre_lib_mod
346
+ elsif File.exists? spectre_lib_mod
347
+ require_relative spectre_lib_mod
324
348
 
325
- else
326
- require mod
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
- # Load mixins
358
+ # Load mixins
335
359
 
336
- cfg['mixin_patterns'].each do |pattern|
337
- Dir.glob(pattern).each do|f|
338
- require_relative File.join(Dir.pwd, f)
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
- Spectre.configure(cfg)
366
+ Spectre.configure(cfg)
343
367
 
344
- Spectre::Logger.debug! if cfg['debug']
368
+ Spectre::Logging.debug! if cfg['debug']
345
369
 
346
- cfg['loggers'].each do |logger_name|
347
- logger = Kernel.const_get(logger_name).new(cfg)
348
- Spectre::Logger.add(logger)
349
- end if cfg['loggers']
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
- specs = Spectre.specs(cfg['specs'], cfg['tags'])
375
+ specs = Spectre.specs(cfg['specs'], cfg['tags'])
352
376
 
353
- unless specs.any?
354
- puts "No specs found in #{Dir.pwd}"
355
- exit 1
356
- end
377
+ unless specs.any?
378
+ puts "No specs found in #{Dir.pwd}"
379
+ exit 1
380
+ end
357
381
 
358
- run_infos = Spectre::Runner.new.run(specs)
382
+ run_infos = Spectre::Runner.new.run(specs)
359
383
 
360
- cfg['reporters'].each do |reporter|
361
- reporter = Kernel.const_get(reporter).new(cfg)
362
- reporter.report(run_infos)
363
- end
384
+ cfg['reporters'].each do |reporter|
385
+ reporter = Kernel.const_get(reporter).new(cfg)
386
+ reporter.report(run_infos)
387
+ end
364
388
 
365
- errors = run_infos.select { |x| nil != x.error or nil != x.failure }
389
+ errors = run_infos.select { |x| nil != x.error or nil != x.failure }
366
390
 
367
- exit 0 if cfg['ignore_failure'] or not errors.any?
391
+ exit 0 if cfg['ignore_failure'] or not errors.any?
368
392
 
369
- exit 1
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.should_not_be nil
529
+ response.json.message.should_not_be_empty
503
530
  end
504
531
  end
505
532
  end