spectre-core 1.13.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd2c5dd03f2ded27246d351696a749bf0f0fbb06ff87ecc27363873202ecb1ac
4
- data.tar.gz: a17d75c2581c6f64f58664b78c68449936610f8fa9c6c313dc73011da59094c6
3
+ metadata.gz: a4bf64674e85ed8358b24a20cb06d453531cb4af450c1670dee4712bcc51fd18
4
+ data.tar.gz: 8647deb255849902fc577c846e14c3e03636dde92619915b1d216d78eef9c73c
5
5
  SHA512:
6
- metadata.gz: 941692c923f0437410ad99376a1df249c81dd970c527445e9a4e3721554e35e2f6d10cca4f23293894df212f7bd5dc4b36ab1610b3351919a88dc9a6fdd8cd18
7
- data.tar.gz: 7245b35708dc29ee1c0d2ec60ec10cbd39125f7302aa3e84962037e2e30824793290b59f70c51e8a7892d79780747697f8635c90b48e3ba4d2276015538bb8b3
6
+ metadata.gz: ab929ce12105b08fb0e0f3180040233c2f748ec6037e71c3b59281083a8a9156b152cb07c0713e56e8d723d2c836671f37a505c6497fae48d7717eeca6008f34
7
+ data.tar.gz: acc709c87e6f5d5132f5a5ad01c4478b893479e847a5f38c2edc8fc793d411390bde9173edde3e2712e95258de5056f24511b5a2a67c51378fe39f78f4721e29
data/exe/spectre CHANGED
@@ -55,9 +55,6 @@ DEFAULT_CONFIG = {
55
55
  'modules' => [
56
56
  'spectre/helpers',
57
57
  'spectre/reporter/console',
58
- 'spectre/reporter/junit',
59
- 'spectre/reporter/vstest',
60
- 'spectre/reporter/html',
61
58
  'spectre/logger/console',
62
59
  'spectre/logger/file',
63
60
  'spectre/assertion',
@@ -86,19 +83,21 @@ property_overrides = {}
86
83
  $COMMAND = ['spectre'].concat(ARGV.clone).join(' ')
87
84
 
88
85
  OptionParser.new do |opts|
89
- opts.banner = %{Spectre #{Spectre::VERSION}
86
+ opts.banner = <<~BANNER
87
+ Spectre #{Spectre::VERSION}
90
88
 
91
- Usage: spectre [command] [options]
89
+ Usage: spectre [command] [options]
92
90
 
93
- Commands:
94
- list List specs
95
- run Run specs (default)
96
- show Print current environment settings
97
- dump Dumps the given environment in YAML format to console
98
- cleanup Will remove all generated files (e.g. logs and reports)
99
- 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
100
98
 
101
- Specific options:}
99
+ Specific options:
100
+ BANNER
102
101
 
103
102
  opts.on('-s SPEC,SPEC', '--specs SPEC,SPEC', Array, 'The specs to run') do |specs|
104
103
  cmd_options['specs'] = specs
@@ -136,11 +135,17 @@ OptionParser.new do |opts|
136
135
  cmd_options['out_path'] = File.absolute_path(path)
137
136
  end
138
137
 
139
- 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|
140
139
  cmd_options['reporters'] = reporters
141
140
  end
142
141
 
143
- 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
144
149
  cmd_options['debug'] = true
145
150
  end
146
151
 
@@ -165,9 +170,9 @@ OptionParser.new do |opts|
165
170
  end
166
171
  end
167
172
 
168
- opts.separator "\nCommon options:"
173
+ opts.separator "\n Common options:"
169
174
 
170
- opts.on_tail('--version', 'Print current installed version') do
175
+ opts.on_tail('-v', '--version', 'Print current installed version') do
171
176
  puts Spectre::VERSION
172
177
  exit
173
178
  end
@@ -205,15 +210,19 @@ if File.exists? config_file
205
210
  Dir.chdir File.dirname(config_file)
206
211
  end
207
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
208
217
  cfg['project'] = File.basename(Dir.pwd) unless cfg['project']
209
218
 
210
219
  cfg.deep_merge! cmd_options
211
220
 
221
+
212
222
  ###########################################
213
223
  # Load Environment
214
224
  ###########################################
215
225
 
216
-
217
226
  envs = {}
218
227
  read_env_files = {}
219
228
  cfg['env_patterns'].each do |pattern|
@@ -258,127 +267,131 @@ require_relative '../lib/spectre/environment' unless cfg['exclude'].include? 'sp
258
267
  Spectre.configure(cfg)
259
268
 
260
269
 
261
- ###########################################
262
- # Load Specs
263
- ###########################################
270
+ # Load specs only, when listing or running specs
271
+ if ['list', 'run'].include? action
264
272
 
273
+ ###########################################
274
+ # Load Specs
275
+ ###########################################
265
276
 
266
- cfg['spec_patterns'].each do |pattern|
267
- Dir.glob(pattern).each do|f|
268
- 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
269
282
  end
270
- end
271
283
 
272
284
 
273
- ###########################################
274
- # List specs
275
- ###########################################
285
+ ###########################################
286
+ # List specs
287
+ ###########################################
288
+
276
289
 
290
+ if 'list' == action
291
+ colors = [:blue, :magenta, :yellow, :green]
292
+ specs = Spectre.specs(cfg['specs'], cfg['tags'])
277
293
 
278
- if 'list' == action
279
- colors = [:blue, :magenta, :yellow, :green]
280
- specs = Spectre.specs(cfg['specs'], cfg['tags'])
294
+ exit 1 unless specs.any?
281
295
 
282
- exit 1 unless specs.any?
296
+ counter = 0
283
297
 
284
- counter = 0
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
285
306
 
286
- specs.group_by { |x| x.subject }.each do |subject, spec_group|
287
- spec_group.each do |spec|
288
- tags = spec.tags.map { |x| '#' + x.to_s }.join ' '
289
- desc = subject.desc
290
- desc += ' - ' + spec.context.__desc + ' -' if spec.context.__desc
291
- desc += ' ' + spec.desc
292
- puts "[#{spec.name}]".send(colors[counter % colors.length]) + " #{desc} #{tags.cyan}"
307
+ counter += 1
293
308
  end
294
309
 
295
- counter += 1
310
+ exit 0
296
311
  end
297
312
 
298
- exit 0
299
- end
300
313
 
314
+ ###########################################
315
+ # Run
316
+ ###########################################
301
317
 
302
- ###########################################
303
- # Run
304
- ###########################################
305
318
 
319
+ if 'run' == action
320
+ # Initialize logger
321
+ now = Time.now
306
322
 
307
- if 'run' == action
308
- # Initialize logger
309
- now = Time.now
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
+ })
310
329
 
311
- cfg['log_file'] = cfg['log_file'].frmt({
312
- shortdate: now.strftime('%Y-%m-%d'),
313
- date: now.strftime('%Y-%m-%d_%H%M%S'),
314
- timestamp: now.strftime('%s'),
315
- subject: 'spectre',
316
- })
330
+ log_dir = File.dirname(cfg['log_file'])
331
+ FileUtils.makedirs(log_dir)
317
332
 
318
- log_dir = File.dirname(cfg['log_file'])
319
- FileUtils.makedirs(log_dir)
333
+ # Load Modules
320
334
 
321
- # Load Modules
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)
322
342
 
323
- cfg['modules']
324
- .concat(cfg['include'])
325
- .select { |mod| !cfg['exclude'].include? mod }
326
- .each do |mod|
327
- begin
328
- mod_file = mod + '.rb'
329
- spectre_lib_mod = File.join(File.dirname(__dir__), 'lib', mod_file)
343
+ if File.exists? mod_file
344
+ require_relative mod_file
330
345
 
331
- if File.exists? mod_file
332
- require_relative mod_file
346
+ elsif File.exists? spectre_lib_mod
347
+ require_relative spectre_lib_mod
333
348
 
334
- elsif File.exists? spectre_lib_mod
335
- require_relative spectre_lib_mod
336
-
337
- else
338
- 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
339
355
  end
340
- rescue LoadError => e
341
- puts "Unable to load module #{mod}. Check if the module exists or remove it from your spectre config:\n#{e.message}"
342
- exit 1
343
356
  end
344
- end
345
357
 
346
- # Load mixins
358
+ # Load mixins
347
359
 
348
- cfg['mixin_patterns'].each do |pattern|
349
- Dir.glob(pattern).each do|f|
350
- 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
351
364
  end
352
- end
353
365
 
354
- Spectre.configure(cfg)
366
+ Spectre.configure(cfg)
355
367
 
356
- Spectre::Logging.debug! if cfg['debug']
368
+ Spectre::Logging.debug! if cfg['debug']
357
369
 
358
- cfg['loggers'].each do |logger_name|
359
- logger = Kernel.const_get(logger_name).new(cfg)
360
- Spectre::Logging.add(logger)
361
- 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']
362
374
 
363
- specs = Spectre.specs(cfg['specs'], cfg['tags'])
375
+ specs = Spectre.specs(cfg['specs'], cfg['tags'])
364
376
 
365
- unless specs.any?
366
- puts "No specs found in #{Dir.pwd}"
367
- exit 1
368
- end
377
+ unless specs.any?
378
+ puts "No specs found in #{Dir.pwd}"
379
+ exit 1
380
+ end
369
381
 
370
- run_infos = Spectre::Runner.new.run(specs)
382
+ run_infos = Spectre::Runner.new.run(specs)
371
383
 
372
- cfg['reporters'].each do |reporter|
373
- reporter = Kernel.const_get(reporter).new(cfg)
374
- reporter.report(run_infos)
375
- end
384
+ cfg['reporters'].each do |reporter|
385
+ reporter = Kernel.const_get(reporter).new(cfg)
386
+ reporter.report(run_infos)
387
+ end
376
388
 
377
- 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 }
378
390
 
379
- exit 0 if cfg['ignore_failure'] or not errors.any?
391
+ exit 0 if cfg['ignore_failure'] or not errors.any?
380
392
 
381
- exit 1
393
+ exit 1
394
+ end
382
395
  end
383
396
 
384
397
 
@@ -425,10 +438,12 @@ if 'cleanup' == action
425
438
 
426
439
  Dir.glob(log_file_pattern).each do |log_file|
427
440
  File.delete(log_file)
441
+ puts "#{log_file} deleted"
428
442
  end
429
443
 
430
444
  Dir.glob(File.join cfg['out_path'], '/*').each do |out_file|
431
445
  File.delete(out_file)
446
+ puts "#{out_file} deleted"
432
447
  end
433
448
  end
434
449
 
@@ -511,7 +526,7 @@ SAMPLE_SPEC = %[describe '<subject>' do
511
526
  end
512
527
 
513
528
  expect 'a message to exist' do
514
- response.json.message.should_not_be nil
529
+ response.json.message.should_not_be_empty
515
530
  end
516
531
  end
517
532
  end
@@ -1,4 +1,5 @@
1
1
  require_relative '../spectre'
2
+ require_relative '../spectre/helpers'
2
3
 
3
4
  require 'ostruct'
4
5
  require_relative 'logger'
@@ -7,32 +8,39 @@ require_relative 'logger'
7
8
  module Spectre
8
9
  module Assertion
9
10
  class ::Object
10
- def should_be(val)
11
- raise AssertionFailure.new("'#{self.to_s.trim}' should be '#{val.to_s.trim}'", val, self) unless self.to_s == val.to_s
11
+ def should_be(value)
12
+ evaluate(value, "#{self} should be #{value}") do |x|
13
+ self.equal? x
14
+ end
12
15
  end
13
16
 
14
17
  def should_be_empty
15
- raise AssertionFailure.new("'#{self.to_s.trim}' should be empty", nil, self) unless self.nil?
18
+ raise AssertionFailure.new("#{self.to_s.trim} should be empty", nil, self) unless self.nil?
16
19
  end
17
20
 
18
21
  def should_not_be(val)
19
- raise AssertionFailure.new("'#{self.to_s.trim}' should not be '#{val.to_s.trim}'", val, self) unless self.to_s != val.to_s
22
+ raise AssertionFailure.new("#{self.to_s.trim} should not be #{val.to_s.trim}", val, self) unless self.to_s != val.to_s
20
23
  end
21
24
 
22
25
  def should_not_exist
23
- raise AssertionFailure.new("'#{self.to_s.trim}' should not exist, but it does", val, self) unless self.to_s != nil
26
+ raise AssertionFailure.new("#{self.to_s.trim} should not exist, but it does", val, self) unless self.to_s != nil
24
27
  end
25
28
 
26
29
  def should_not_be_empty
27
30
  raise AssertionFailure.new('empty value', 'nothing', self) unless self != nil
28
31
  end
29
32
 
33
+ def evaluate val, message, &block
34
+ val = Evaluation.new(val) unless val.is_a? Evaluation
35
+ raise AssertionFailure.new(message, val, self) unless val.run &block
36
+ end
37
+
30
38
  def or other
31
- OrEvaluation.new self, other
39
+ OrEvaluation.new(self, other)
32
40
  end
33
41
 
34
42
  def and other
35
- AndEvaluation.new self, other
43
+ AndEvaluation.new(self, other)
36
44
  end
37
45
  end
38
46
 
@@ -93,7 +101,9 @@ module Spectre
93
101
  val = OpenStruct.new(val)
94
102
  end
95
103
 
96
- raise AssertionFailure.new("[#{list.join(', ').trim}] should contain '#{val.to_s.trim}'", val, list) unless list.include? val
104
+ evaluate(val, "#{self} should contain #{val.to_s}") do |x|
105
+ self.include? x
106
+ end
97
107
  end
98
108
 
99
109
  def should_not_contain(val)
@@ -134,15 +144,9 @@ module Spectre
134
144
  end
135
145
 
136
146
  def should_contain(value)
137
- raise AssertionFailure.new("Value is nil") if value.nil?
138
-
139
- predicate = proc { |x| self.include? x.to_s }
140
- evaluation = SingleEvaluation.new(value)
141
- success = evaluation.call(predicate)
142
-
143
- return if success
144
-
145
- raise AssertionFailure.new("'#{self.to_s.trim}' should contain #{evaluation.to_s}", evaluation, self)
147
+ evaluate(value, "'#{self.trim}' should contain #{value.to_s}") do |x|
148
+ self.include? x.to_s
149
+ end
146
150
  end
147
151
 
148
152
  def should_not_contain(val)
@@ -162,54 +166,58 @@ module Spectre
162
166
  end
163
167
 
164
168
  class Evaluation
165
- def initialize value, other
166
- @value = value
167
- @other = other
169
+ def initialize val
170
+ @val = val
168
171
  end
169
172
 
170
- def eval_assertion predicate, val
173
+ def run &block
174
+ evaluate(@val, block)
175
+ end
176
+
177
+ def evaluate(val, predicate)
171
178
  if val.is_a? Evaluation
172
- val.call(predicate)
179
+ val.run &predicate
173
180
  else
174
181
  predicate.call(val)
175
182
  end
176
183
  end
177
184
 
178
- alias :| :or
179
- alias :& :and
180
- end
181
-
182
- class SingleEvaluation < Evaluation
183
- def initialize value
184
- super(value, nil)
185
- end
186
-
187
- def call predicate
188
- eval_assertion(predicate, @value)
189
- end
190
-
191
185
  def to_s
192
- @value.to_s
186
+ @val.to_s
193
187
  end
194
188
  end
195
189
 
196
190
  class OrEvaluation < Evaluation
197
- def call predicate
198
- eval_assertion(predicate, @value) or eval_assertion(predicate, @other)
191
+ def initialize val, other
192
+ @val = val
193
+ @other = other
194
+ end
195
+
196
+ def run &block
197
+ res1 = evaluate(@val, block)
198
+ res2 = evaluate(@other, block)
199
+ res1 or res2
199
200
  end
200
201
 
201
202
  def to_s
202
- "(#{@value.to_s} or #{@other.to_s})"
203
+ "(#{@val} or #{@other})"
203
204
  end
204
205
  end
205
206
 
206
207
  class AndEvaluation < Evaluation
207
- def call predicate
208
- eval_assertion(predicate, @value) and eval_assertion(predicate, @other)
208
+ def initialize val, other
209
+ @val = val
210
+ @other = other
211
+ end
212
+
213
+ def run &block
214
+ res1 = evaluate(@val, block)
215
+ res2 = evaluate(@other, block)
216
+ res1 and res2
209
217
  end
210
218
 
211
219
  def to_s
212
- "(#{@value.to_s} and #{@other.to_s})"
220
+ "(#{@val} and #{@other})"
213
221
  end
214
222
  end
215
223
 
data/lib/spectre/http.rb CHANGED
@@ -19,7 +19,7 @@ module Spectre
19
19
  'cert' => nil,
20
20
  'headers' => nil,
21
21
  'query' => nil,
22
- 'content_type' => '',
22
+ 'content_type' => nil,
23
23
  'timeout' => 180,
24
24
  'retries' => 0,
25
25
  }
@@ -77,8 +77,7 @@ module Spectre
77
77
  data = data.to_h if data.is_a? OpenStruct
78
78
  body JSON.pretty_generate(data)
79
79
 
80
- # TODO: Only set content type, if not explicitly set
81
- content_type('application/json')
80
+ content_type('application/json') unless @__req['content_type']
82
81
  end
83
82
 
84
83
  def body body_content
@@ -231,10 +230,6 @@ module Spectre
231
230
  # do nothing
232
231
  end
233
232
 
234
- if str.length > 1000
235
- str = str[0...1000] + "\n[...]"
236
- end
237
-
238
233
  str
239
234
  end
240
235
 
data/lib/spectre.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Spectre
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 13
4
+ MINOR = 14
5
5
  TINY = 0
6
6
  end
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ectoplasm
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.1
19
+ version: 1.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.1
26
+ version: 1.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jsonpath
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -63,15 +63,7 @@ files:
63
63
  - lib/spectre/logger/file.rb
64
64
  - lib/spectre/mixin.rb
65
65
  - lib/spectre/reporter/console.rb
66
- - lib/spectre/reporter/html.rb
67
- - lib/spectre/reporter/junit.rb
68
- - lib/spectre/reporter/vstest.rb
69
66
  - lib/spectre/resources.rb
70
- - resources/OpenSans-Regular.ttf
71
- - resources/fa-regular-400.ttf
72
- - resources/fa-solid-900.ttf
73
- - resources/spectre_icon.svg
74
- - resources/vue.global.prod.js
75
67
  homepage: https://github.com/ionos-spectre/spectre-core
76
68
  licenses:
77
69
  - GPL-3.0-or-later