spectre-core 1.15.2 → 2.0.1
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 +271 -463
- data/lib/spectre/assertion.rb +118 -250
- data/lib/spectre/expectation.rb +89 -0
- data/lib/spectre/helpers.rb +56 -59
- data/lib/spectre/version.rb +3 -0
- data/lib/spectre.rb +1510 -334
- metadata +57 -32
- data/lib/spectre/async.rb +0 -31
- data/lib/spectre/bag.rb +0 -17
- data/lib/spectre/curl.rb +0 -398
- data/lib/spectre/diagnostic.rb +0 -39
- data/lib/spectre/environment.rb +0 -30
- data/lib/spectre/http/basic_auth.rb +0 -25
- data/lib/spectre/http/keystone.rb +0 -99
- data/lib/spectre/http.rb +0 -394
- data/lib/spectre/logging/console.rb +0 -156
- data/lib/spectre/logging/file.rb +0 -106
- data/lib/spectre/logging.rb +0 -183
- data/lib/spectre/mixin.rb +0 -61
- data/lib/spectre/reporter/console.rb +0 -104
- data/lib/spectre/reporter.rb +0 -17
- data/lib/spectre/resources.rb +0 -53
data/lib/spectre/logging/file.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
module Spectre
|
2
|
-
module Logging
|
3
|
-
class File
|
4
|
-
def initialize config
|
5
|
-
raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'file'
|
6
|
-
|
7
|
-
@config = config['log_format']['file']
|
8
|
-
@fmt_start_group = @config['start_group']
|
9
|
-
@fmt_end_group = @config['end_group']
|
10
|
-
@fmt_sep = @config['separator']
|
11
|
-
|
12
|
-
@file_log = ::Logger.new(config['log_file'], progname: 'spectre')
|
13
|
-
@file_log.level = config['debug'] ? 'DEBUG' : 'INFO'
|
14
|
-
end
|
15
|
-
|
16
|
-
def start_subject subject
|
17
|
-
@file_log.debug("start running subject '#{subject.desc}'")
|
18
|
-
end
|
19
|
-
|
20
|
-
def end_subject subject
|
21
|
-
@file_log.debug("subject '#{subject.desc}' finished")
|
22
|
-
end
|
23
|
-
|
24
|
-
def start_context context
|
25
|
-
if context and context.__desc
|
26
|
-
@file_log.debug("start running context '#{context.__desc}'")
|
27
|
-
else
|
28
|
-
@file_log.debug("start running main context of #{context.__subject.desc}")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def end_context context
|
33
|
-
if context and context.__desc
|
34
|
-
@file_log.debug("context '#{context.__desc}' finished")
|
35
|
-
else
|
36
|
-
@file_log.debug("main context finished of #{context.__subject.desc}")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def start_spec spec, data=nil
|
41
|
-
log_msg = "start running spec [#{spec.name}] '#{spec.desc}'"
|
42
|
-
log_msg += " with data #{data}" if data
|
43
|
-
@file_log.debug(log_msg)
|
44
|
-
end
|
45
|
-
|
46
|
-
def end_spec spec, data=nil
|
47
|
-
log_msg = "running spec [#{spec.name}] '#{spec.desc}'"
|
48
|
-
log_msg += " with data #{data}" if data
|
49
|
-
log_msg += " finished"
|
50
|
-
@file_log.debug(log_msg)
|
51
|
-
end
|
52
|
-
|
53
|
-
def log_separator desc
|
54
|
-
desc = @fmt_sep.gsub('<desc>', desc) if @fmt_sep
|
55
|
-
@file_log.info(desc)
|
56
|
-
end
|
57
|
-
|
58
|
-
def start_group desc
|
59
|
-
desc = @fmt_start_group.gsub('<desc>', desc) if @fmt_start_group
|
60
|
-
@file_log.info(desc)
|
61
|
-
end
|
62
|
-
|
63
|
-
def end_group desc
|
64
|
-
desc = @fmt_end_group.gsub('<desc>', desc) if @fmt_end_group
|
65
|
-
@file_log.info(desc)
|
66
|
-
end
|
67
|
-
|
68
|
-
def log_process desc
|
69
|
-
@file_log.debug(desc)
|
70
|
-
end
|
71
|
-
|
72
|
-
def log_info message
|
73
|
-
@file_log.info("#{Status::INFO} #{message}")
|
74
|
-
end
|
75
|
-
|
76
|
-
def log_debug message
|
77
|
-
@file_log.debug("#{Status::DEBUG} #{message}")
|
78
|
-
end
|
79
|
-
|
80
|
-
def log_error spec, exception
|
81
|
-
file, line = exception.backtrace[0].match(/(.*\.rb):(\d+)/).captures
|
82
|
-
@file_log.error("An unexpected error occurred at '#{file}:#{line}' while running spec '#{spec.name}': [#{exception.class}] #{exception.message}\n#{exception.backtrace.join "\n"}")
|
83
|
-
end
|
84
|
-
|
85
|
-
def log_skipped spec, message=nil
|
86
|
-
txt = "spec '#{spec.desc}' skipped"
|
87
|
-
|
88
|
-
unless message.nil?
|
89
|
-
txt += ': ' + message
|
90
|
-
end
|
91
|
-
|
92
|
-
@file_log.warn(txt)
|
93
|
-
end
|
94
|
-
|
95
|
-
def log_status desc, status, annotation=nil
|
96
|
-
msg = "expected #{desc}...#{status.upcase}"
|
97
|
-
msg += " - #{annotation}" if annotation
|
98
|
-
@file_log.debug(msg)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
Spectre.register do |config|
|
103
|
-
Spectre::Logging.add File.new(config)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/spectre/logging.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
require_relative '../spectre'
|
2
|
-
require 'date'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
module Spectre
|
6
|
-
module Logging
|
7
|
-
module Status
|
8
|
-
OK = '[ok]'
|
9
|
-
FAILED = '[failed]'
|
10
|
-
ERROR = '[error]'
|
11
|
-
INFO = '[info]'
|
12
|
-
SKIPPED = '[skipped]'
|
13
|
-
DEBUG = '[debug]'
|
14
|
-
end
|
15
|
-
|
16
|
-
class ModuleLogger
|
17
|
-
attr_reader :logger
|
18
|
-
|
19
|
-
def initialize config, name
|
20
|
-
@name = name
|
21
|
-
@debug = config['debug']
|
22
|
-
@logger = ::Logger.new(config['log_file'], progname: name)
|
23
|
-
|
24
|
-
@logger.level = @debug ? ::Logger::DEBUG : ::Logger::INFO
|
25
|
-
end
|
26
|
-
|
27
|
-
def info message
|
28
|
-
@logger.info(message)
|
29
|
-
Spectre::Logging.add_log(message, :info, @name)
|
30
|
-
end
|
31
|
-
|
32
|
-
def debug message
|
33
|
-
return unless @debug
|
34
|
-
|
35
|
-
@logger.debug(message)
|
36
|
-
Spectre::Logging.add_log(message, :debug, @name)
|
37
|
-
end
|
38
|
-
|
39
|
-
def warn message
|
40
|
-
@logger.warn(message)
|
41
|
-
Spectre::Logging.add_log(message, :warn, @name)
|
42
|
-
end
|
43
|
-
|
44
|
-
def error message
|
45
|
-
@logger.error(message)
|
46
|
-
Spectre::Logging.add_log(message, :error, @name)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class << self
|
51
|
-
@@debug = false
|
52
|
-
@@logger = []
|
53
|
-
|
54
|
-
def debug!
|
55
|
-
@@debug = true
|
56
|
-
end
|
57
|
-
|
58
|
-
def debug?
|
59
|
-
@@debug
|
60
|
-
end
|
61
|
-
|
62
|
-
def add logger
|
63
|
-
@@logger.append(logger)
|
64
|
-
end
|
65
|
-
|
66
|
-
def start_subject subject
|
67
|
-
delegate(:start_subject, subject)
|
68
|
-
end
|
69
|
-
|
70
|
-
def end_subject subject
|
71
|
-
delegate(:end_subject, subject)
|
72
|
-
end
|
73
|
-
|
74
|
-
def start_context context
|
75
|
-
delegate(:start_context, context)
|
76
|
-
end
|
77
|
-
|
78
|
-
def end_context context
|
79
|
-
delegate(:end_context, context)
|
80
|
-
end
|
81
|
-
|
82
|
-
def start_spec spec, data=nil
|
83
|
-
delegate(:start_spec, spec, data)
|
84
|
-
end
|
85
|
-
|
86
|
-
def end_spec spec, data=nil
|
87
|
-
delegate(:end_spec, spec, data)
|
88
|
-
end
|
89
|
-
|
90
|
-
def log_subject subject
|
91
|
-
begin
|
92
|
-
start_subject(subject)
|
93
|
-
yield
|
94
|
-
ensure
|
95
|
-
end_subject(subject)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def log_context context
|
100
|
-
begin
|
101
|
-
start_context(context)
|
102
|
-
yield
|
103
|
-
ensure
|
104
|
-
end_context(context)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def log_spec spec, data=nil
|
109
|
-
start_spec(spec, data)
|
110
|
-
yield
|
111
|
-
end_spec(spec, data)
|
112
|
-
end
|
113
|
-
|
114
|
-
def log_separator desc
|
115
|
-
delegate(:log_separator, desc)
|
116
|
-
end
|
117
|
-
|
118
|
-
def start_group desc
|
119
|
-
delegate(:start_group, desc)
|
120
|
-
end
|
121
|
-
|
122
|
-
def end_group desc
|
123
|
-
delegate(:end_group, desc)
|
124
|
-
end
|
125
|
-
|
126
|
-
def log_process desc
|
127
|
-
delegate(:log_process, desc)
|
128
|
-
end
|
129
|
-
|
130
|
-
def log_info message
|
131
|
-
add_log(message, :info)
|
132
|
-
delegate(:log_info, message)
|
133
|
-
end
|
134
|
-
|
135
|
-
def log_debug message
|
136
|
-
return unless @@debug
|
137
|
-
|
138
|
-
add_log(message, :debug)
|
139
|
-
delegate(:log_debug, message)
|
140
|
-
end
|
141
|
-
|
142
|
-
def log_error spec, exception
|
143
|
-
add_log(exception, :error)
|
144
|
-
delegate(:log_error, spec, exception)
|
145
|
-
end
|
146
|
-
|
147
|
-
def log_skipped spec, message=nil
|
148
|
-
delegate(:log_skipped, spec, message)
|
149
|
-
end
|
150
|
-
|
151
|
-
def log_status desc, status, annotation=nil
|
152
|
-
delegate(:log_status, desc, status, annotation)
|
153
|
-
end
|
154
|
-
|
155
|
-
def group desc
|
156
|
-
Spectre::Logging.start_group(desc)
|
157
|
-
yield
|
158
|
-
Spectre::Logging.end_group(desc)
|
159
|
-
end
|
160
|
-
|
161
|
-
def add_log message, level, logger_name='spectre'
|
162
|
-
return unless Spectre::Runner.current
|
163
|
-
|
164
|
-
Spectre::Runner.current.log.append([DateTime.now, message, level, logger_name])
|
165
|
-
end
|
166
|
-
|
167
|
-
alias_method :info, :log_info
|
168
|
-
alias_method :log, :log_info
|
169
|
-
alias_method :debug, :log_debug
|
170
|
-
alias_method :separate, :log_separator
|
171
|
-
|
172
|
-
private
|
173
|
-
|
174
|
-
def delegate method, *args
|
175
|
-
@@logger.each do |logger|
|
176
|
-
logger.send(method, *args) if logger.respond_to? method
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
Spectre.delegate(:log, :info, :debug, :group, :separate, to: self)
|
182
|
-
end
|
183
|
-
end
|
data/lib/spectre/mixin.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require_relative '../spectre'
|
2
|
-
require_relative 'logging'
|
3
|
-
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
module Spectre
|
7
|
-
module Mixin
|
8
|
-
class MixinContext < Spectre::DslClass
|
9
|
-
def initialize desc
|
10
|
-
@__desc = desc
|
11
|
-
end
|
12
|
-
|
13
|
-
def required params, *keys
|
14
|
-
missing_keys = keys.select { |x| !params.to_h.key? x }
|
15
|
-
Spectre::Logging.log_debug("required parameters for '#{@__desc}': #{keys.join ', '}")
|
16
|
-
raise ArgumentError, "mixin '#{@__desc}' requires #{keys.join ', '}, but only has #{missing_keys.join ', '} given" unless missing_keys.empty?
|
17
|
-
end
|
18
|
-
|
19
|
-
def optional params, *keys
|
20
|
-
Spectre::Logging.log_debug("optional parameters for '#{@__desc}': #{keys.join ', '}")
|
21
|
-
params
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
@@mixins = {}
|
27
|
-
|
28
|
-
def mixin desc, &block
|
29
|
-
@@mixins[desc] = block
|
30
|
-
end
|
31
|
-
|
32
|
-
def run desc, with: []
|
33
|
-
raise "no mixin with desc '#{desc}' defined" unless @@mixins.key? desc
|
34
|
-
|
35
|
-
Spectre::Logging.log_debug "running mixin '#{desc}'"
|
36
|
-
|
37
|
-
params = with || {}
|
38
|
-
if params.empty?
|
39
|
-
params = {}
|
40
|
-
end
|
41
|
-
|
42
|
-
ctx = MixinContext.new(desc)
|
43
|
-
|
44
|
-
if params.is_a? Array
|
45
|
-
return_val = ctx._execute(*params, &@@mixins[desc])
|
46
|
-
elsif params.is_a? Hash
|
47
|
-
return_val = ctx._execute(OpenStruct.new(params), &@@mixins[desc])
|
48
|
-
else
|
49
|
-
return_val = ctx._execute(params, &@@mixins[desc])
|
50
|
-
end
|
51
|
-
|
52
|
-
return_val.is_a?(Hash) ? OpenStruct.new(return_val) : return_val
|
53
|
-
end
|
54
|
-
|
55
|
-
alias_method :also, :run
|
56
|
-
alias_method :step, :run
|
57
|
-
end
|
58
|
-
|
59
|
-
Spectre.delegate :mixin, :run, :also, :step, to: self
|
60
|
-
end
|
61
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require_relative '../reporter'
|
2
|
-
|
3
|
-
module Spectre::Reporter
|
4
|
-
class Console
|
5
|
-
def initialize config
|
6
|
-
@debug = config['debug']
|
7
|
-
end
|
8
|
-
|
9
|
-
def report run_infos
|
10
|
-
report_str = ''
|
11
|
-
|
12
|
-
errors = 0
|
13
|
-
failures = 0
|
14
|
-
skipped = run_infos.select { |x| x.skipped? }.count
|
15
|
-
|
16
|
-
run_infos
|
17
|
-
.select { |x| x.error != nil or x.failure != nil }
|
18
|
-
.each_with_index do |run_info, index|
|
19
|
-
report_str += "\n#{index+1}) #{format_title(run_info)}\n"
|
20
|
-
|
21
|
-
if run_info.failure
|
22
|
-
report_str += " Expected #{run_info.failure.expectation}"
|
23
|
-
report_str += " with #{run_info.data}" if run_info.data
|
24
|
-
|
25
|
-
report_str += " but it failed"
|
26
|
-
|
27
|
-
if run_info.failure.cause
|
28
|
-
report_str += "\n with an unexpected error:\n"
|
29
|
-
report_str += format_exception(run_info.failure.cause)
|
30
|
-
|
31
|
-
elsif run_info.failure.message and not run_info.failure.message.empty?
|
32
|
-
report_str += " with:\n #{run_info.failure.message}"
|
33
|
-
|
34
|
-
else
|
35
|
-
report_str += '.'
|
36
|
-
end
|
37
|
-
|
38
|
-
report_str += "\n"
|
39
|
-
failures += 1
|
40
|
-
|
41
|
-
else
|
42
|
-
report_str += " but an unexpected error occurred during run\n"
|
43
|
-
report_str += format_exception(run_info.error)
|
44
|
-
errors += 1
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if failures + errors > 0
|
49
|
-
summary = ''
|
50
|
-
summary += "#{run_infos.length - failures - errors - skipped} succeeded "
|
51
|
-
summary += "#{failures} failures " if failures > 0
|
52
|
-
summary += "#{errors} errors " if errors > 0
|
53
|
-
summary += "#{skipped} skipped " if skipped > 0
|
54
|
-
summary += "#{run_infos.length} total"
|
55
|
-
print "\n#{summary}\n".red
|
56
|
-
else
|
57
|
-
summary = "\nRun finished successfully"
|
58
|
-
summary += " (#{skipped} skipped)" if skipped > 0
|
59
|
-
print "#{summary}\n".green
|
60
|
-
end
|
61
|
-
|
62
|
-
puts report_str.red
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def format_title run_info
|
68
|
-
title = run_info.spec.subject.desc
|
69
|
-
title += " #{run_info.spec.context.__desc}" if run_info.spec.context.__desc
|
70
|
-
title += ' ' + run_info.spec.desc
|
71
|
-
title += " (#{'%.3f' % run_info.duration}s)"
|
72
|
-
title += " [#{run_info.spec.name}]"
|
73
|
-
title
|
74
|
-
end
|
75
|
-
|
76
|
-
def format_exception error
|
77
|
-
non_spectre_files = error.backtrace.select { |x| !x.include? 'lib/spectre' }
|
78
|
-
|
79
|
-
if non_spectre_files.count > 0
|
80
|
-
causing_file = non_spectre_files.first
|
81
|
-
else
|
82
|
-
causing_file = error.backtrace[0]
|
83
|
-
end
|
84
|
-
|
85
|
-
matches = causing_file.match(/(.*\.rb):(\d+)/)
|
86
|
-
|
87
|
-
return '' unless matches
|
88
|
-
|
89
|
-
file, line = matches.captures
|
90
|
-
file.slice!(Dir.pwd + '/')
|
91
|
-
|
92
|
-
str = ''
|
93
|
-
str += " file.....: #{file}:#{line}\n"
|
94
|
-
str += " type.....: #{error.class}\n"
|
95
|
-
str += " message..: #{error.message}\n"
|
96
|
-
str += " backtrace: \n #{error.backtrace.join("\n ")}\n" if @debug
|
97
|
-
str
|
98
|
-
end
|
99
|
-
|
100
|
-
Spectre.register do |config|
|
101
|
-
Spectre::Reporter.add Console.new(config)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/spectre/reporter.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Spectre
|
2
|
-
module Reporter
|
3
|
-
@@reporters = []
|
4
|
-
|
5
|
-
def self.add reporter
|
6
|
-
raise NotImplementedError.new("#{reporter} does not implement `report' method") unless reporter.respond_to? :report
|
7
|
-
|
8
|
-
@@reporters.append(reporter)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.report run_infos
|
12
|
-
@@reporters.each do |reporter|
|
13
|
-
reporter.report(run_infos)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/spectre/resources.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require_relative '../spectre'
|
2
|
-
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
module Spectre
|
6
|
-
module Resources
|
7
|
-
class ResourceCollection
|
8
|
-
def initialize
|
9
|
-
@items = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def add name, path
|
13
|
-
@items[name] = path
|
14
|
-
end
|
15
|
-
|
16
|
-
def [] name
|
17
|
-
raise "Resource with name '#{name}' does not exist" unless @items.key? name
|
18
|
-
|
19
|
-
@items[name]
|
20
|
-
end
|
21
|
-
|
22
|
-
def key? name
|
23
|
-
@items.key? name
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class << self
|
28
|
-
@@resources = ResourceCollection.new
|
29
|
-
|
30
|
-
def resources
|
31
|
-
@@resources
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Spectre.register do |config|
|
36
|
-
return unless config.key? 'resource_paths'
|
37
|
-
|
38
|
-
config['resource_paths'].each do |resource_path|
|
39
|
-
resource_files = Dir.glob File.join(resource_path, '**/*')
|
40
|
-
|
41
|
-
resource_files.each do |file|
|
42
|
-
file.slice! resource_path
|
43
|
-
file = file[1..-1]
|
44
|
-
@@resources.add file, File.expand_path(File.join resource_path, file)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
@@resources.freeze
|
49
|
-
end
|
50
|
-
|
51
|
-
Spectre.delegate :resources, to: self
|
52
|
-
end
|
53
|
-
end
|