spectre-core 1.9.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/spectre +51 -46
- data/lib/spectre/assertion.rb +50 -37
- data/lib/spectre/bag.rb +4 -2
- data/lib/spectre/curl.rb +62 -33
- data/lib/spectre/diagnostic.rb +12 -2
- data/lib/spectre/environment.rb +9 -5
- data/lib/spectre/helpers.rb +81 -22
- data/lib/spectre/http/basic_auth.rb +5 -2
- data/lib/spectre/http/keystone.rb +76 -73
- data/lib/spectre/http.rb +373 -359
- data/lib/spectre/logger/console.rb +7 -6
- data/lib/spectre/logger/file.rb +96 -96
- data/lib/spectre/logger.rb +146 -144
- data/lib/spectre/mixin.rb +35 -18
- data/lib/spectre/reporter/console.rb +3 -5
- data/lib/spectre/reporter/junit.rb +5 -3
- data/lib/spectre/resources.rb +7 -4
- data/lib/spectre.rb +58 -45
- metadata +26 -12
data/lib/spectre/resources.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative '../spectre'
|
2
|
+
|
1
3
|
require 'ostruct'
|
2
4
|
|
3
5
|
module Spectre
|
@@ -12,7 +14,8 @@ module Spectre
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def [] name
|
15
|
-
raise "Resource with name '#{name}' does not exist"
|
17
|
+
raise "Resource with name '#{name}' does not exist" unless @items.key? name
|
18
|
+
|
16
19
|
@items[name]
|
17
20
|
end
|
18
21
|
end
|
@@ -26,7 +29,7 @@ module Spectre
|
|
26
29
|
end
|
27
30
|
|
28
31
|
Spectre.register do |config|
|
29
|
-
return
|
32
|
+
return unless config.key? 'resource_paths'
|
30
33
|
|
31
34
|
config['resource_paths'].each do |resource_path|
|
32
35
|
resource_files = Dir.glob File.join(resource_path, '**/*')
|
@@ -41,6 +44,6 @@ module Spectre
|
|
41
44
|
@@resources.freeze
|
42
45
|
end
|
43
46
|
|
44
|
-
Spectre.delegate :resources, to:
|
47
|
+
Spectre.delegate :resources, to: self
|
45
48
|
end
|
46
|
-
end
|
49
|
+
end
|
data/lib/spectre.rb
CHANGED
@@ -1,18 +1,44 @@
|
|
1
1
|
module Spectre
|
2
2
|
module Version
|
3
3
|
MAJOR = 1
|
4
|
-
MINOR =
|
5
|
-
TINY =
|
4
|
+
MINOR = 12
|
5
|
+
TINY = 1
|
6
6
|
end
|
7
7
|
|
8
8
|
VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
|
9
9
|
|
10
10
|
|
11
|
+
class ::Hash
|
12
|
+
def deep_merge!(second)
|
13
|
+
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge!(v2, &merger) : v2 }
|
14
|
+
self.merge!(second, &merger)
|
15
|
+
end
|
16
|
+
|
17
|
+
def deep_clone
|
18
|
+
Marshal.load(Marshal.dump(self))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ::Object
|
23
|
+
def to_h
|
24
|
+
self.instance_variables.each_with_object({}) do |var, hash|
|
25
|
+
hash[var.to_s.delete("@")] = self.instance_variable_get(var)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
11
31
|
###########################################
|
12
32
|
# Custom Exceptions
|
13
33
|
###########################################
|
14
34
|
|
15
35
|
|
36
|
+
class SpectreError < Exception
|
37
|
+
def initialize message
|
38
|
+
super message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
16
42
|
class ExpectationFailure < Exception
|
17
43
|
attr_reader :expectation
|
18
44
|
|
@@ -31,25 +57,24 @@ module Spectre
|
|
31
57
|
# https://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
|
32
58
|
class DslClass
|
33
59
|
def _evaluate &block
|
34
|
-
@__bound_self__ = eval
|
60
|
+
@__bound_self__ = eval('self', block.binding)
|
35
61
|
instance_eval(&block)
|
36
62
|
end
|
37
63
|
|
38
|
-
def _execute args, &block
|
39
|
-
@__bound_self__ = eval
|
40
|
-
instance_exec(args, &block)
|
64
|
+
def _execute *args, &block
|
65
|
+
@__bound_self__ = eval('self', block.binding)
|
66
|
+
instance_exec(*args, &block)
|
41
67
|
end
|
42
68
|
|
43
69
|
def method_missing method, *args, **kwargs, &block
|
44
70
|
if @__bound_self__.respond_to? method
|
45
|
-
@__bound_self__.send
|
71
|
+
@__bound_self__.send(method, *args, **kwargs, &block)
|
46
72
|
else
|
47
|
-
Delegator.redirect
|
73
|
+
Delegator.redirect(method, *args, **kwargs, &block)
|
48
74
|
end
|
49
75
|
end
|
50
76
|
end
|
51
77
|
|
52
|
-
|
53
78
|
class Subject
|
54
79
|
attr_reader :name, :desc, :specs
|
55
80
|
|
@@ -65,7 +90,6 @@ module Spectre
|
|
65
90
|
end
|
66
91
|
end
|
67
92
|
|
68
|
-
|
69
93
|
class Spec
|
70
94
|
attr_reader :name, :subject, :context, :desc, :tags, :data, :block, :file
|
71
95
|
|
@@ -85,9 +109,9 @@ module Spectre
|
|
85
109
|
end
|
86
110
|
end
|
87
111
|
|
88
|
-
|
89
112
|
class RunInfo
|
90
|
-
attr_accessor :spec, :data, :started, :finished, :error, :failure, :skipped
|
113
|
+
attr_accessor :spec, :data, :started, :finished, :error, :failure, :skipped
|
114
|
+
attr_reader :log, :properties
|
91
115
|
|
92
116
|
def initialize spec, data=nil
|
93
117
|
@spec = spec
|
@@ -114,7 +138,6 @@ module Spectre
|
|
114
138
|
end
|
115
139
|
end
|
116
140
|
|
117
|
-
|
118
141
|
class Runner
|
119
142
|
@@current
|
120
143
|
|
@@ -151,12 +174,16 @@ module Spectre
|
|
151
174
|
|
152
175
|
begin
|
153
176
|
specs.each do |spec|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
177
|
+
raise SpectreError.new("Multi data definition (`with' parameter) of '#{spec.subject.desc} #{spec.desc}' has to be an `Array'") unless !spec.data.nil? and spec.data.is_a? Array
|
178
|
+
|
179
|
+
if spec.data.any?
|
180
|
+
spec.data
|
181
|
+
.map { |x| x.is_a?(Hash) ? OpenStruct.new(x) : x }
|
182
|
+
.each do |data|
|
183
|
+
Logger.log_spec(spec, data) do
|
184
|
+
runs << run_spec(spec, data)
|
185
|
+
end
|
158
186
|
end
|
159
|
-
end
|
160
187
|
else
|
161
188
|
Logger.log_spec(spec) do
|
162
189
|
runs << run_spec(spec)
|
@@ -189,14 +216,11 @@ module Spectre
|
|
189
216
|
end
|
190
217
|
|
191
218
|
run_info.finished = Time.now
|
192
|
-
|
193
219
|
rescue ExpectationFailure => e
|
194
220
|
run_info.failure = e
|
195
|
-
|
196
221
|
rescue Exception => e
|
197
222
|
run_info.error = e
|
198
223
|
Logger.log_error spec, e
|
199
|
-
|
200
224
|
end
|
201
225
|
end
|
202
226
|
|
@@ -208,7 +232,7 @@ module Spectre
|
|
208
232
|
end
|
209
233
|
|
210
234
|
def run_spec spec, data=nil
|
211
|
-
run_info = RunInfo.new
|
235
|
+
run_info = RunInfo.new(spec, data)
|
212
236
|
|
213
237
|
@@current = run_info
|
214
238
|
|
@@ -216,31 +240,27 @@ module Spectre
|
|
216
240
|
|
217
241
|
begin
|
218
242
|
if spec.context.__before_blocks.count > 0
|
219
|
-
before_ctx = SpecContext.new
|
243
|
+
before_ctx = SpecContext.new(spec.subject, 'before')
|
220
244
|
|
221
245
|
Logger.log_context before_ctx do
|
222
246
|
spec.context.__before_blocks.each do |block|
|
223
|
-
block.call
|
247
|
+
block.call(data)
|
224
248
|
end
|
225
249
|
end
|
226
250
|
end
|
227
251
|
|
228
|
-
spec.block.call
|
229
|
-
|
252
|
+
spec.block.call(data)
|
230
253
|
rescue ExpectationFailure => e
|
231
254
|
run_info.failure = e
|
232
|
-
|
233
255
|
rescue Interrupt
|
234
256
|
run_info.skipped = true
|
235
257
|
Logger.log_skipped spec
|
236
|
-
|
237
258
|
rescue Exception => e
|
238
259
|
run_info.error = e
|
239
260
|
Logger.log_error spec, e
|
240
|
-
|
241
261
|
ensure
|
242
262
|
if spec.context.__after_blocks.count > 0
|
243
|
-
after_ctx = SpecContext.new
|
263
|
+
after_ctx = SpecContext.new(spec.subject, 'after')
|
244
264
|
|
245
265
|
Logger.log_context after_ctx do
|
246
266
|
begin
|
@@ -249,14 +269,11 @@ module Spectre
|
|
249
269
|
end
|
250
270
|
|
251
271
|
run_info.finished = Time.now
|
252
|
-
|
253
272
|
rescue ExpectationFailure => e
|
254
273
|
run_info.failure = e
|
255
|
-
|
256
274
|
rescue Exception => e
|
257
275
|
run_info.error = e
|
258
276
|
Logger.log_error spec, e
|
259
|
-
|
260
277
|
end
|
261
278
|
end
|
262
279
|
end
|
@@ -290,7 +307,6 @@ module Spectre
|
|
290
307
|
end
|
291
308
|
|
292
309
|
def it desc, tags: [], with: [], &block
|
293
|
-
|
294
310
|
# Get the file, where the spec is defined.
|
295
311
|
# Nasty, but it works
|
296
312
|
# Maybe there is another way, but this works for now
|
@@ -344,6 +360,7 @@ module Spectre
|
|
344
360
|
methods.each do |method_name|
|
345
361
|
define_method(method_name) do |*args, &block|
|
346
362
|
return super(*args, &block) if respond_to? method_name
|
363
|
+
|
347
364
|
target.send(method_name, *args, &block)
|
348
365
|
end
|
349
366
|
|
@@ -354,8 +371,9 @@ module Spectre
|
|
354
371
|
end
|
355
372
|
|
356
373
|
def self.redirect method_name, *args, **kwargs, &block
|
357
|
-
target = @@mappings[method_name]
|
358
|
-
raise "
|
374
|
+
target = @@mappings[method_name] || Kernel
|
375
|
+
raise SpectreError.new("no variable or method '#{method_name}' found") unless target.respond_to? method_name
|
376
|
+
|
359
377
|
target.send(method_name, *args, **kwargs, &block)
|
360
378
|
end
|
361
379
|
end
|
@@ -373,12 +391,11 @@ module Spectre
|
|
373
391
|
.map { |x| x.specs }
|
374
392
|
.flatten
|
375
393
|
.select do |spec|
|
376
|
-
(spec_filter.empty? or spec_filter.any? { |x| spec.name.match('^' + x.gsub('*', '.*') + '$') }) and (tags.empty? or tags.any? { |x|
|
394
|
+
(spec_filter.empty? or spec_filter.any? { |x| spec.name.match('^' + x.gsub('*', '.*') + '$') }) and (tags.empty? or tags.any? { |x| tag?(spec.tags, x) })
|
377
395
|
end
|
378
396
|
end
|
379
397
|
|
380
|
-
|
381
|
-
def has_tag tags, tag_exp
|
398
|
+
def tag? tags, tag_exp
|
382
399
|
tags = tags.map { |x| x.to_s }
|
383
400
|
all_tags = tag_exp.split '+'
|
384
401
|
included_tags = all_tags.select { |x| !x.start_with? '!' }
|
@@ -386,17 +403,14 @@ module Spectre
|
|
386
403
|
included_tags & tags == included_tags and excluded_tags & tags == []
|
387
404
|
end
|
388
405
|
|
389
|
-
|
390
406
|
def delegate *method_names, to: nil
|
391
407
|
Spectre::Delegator.delegate *method_names, to
|
392
408
|
end
|
393
409
|
|
394
|
-
|
395
410
|
def register &block
|
396
411
|
@@modules << block
|
397
412
|
end
|
398
413
|
|
399
|
-
|
400
414
|
def configure config
|
401
415
|
@@modules.each do |block|
|
402
416
|
block.call(config)
|
@@ -412,7 +426,7 @@ module Spectre
|
|
412
426
|
def describe desc, &block
|
413
427
|
subject = @@subjects.find { |x| x.desc == desc }
|
414
428
|
|
415
|
-
|
429
|
+
unless subject
|
416
430
|
subject = Subject.new(desc)
|
417
431
|
@@subjects << subject
|
418
432
|
end
|
@@ -424,11 +438,10 @@ module Spectre
|
|
424
438
|
def property key, val
|
425
439
|
Spectre::Runner.current.properties[key] = val
|
426
440
|
end
|
427
|
-
|
428
441
|
end
|
429
442
|
|
430
443
|
delegate :describe, :property, to: Spectre
|
431
444
|
end
|
432
445
|
|
433
446
|
|
434
|
-
extend Spectre::Delegator
|
447
|
+
extend Spectre::Delegator
|
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.
|
4
|
+
version: 1.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Neubauer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ectoplasm
|
@@ -24,9 +24,23 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jsonpath
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.0
|
27
41
|
description: A DSL and command line tool to describe and run automated tests
|
28
42
|
email:
|
29
|
-
-
|
43
|
+
- christian.neubauer@ionos.com
|
30
44
|
executables:
|
31
45
|
- spectre
|
32
46
|
extensions: []
|
@@ -50,15 +64,15 @@ files:
|
|
50
64
|
- lib/spectre/reporter/console.rb
|
51
65
|
- lib/spectre/reporter/junit.rb
|
52
66
|
- lib/spectre/resources.rb
|
53
|
-
homepage: https://github.com/
|
67
|
+
homepage: https://github.com/ionos-spectre/spectre-core
|
54
68
|
licenses:
|
55
|
-
-
|
69
|
+
- GPL-3.0-or-later
|
56
70
|
metadata:
|
57
71
|
allowed_push_host: https://rubygems.org/
|
58
|
-
homepage_uri: https://github.com/
|
59
|
-
source_code_uri: https://github.com/
|
60
|
-
changelog_uri: https://github.com/
|
61
|
-
post_install_message:
|
72
|
+
homepage_uri: https://github.com/ionos-spectre/spectre-core
|
73
|
+
source_code_uri: https://github.com/ionos-spectre/spectre-core
|
74
|
+
changelog_uri: https://github.com/ionos-spectre/spectre-core/blob/master/CHANGELOG.md
|
75
|
+
post_install_message:
|
62
76
|
rdoc_options: []
|
63
77
|
require_paths:
|
64
78
|
- lib
|
@@ -73,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '0'
|
75
89
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
77
|
-
signing_key:
|
90
|
+
rubygems_version: 3.2.3
|
91
|
+
signing_key:
|
78
92
|
specification_version: 4
|
79
93
|
summary: Describe and run automated tests
|
80
94
|
test_files: []
|