spectre-core 1.8.3 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/spectre +53 -16
- data/lib/spectre/assertion.rb +15 -21
- data/lib/spectre/curl.rb +45 -22
- data/lib/spectre/helpers.rb +84 -14
- data/lib/spectre/http.rb +32 -17
- data/lib/spectre/mixin.rb +9 -16
- data/lib/spectre/reporter/console.rb +1 -0
- data/lib/spectre/reporter/junit.rb +2 -0
- data/lib/spectre.rb +17 -13
- metadata +19 -65
- data/lib/spectre/database/postgres.rb +0 -78
- data/lib/spectre/ftp.rb +0 -195
- data/lib/spectre/mysql.rb +0 -97
- data/lib/spectre/ssh.rb +0 -149
data/lib/spectre/http.rb
CHANGED
@@ -62,8 +62,7 @@ module Spectre
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def body body_content
|
65
|
-
|
66
|
-
@__req['body'] = body_content
|
65
|
+
@__req['body'] = body_content.to_s
|
67
66
|
end
|
68
67
|
|
69
68
|
def ensure_success!
|
@@ -102,6 +101,7 @@ module Spectre
|
|
102
101
|
end
|
103
102
|
|
104
103
|
def [] key
|
104
|
+
return nil if not @headers.has_key?(key.downcase)
|
105
105
|
@headers[key.downcase].first
|
106
106
|
end
|
107
107
|
|
@@ -166,6 +166,7 @@ module Spectre
|
|
166
166
|
@@response = nil
|
167
167
|
@@request = nil
|
168
168
|
@@modules = []
|
169
|
+
@@secure_keys = []
|
169
170
|
|
170
171
|
def https name, &block
|
171
172
|
http(name, secure: true, &block)
|
@@ -209,7 +210,8 @@ module Spectre
|
|
209
210
|
return str unless str or str.empty?
|
210
211
|
|
211
212
|
begin
|
212
|
-
json = JSON.parse
|
213
|
+
json = JSON.parse(str)
|
214
|
+
json.obfuscate!(@@secure_keys) if not @@debug
|
213
215
|
|
214
216
|
if pretty
|
215
217
|
str = JSON.pretty_generate(json)
|
@@ -223,6 +225,19 @@ module Spectre
|
|
223
225
|
str
|
224
226
|
end
|
225
227
|
|
228
|
+
def is_secure? key
|
229
|
+
@@secure_keys.any? { |x| key.to_s.downcase.include? x.downcase }
|
230
|
+
end
|
231
|
+
|
232
|
+
def header_to_s headers
|
233
|
+
s = ''
|
234
|
+
headers.each_header.each do |header, value|
|
235
|
+
value = '*****' if is_secure?(header) and not @@debug
|
236
|
+
s += "#{header.to_s.ljust(30, '.')}: #{value.to_s}\n"
|
237
|
+
end
|
238
|
+
s
|
239
|
+
end
|
240
|
+
|
226
241
|
def invoke req
|
227
242
|
@@request = nil
|
228
243
|
|
@@ -275,28 +290,28 @@ module Spectre
|
|
275
290
|
|
276
291
|
req_id = SecureRandom.uuid()[0..5]
|
277
292
|
|
293
|
+
# Run HTTP modules
|
294
|
+
|
295
|
+
@@modules.each do |mod|
|
296
|
+
mod.on_req(net_http, net_req, req) if mod.respond_to? :on_req
|
297
|
+
end
|
298
|
+
|
278
299
|
# Log request
|
279
300
|
|
280
|
-
req_log = "[>] #{req_id} #{req['method']} #{uri}"
|
281
|
-
|
282
|
-
|
283
|
-
end if req['headers']
|
284
|
-
req_log += "\n" + try_format_json(req['body'], pretty: true) if req['body'] != nil and not req['body'].empty?
|
301
|
+
req_log = "[>] #{req_id} #{req['method']} #{uri}\n"
|
302
|
+
req_log += header_to_s(net_req)
|
303
|
+
req_log += try_format_json(req['body'], pretty: true) if req['body'] != nil and not req['body'].empty?
|
285
304
|
|
286
305
|
@@logger.info req_log
|
287
306
|
|
288
307
|
# Request
|
289
308
|
|
290
309
|
start_time = Time.now
|
291
|
-
|
292
|
-
@@modules.each do |mod|
|
293
|
-
mod.on_req(net_http, net_req, req) if mod.respond_to? :on_req
|
294
|
-
end
|
295
|
-
|
296
310
|
net_res = net_http.request(net_req)
|
297
|
-
|
298
311
|
end_time = Time.now
|
299
312
|
|
313
|
+
# Run HTTP modules
|
314
|
+
|
300
315
|
@@modules.each do |mod|
|
301
316
|
mod.on_res(net_http, net_res, req) if mod.respond_to? :on_res
|
302
317
|
end
|
@@ -304,9 +319,7 @@ module Spectre
|
|
304
319
|
# Log response
|
305
320
|
|
306
321
|
res_log = "[<] #{req_id} #{net_res.code} #{net_res.message} (#{end_time - start_time}s)\n"
|
307
|
-
|
308
|
-
res_log += "#{header.to_s.ljust(30, '.')}: #{value}\n"
|
309
|
-
end
|
322
|
+
res_log += header_to_s(net_res)
|
310
323
|
res_log += try_format_json(net_res.body, pretty: true) if net_res.body != nil and !net_res.body.empty?
|
311
324
|
|
312
325
|
@@logger.info(res_log)
|
@@ -328,6 +341,8 @@ module Spectre
|
|
328
341
|
|
329
342
|
Spectre.register do |config|
|
330
343
|
@@logger = ::Logger.new config['log_file'], progname: 'spectre/http'
|
344
|
+
@@secure_keys = config['secure_keys'] || []
|
345
|
+
@@debug = config['debug']
|
331
346
|
|
332
347
|
if config.key? 'http'
|
333
348
|
@@http_cfg = {}
|
data/lib/spectre/mixin.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'ostruct'
|
2
|
+
require 'spectre/logger'
|
2
3
|
|
3
4
|
module Spectre
|
4
5
|
module Mixin
|
@@ -11,12 +12,16 @@ module Spectre
|
|
11
12
|
|
12
13
|
def run desc, with: []
|
13
14
|
raise "no mixin with desc '#{desc}' defined" unless @@mixins.key? desc
|
14
|
-
Logger.log_debug "running mixin '#{desc}'"
|
15
|
+
Spectre::Logger.log_debug "running mixin '#{desc}'"
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
params = with || {}
|
18
|
+
|
19
|
+
if params.is_a? Array
|
20
|
+
@@mixins[desc].call *params
|
21
|
+
elsif params.is_a? Hash
|
22
|
+
@@mixins[desc].call OpenStruct.new(params)
|
18
23
|
else
|
19
|
-
@@mixins[desc].call
|
24
|
+
@@mixins[desc].call params
|
20
25
|
end
|
21
26
|
end
|
22
27
|
|
@@ -24,18 +29,6 @@ module Spectre
|
|
24
29
|
alias_method :step, :run
|
25
30
|
end
|
26
31
|
|
27
|
-
Spectre.register do |config|
|
28
|
-
if not config.key? 'mixin_patterns'
|
29
|
-
return
|
30
|
-
end
|
31
|
-
|
32
|
-
config['mixin_patterns'].each do |pattern|
|
33
|
-
Dir.glob(pattern).each do|f|
|
34
|
-
require_relative File.join(Dir.pwd, f)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
32
|
Spectre.delegate :mixin, :run, :also, :step, to: Mixin
|
40
33
|
end
|
41
34
|
end
|
@@ -57,6 +57,7 @@ module Spectre::Reporter
|
|
57
57
|
|
58
58
|
if run_info.log.count > 0 or run_info.properties.count > 0 or run_info.data
|
59
59
|
xml_str += '<system-out>'
|
60
|
+
xml_str += '<![CDATA['
|
60
61
|
|
61
62
|
if run_info.properties.count > 0
|
62
63
|
run_info.properties.each do |key, val|
|
@@ -75,6 +76,7 @@ module Spectre::Reporter
|
|
75
76
|
xml_str += messages.join("\n")
|
76
77
|
end
|
77
78
|
|
79
|
+
xml_str += ']]>'
|
78
80
|
xml_str += '</system-out>'
|
79
81
|
end
|
80
82
|
|
data/lib/spectre.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spectre
|
2
2
|
module Version
|
3
3
|
MAJOR = 1
|
4
|
-
MINOR =
|
5
|
-
TINY =
|
4
|
+
MINOR = 11
|
5
|
+
TINY = 0
|
6
6
|
end
|
7
7
|
|
8
8
|
VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
|
@@ -31,20 +31,20 @@ module Spectre
|
|
31
31
|
# https://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
|
32
32
|
class DslClass
|
33
33
|
def _evaluate &block
|
34
|
-
@__bound_self__ = eval
|
34
|
+
@__bound_self__ = eval('self', block.binding)
|
35
35
|
instance_eval(&block)
|
36
36
|
end
|
37
37
|
|
38
38
|
def _execute args, &block
|
39
|
-
@__bound_self__ = eval
|
39
|
+
@__bound_self__ = eval('self', block.binding)
|
40
40
|
instance_exec(args, &block)
|
41
41
|
end
|
42
42
|
|
43
43
|
def method_missing method, *args, **kwargs, &block
|
44
44
|
if @__bound_self__.respond_to? method
|
45
|
-
@__bound_self__.send
|
45
|
+
@__bound_self__.send(method, *args, **kwargs, &block)
|
46
46
|
else
|
47
|
-
Delegator.redirect
|
47
|
+
Delegator.redirect(method, *args, **kwargs, &block)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -151,7 +151,7 @@ module Spectre
|
|
151
151
|
|
152
152
|
begin
|
153
153
|
specs.each do |spec|
|
154
|
-
if spec.data.
|
154
|
+
if spec.data.any?
|
155
155
|
spec.data.each do |data|
|
156
156
|
Logger.log_spec(spec, data) do
|
157
157
|
runs << run_spec(spec, data)
|
@@ -208,7 +208,7 @@ module Spectre
|
|
208
208
|
end
|
209
209
|
|
210
210
|
def run_spec spec, data=nil
|
211
|
-
run_info = RunInfo.new
|
211
|
+
run_info = RunInfo.new(spec, data)
|
212
212
|
|
213
213
|
@@current = run_info
|
214
214
|
|
@@ -216,16 +216,16 @@ module Spectre
|
|
216
216
|
|
217
217
|
begin
|
218
218
|
if spec.context.__before_blocks.count > 0
|
219
|
-
before_ctx = SpecContext.new
|
219
|
+
before_ctx = SpecContext.new(spec.subject, 'before')
|
220
220
|
|
221
221
|
Logger.log_context before_ctx do
|
222
222
|
spec.context.__before_blocks.each do |block|
|
223
|
-
block.call
|
223
|
+
block.call(data)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
spec.block.call
|
228
|
+
spec.block.call(data)
|
229
229
|
|
230
230
|
rescue ExpectationFailure => e
|
231
231
|
run_info.failure = e
|
@@ -240,7 +240,7 @@ module Spectre
|
|
240
240
|
|
241
241
|
ensure
|
242
242
|
if spec.context.__after_blocks.count > 0
|
243
|
-
after_ctx = SpecContext.new
|
243
|
+
after_ctx = SpecContext.new(spec.subject, 'after')
|
244
244
|
|
245
245
|
Logger.log_context after_ctx do
|
246
246
|
begin
|
@@ -306,7 +306,11 @@ module Spectre
|
|
306
306
|
.first
|
307
307
|
end
|
308
308
|
|
309
|
-
|
309
|
+
raise "`with' has to be an Array" unless with.is_a? Array
|
310
|
+
|
311
|
+
data = with.map { |x| x.is_a?(Hash) ? OpenStruct.new(x) : x }
|
312
|
+
|
313
|
+
@__subject.add_spec(desc, tags, data, block, self, spec_file)
|
310
314
|
end
|
311
315
|
|
312
316
|
def before &block
|
metadata
CHANGED
@@ -1,85 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spectre-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
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-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ectoplasm
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.1.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: openssl
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.2.0
|
19
|
+
version: 1.2.0
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
26
|
+
version: 1.2.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: jsonpath
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - "
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 6.1.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
31
|
+
- - ">="
|
53
32
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: net-sftp
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 3.0.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 3.0.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: mysql2
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.5.3
|
33
|
+
version: 1.1.0
|
76
34
|
type: :runtime
|
77
35
|
prerelease: false
|
78
36
|
version_requirements: !ruby/object:Gem::Requirement
|
79
37
|
requirements:
|
80
|
-
- - "
|
38
|
+
- - ">="
|
81
39
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
40
|
+
version: 1.1.0
|
83
41
|
description: A DSL and command line tool to describe and run automated tests
|
84
42
|
email:
|
85
43
|
- me@christianneubauer.de
|
@@ -93,10 +51,8 @@ files:
|
|
93
51
|
- lib/spectre/assertion.rb
|
94
52
|
- lib/spectre/bag.rb
|
95
53
|
- lib/spectre/curl.rb
|
96
|
-
- lib/spectre/database/postgres.rb
|
97
54
|
- lib/spectre/diagnostic.rb
|
98
55
|
- lib/spectre/environment.rb
|
99
|
-
- lib/spectre/ftp.rb
|
100
56
|
- lib/spectre/helpers.rb
|
101
57
|
- lib/spectre/http.rb
|
102
58
|
- lib/spectre/http/basic_auth.rb
|
@@ -105,20 +61,18 @@ files:
|
|
105
61
|
- lib/spectre/logger/console.rb
|
106
62
|
- lib/spectre/logger/file.rb
|
107
63
|
- lib/spectre/mixin.rb
|
108
|
-
- lib/spectre/mysql.rb
|
109
64
|
- lib/spectre/reporter/console.rb
|
110
65
|
- lib/spectre/reporter/junit.rb
|
111
66
|
- lib/spectre/resources.rb
|
112
|
-
|
113
|
-
homepage: https://bitbucket.org/cneubaur/spectre-core
|
67
|
+
homepage: https://github.com/cneubauer/spectre-core
|
114
68
|
licenses:
|
115
69
|
- MIT
|
116
70
|
metadata:
|
117
71
|
allowed_push_host: https://rubygems.org/
|
118
|
-
homepage_uri: https://
|
119
|
-
source_code_uri: https://
|
120
|
-
changelog_uri: https://
|
121
|
-
post_install_message:
|
72
|
+
homepage_uri: https://github.com/cneubauer/spectre-core
|
73
|
+
source_code_uri: https://github.com/cneubauer/spectre-core
|
74
|
+
changelog_uri: https://github.com/cneubauer/spectre-core/blob/master/CHANGELOG.md
|
75
|
+
post_install_message:
|
122
76
|
rdoc_options: []
|
123
77
|
require_paths:
|
124
78
|
- lib
|
@@ -133,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
87
|
- !ruby/object:Gem::Version
|
134
88
|
version: '0'
|
135
89
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
137
|
-
signing_key:
|
90
|
+
rubygems_version: 3.0.8
|
91
|
+
signing_key:
|
138
92
|
specification_version: 4
|
139
93
|
summary: Describe and run automated tests
|
140
94
|
test_files: []
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'pg'
|
2
|
-
|
3
|
-
|
4
|
-
class PG::Result
|
5
|
-
alias :count :ntuples
|
6
|
-
end
|
7
|
-
|
8
|
-
|
9
|
-
module Spectre
|
10
|
-
module Database
|
11
|
-
module Postgres
|
12
|
-
@@modules = []
|
13
|
-
|
14
|
-
class SQLStatement
|
15
|
-
attr_accessor :query, :params
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@query = nil
|
19
|
-
@params = []
|
20
|
-
end
|
21
|
-
|
22
|
-
def statement query
|
23
|
-
@query = query
|
24
|
-
end
|
25
|
-
|
26
|
-
def param val
|
27
|
-
@params << val
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
class << self
|
33
|
-
def postgres name, &block
|
34
|
-
raise "postgres '#{name}' not configured" unless @@db_cfg.key? name
|
35
|
-
|
36
|
-
statement = SQLStatement.new
|
37
|
-
statement.instance_eval &block
|
38
|
-
|
39
|
-
cfg = @@db_cfg[name]
|
40
|
-
|
41
|
-
begin
|
42
|
-
con = PG.connect({
|
43
|
-
host: cfg['host'],
|
44
|
-
port: cfg['port'],
|
45
|
-
dbname: cfg['database'],
|
46
|
-
user: cfg['username'],
|
47
|
-
password: cfg['username'],
|
48
|
-
})
|
49
|
-
|
50
|
-
if statement.params
|
51
|
-
@@result = con.exec_params(statement.query, statement.params)
|
52
|
-
else
|
53
|
-
@@result = con.exec(statement.query)
|
54
|
-
end
|
55
|
-
|
56
|
-
ensure
|
57
|
-
con.close if con
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
def result
|
63
|
-
@@result
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
Spectre.register do |config|
|
68
|
-
@@db_cfg = {}
|
69
|
-
|
70
|
-
config['postgres'].each do |name, cfg|
|
71
|
-
@@db_cfg[name] = cfg
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
Spectre.delegate :postgres, :result, to: self
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|