spectre-core 1.14.2 → 1.14.3

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: f1d19a96bd18baeb678abc3670c744bbd8855b4680db1e05bd57dcd99dfc3f21
4
- data.tar.gz: db9f3efd3faf3bf571845b1ae340a133ee9a95065cec2b8469d28b0a76985996
3
+ metadata.gz: 95442cbc13e78bd7fee6da1512708a07feb44846579ccede48c5c0e78bdbf3a5
4
+ data.tar.gz: 27297fba1be0eff1cebca38f37624483a5f52b1bf94a6f89a1ec4f0142294772
5
5
  SHA512:
6
- metadata.gz: dcfa21488bfce34984bac2efa1bc7fa73d703eb84d730497edef928fd9eea35be33abe9774d3becf38a1424d2e347728b5627ec1d053ac69e19b82b8b937decb
7
- data.tar.gz: af9018490eb268a7820419e597ea2eb5d8887ed7606c28bb7180e28245347f8d4fe630e26028113a39fd8ad7b54744b20687376fa1c386102ded67bb4ee38874
6
+ metadata.gz: 6a4ff3fd06c3c83349936ac1daec3002c7b36634cdef74e02aee89a1ee7bf87a13047079f86bfa7b9c389307b6cebe59d32a8cd4eac2e55bb734b35f00c990be
7
+ data.tar.gz: 4e57aafb0e340f308ed339c0ea56d695fd7546dfd6c7dce2d20540bdcd1e595b29b0ee308d2f07d2c66e221e96c2d605fff5e3cc713d30190132128598ddfd4f
data/exe/spectre CHANGED
@@ -23,13 +23,6 @@ DEFAULT_CONFIG = {
23
23
  'tags' => [],
24
24
  'colored' => true,
25
25
  'verbose' => false,
26
- 'reporters' => [
27
- 'Spectre::Reporter::Console',
28
- ],
29
- 'loggers' => [
30
- 'Spectre::Logging::Console',
31
- 'Spectre::Logging::File',
32
- ],
33
26
  'log_file' => './logs/spectre_<date>.log',
34
27
  'log_format' => {
35
28
  'console' => {
@@ -55,8 +48,8 @@ DEFAULT_CONFIG = {
55
48
  'modules' => [
56
49
  'spectre/helpers',
57
50
  'spectre/reporter/console',
58
- 'spectre/logger/console',
59
- 'spectre/logger/file',
51
+ 'spectre/logging/console',
52
+ 'spectre/logging/file',
60
53
  'spectre/assertion',
61
54
  'spectre/diagnostic',
62
55
  'spectre/environment',
@@ -135,10 +128,6 @@ OptionParser.new do |opts|
135
128
  cmd_options['out_path'] = File.absolute_path(path)
136
129
  end
137
130
 
138
- opts.on('-r NAME,NAME', '--reporters NAME,NAME', Array, "A list of reporters to use") do |reporters|
139
- cmd_options['reporters'] = reporters
140
- end
141
-
142
131
  opts.on('-m MODULE,MODULE', '--modules MODULE,MODULE', Array, "Load the given modules") do |modules|
143
132
  modules.each do |mod|
144
133
  require mod
@@ -195,6 +184,7 @@ action = ARGV[0] || 'run'
195
184
  cfg = {}
196
185
  cfg.deep_merge! DEFAULT_CONFIG
197
186
 
187
+ # Load global config file first
198
188
  global_config_file = File.join File.expand_path('~'), '.spectre'
199
189
 
200
190
  if File.exists? global_config_file
@@ -202,6 +192,7 @@ if File.exists? global_config_file
202
192
  cfg.deep_merge! global_options if global_options
203
193
  end
204
194
 
195
+ # Then load local config file
205
196
  config_file = cmd_options['config_file'] || cfg['config_file']
206
197
 
207
198
  if File.exists? config_file
@@ -216,6 +207,7 @@ cfg['debug'] = DEFAULT_CONFIG['debug']
216
207
  # Set project name
217
208
  cfg['project'] = File.basename(Dir.pwd) unless cfg['project']
218
209
 
210
+ # And merge the command line arguments last
219
211
  cfg.deep_merge! cmd_options
220
212
 
221
213
 
@@ -336,24 +328,24 @@ if ['list', 'run'].include? action
336
328
  .concat(cfg['include'])
337
329
  .select { |mod| !cfg['exclude'].include? mod }
338
330
  .each do |mod|
339
- begin
340
- mod_file = mod + '.rb'
341
- spectre_lib_mod = File.join(File.dirname(__dir__), 'lib', mod_file)
342
-
343
- if File.exists? mod_file
344
- require_relative mod_file
345
-
346
- elsif File.exists? spectre_lib_mod
347
- require_relative spectre_lib_mod
348
-
349
- else
350
- require mod
331
+ begin
332
+ mod_file = mod + '.rb'
333
+ spectre_lib_mod = File.join(File.dirname(__dir__), 'lib', mod_file)
334
+
335
+ if File.exists? mod_file
336
+ require_relative mod_file
337
+
338
+ elsif File.exists? spectre_lib_mod
339
+ require_relative spectre_lib_mod
340
+
341
+ else
342
+ require mod
343
+ end
344
+ rescue LoadError => e
345
+ puts "Unable to load module #{mod}. Check if the module exists or remove it from your spectre config:\n#{e.message}"
346
+ exit 1
351
347
  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
355
348
  end
356
- end
357
349
 
358
350
  # Load mixins
359
351
 
@@ -367,11 +359,6 @@ if ['list', 'run'].include? action
367
359
 
368
360
  Spectre::Logging.debug! if cfg['debug']
369
361
 
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']
374
-
375
362
  specs = Spectre.specs(cfg['specs'], cfg['tags'])
376
363
 
377
364
  unless specs.any?
@@ -381,12 +368,9 @@ if ['list', 'run'].include? action
381
368
 
382
369
  run_infos = Spectre::Runner.new.run(specs)
383
370
 
384
- cfg['reporters'].each do |reporter|
385
- reporter = Kernel.const_get(reporter).new(cfg)
386
- reporter.report(run_infos)
387
- end
371
+ Spectre::Reporter.report(run_infos)
388
372
 
389
- errors = run_infos.select { |x| nil != x.error or nil != x.failure }
373
+ errors = run_infos.select { |x| x.error? or x.failed? }
390
374
 
391
375
  exit 0 if cfg['ignore_failure'] or not errors.any?
392
376
 
@@ -542,10 +526,13 @@ DEFAULT_GEMFILE = %[source 'https://rubygems.org'
542
526
 
543
527
  gem 'spectre-core', '>= #{Spectre::VERSION}'
544
528
  # gem 'spectre-mysql', '>= 1.0.0'
545
- # gem 'spectre-ssh', '>= 1.0.0'
529
+ # gem 'spectre-ssh', '>= 1.0.2'
546
530
  # gem 'spectre-ftp', '>= 1.0.0'
547
531
  # gem 'spectre-curl', '>= 1.0.0'
548
- # gem 'spectre-git', '>= 0.1.0'
532
+ # gem 'spectre-git', '>= 0.2.1'
533
+ # gem 'spectre-reporter-junit', '>= 1.0.0'
534
+ # gem 'spectre-reporter-vstest', '>= 1.0.1'
535
+ # gem 'spectre-reporter-html', '>= 1.0.0'
549
536
  ]
550
537
 
551
538
  if 'init' == action
@@ -1,8 +1,8 @@
1
1
  require_relative '../spectre'
2
- require_relative '../spectre/helpers'
2
+ require_relative 'helpers'
3
+ require_relative 'logging'
3
4
 
4
5
  require 'ostruct'
5
- require_relative 'logger'
6
6
 
7
7
 
8
8
  module Spectre
@@ -249,20 +249,20 @@ module Spectre
249
249
  status = 'unknown'
250
250
 
251
251
  begin
252
- Logging.log_process("expect #{desc}")
252
+ Spectre::Logging.log_process("expect #{desc}")
253
253
  yield
254
- Logging.log_status(desc, Logging::Status::OK)
255
- status = 'ok'
254
+ Spectre::Logging.log_status(desc, Logging::Status::OK)
255
+ status = :ok
256
256
  rescue Interrupt => e
257
- status = 'skipped'
257
+ status = :skipped
258
258
  raise e
259
259
  rescue AssertionFailure => e
260
- Logging.log_status(desc, Logging::Status::FAILED)
261
- status = 'failed'
260
+ Spectre::Logging.log_status(desc, Logging::Status::FAILED)
261
+ status = :failed
262
262
  raise AssertionFailure.new(e.message, e.expected, e.actual, desc), cause: nil
263
263
  rescue Exception => e
264
- Logging.log_status(desc, Logging::Status::ERROR)
265
- status = 'error'
264
+ Spectre::Logging.log_status(desc, Logging::Status::ERROR)
265
+ status = :error
266
266
  raise AssertionFailure.new("An unexpected error occurred during expectation: #{e.message}", nil, nil, desc), cause: e
267
267
  ensure
268
268
  Spectre::Runner.current.expectations.append([desc, status])
@@ -274,7 +274,7 @@ module Spectre
274
274
  prefix += " '#{desc}'" if desc
275
275
 
276
276
  begin
277
- Logging.log_info(prefix) if desc
277
+ Spectre::Logging.log_info(prefix) if desc
278
278
  yield
279
279
  @@success = true
280
280
  @@logger.info("#{prefix} finished with success")
data/lib/spectre/bag.rb CHANGED
@@ -5,17 +5,13 @@ require 'ostruct'
5
5
  module Spectre
6
6
  module Bag
7
7
  class << self
8
- @@bag
8
+ @@bag = OpenStruct.new
9
9
 
10
10
  def bag
11
11
  @@bag
12
12
  end
13
13
  end
14
14
 
15
- Spectre.register do |_config|
16
- @@bag = OpenStruct.new
17
- end
18
-
19
15
  Spectre.delegate :bag, to: self
20
16
  end
21
17
  end
data/lib/spectre/curl.rb CHANGED
@@ -279,7 +279,7 @@ module Spectre::Curl
279
279
  cmd.append('-d', '"\n"')
280
280
  end
281
281
 
282
- # Add certificate path if one if given
282
+ # Add certificate path if one is given
283
283
  if req['cert']
284
284
  raise "Certificate '#{req['cert']}' does not exist" unless File.exists? req['cert']
285
285
 
@@ -130,6 +130,7 @@ end
130
130
 
131
131
  def uuid length = nil
132
132
  return SecureRandom.hex(length/2) if length
133
+
133
134
  SecureRandom.uuid
134
135
  end
135
136
 
data/lib/spectre/http.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative '../spectre'
2
+ require_relative '../spectre/logging'
2
3
 
3
4
  require 'net/http'
4
5
  require 'openssl'
@@ -4,15 +4,18 @@ module Spectre
4
4
  module Logging
5
5
  class Console
6
6
  def initialize config
7
- raise 'No log format section in config for console logger' unless config.key? 'log_format' and config['log_format'].key? 'console'
8
-
9
- @config = config['log_format']['console']
10
- @indent = @config['indent'] || 2
11
- @width = @config['width'] || 80
12
- @fmt_end_context = @config['end_context']
13
- @fmt_sep = @config['separator']
14
- @fmt_start_group = @config['start_group']
15
- @fmt_end_group = @config['end_group']
7
+ @indent = 2
8
+ @width = 80
9
+
10
+ if config.key? 'log_format'
11
+ @config = config['log_format']['console'] || {}
12
+ @indent = @config['indent'] || @indent
13
+ @width = @config['width'] || @width
14
+ @fmt_end_context = @config['end_context']
15
+ @fmt_sep = @config['separator']
16
+ @fmt_start_group = @config['start_group']
17
+ @fmt_end_group = @config['end_group']
18
+ end
16
19
 
17
20
  @process = nil
18
21
  @level = 0
@@ -145,5 +148,9 @@ module Spectre
145
148
  end
146
149
  end
147
150
  end
151
+
152
+ Spectre.register do |config|
153
+ Spectre::Logging.add Console.new(config)
154
+ end
148
155
  end
149
156
  end
@@ -98,5 +98,9 @@ module Spectre
98
98
  @file_log.debug(msg)
99
99
  end
100
100
  end
101
+
102
+ Spectre.register do |config|
103
+ Spectre::Logging.add File.new(config)
104
+ end
101
105
  end
102
106
  end
@@ -1,5 +1,6 @@
1
1
  require_relative '../spectre'
2
2
  require 'date'
3
+ require 'logger'
3
4
 
4
5
  module Spectre
5
6
  module Logging
@@ -23,17 +24,24 @@ module Spectre
23
24
 
24
25
  def info message
25
26
  @logger.info(message)
26
- Logging.add_log(message, :info, @name)
27
+ Spectre::Logging.add_log(message, :info, @name)
27
28
  end
28
29
 
29
30
  def debug message
31
+ return unless @debug
32
+
30
33
  @logger.debug(message)
31
- Logging.add_log(message, :debug, @name) if @debug
34
+ Spectre::Logging.add_log(message, :debug, @name)
32
35
  end
33
36
 
34
37
  def warn message
35
38
  @logger.warn(message)
36
- Logging.add_log(message, :warn, @name)
39
+ Spectre::Logging.add_log(message, :warn, @name)
40
+ end
41
+
42
+ def error message
43
+ @logger.error(message)
44
+ Spectre::Logging.add_log(message, :error, @name)
37
45
  end
38
46
  end
39
47
 
@@ -50,7 +58,7 @@ module Spectre
50
58
  end
51
59
 
52
60
  def add logger
53
- @@logger.append logger
61
+ @@logger.append(logger)
54
62
  end
55
63
 
56
64
  def start_subject subject
@@ -143,9 +151,9 @@ module Spectre
143
151
  end
144
152
 
145
153
  def group desc
146
- Logging.start_group desc
154
+ Spectre::Logging.start_group(desc)
147
155
  yield
148
- Logging.end_group desc
156
+ Spectre::Logging.end_group(desc)
149
157
  end
150
158
 
151
159
  def add_log message, level, logger_name='spectre'
@@ -168,6 +176,6 @@ module Spectre
168
176
  end
169
177
  end
170
178
 
171
- Spectre.delegate :log, :info, :debug, :group, :separate, to: self
179
+ Spectre.delegate(:log, :info, :debug, :group, :separate, to: self)
172
180
  end
173
181
  end
data/lib/spectre/mixin.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require_relative '../spectre'
2
- require_relative 'logger'
2
+ require_relative 'logging'
3
3
 
4
4
  require 'ostruct'
5
5
 
@@ -1,7 +1,9 @@
1
+ require_relative '../reporter'
2
+
1
3
  module Spectre::Reporter
2
4
  class Console
3
5
  def initialize config
4
- @config = config
6
+ @debug = config['debug']
5
7
  end
6
8
 
7
9
  def report run_infos
@@ -91,8 +93,12 @@ module Spectre::Reporter
91
93
  str += " file.....: #{file}:#{line}\n"
92
94
  str += " type.....: #{error.class}\n"
93
95
  str += " message..: #{error.message}\n"
94
- str += " backtrace: \n #{error.backtrace.join("\n ")}\n" if @config['debug']
96
+ str += " backtrace: \n #{error.backtrace.join("\n ")}\n" if @debug
95
97
  str
96
98
  end
99
+
100
+ Spectre.register do |config|
101
+ Spectre::Reporter.add Console.new(config)
102
+ end
97
103
  end
98
104
  end
@@ -0,0 +1,17 @@
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.rb CHANGED
@@ -2,7 +2,7 @@ module Spectre
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 14
5
- TINY = 2
5
+ TINY = 3
6
6
  end
7
7
 
8
8
  VERSION = [Version::MAJOR, Version::MINOR, Version::TINY].compact * '.'
@@ -13,10 +13,6 @@ module Spectre
13
13
  merger = proc { |_key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge!(v2, &merger) : v2 }
14
14
  self.merge!(second, &merger)
15
15
  end
16
-
17
- def deep_clone
18
- Marshal.load(Marshal.dump(self))
19
- end
20
16
  end
21
17
 
22
18
  class ::Object
@@ -25,6 +21,10 @@ module Spectre
25
21
  hash[var.to_s.delete("@")] = self.instance_variable_get(var)
26
22
  end
27
23
  end
24
+
25
+ def deep_clone
26
+ Marshal.load(Marshal.dump(self))
27
+ end
28
28
  end
29
29
 
30
30
 
@@ -84,16 +84,24 @@ module Spectre
84
84
  @name = desc.downcase.gsub(/[^a-z0-9]+/, '_')
85
85
  end
86
86
 
87
- def add_spec desc, tags, data, block, context, file
87
+ def add_spec desc, tags, data, block, context, file, line
88
88
  name = @name + '-' + (@specs.length+1).to_s
89
- @specs << Spec.new(name, self, desc, tags, data, block, context, file)
89
+ @specs << Spec.new(name, self, desc, tags, data, block, context, file, line)
90
+ end
91
+
92
+ def to_h
93
+ {
94
+ name: @name,
95
+ desc: @desc,
96
+ specs: @specs.map { |x| x.to_h },
97
+ }
90
98
  end
91
99
  end
92
100
 
93
101
  class Spec
94
- attr_reader :name, :subject, :context, :desc, :tags, :data, :block, :file
102
+ attr_reader :id, :name, :subject, :context, :desc, :tags, :data, :block, :file, :line
95
103
 
96
- def initialize name, subject, desc, tags, data, block, context, file
104
+ def initialize name, subject, desc, tags, data, block, context, file, line
97
105
  @name = name
98
106
  @context = context
99
107
  @data = data
@@ -102,11 +110,25 @@ module Spectre
102
110
  @tags = tags
103
111
  @block = block
104
112
  @file = file
113
+ @line = line
105
114
  end
106
115
 
107
116
  def full_desc
108
117
  @subject.desc + ' ' + desc
109
118
  end
119
+
120
+ def to_h
121
+ {
122
+ name: @name,
123
+ context: @context.__desc,
124
+ data: @data.map { |x| x.to_h },
125
+ subject: @subject.desc,
126
+ desc: @desc,
127
+ tags: @tags,
128
+ file: @file,
129
+ line: @line,
130
+ }
131
+ end
110
132
  end
111
133
 
112
134
  class RunInfo
@@ -149,22 +171,41 @@ module Spectre
149
171
 
150
172
  return :success
151
173
  end
174
+
175
+ def to_h
176
+ date_format = '%FT%T.%L%:z'
177
+
178
+ {
179
+ spec: @spec.name,
180
+ data: @data,
181
+ started: @started.strftime(date_format),
182
+ finished: @finished.strftime(date_format),
183
+ error: @error,
184
+ failure: @failure,
185
+ skipped: @skipped,
186
+ log: @log.map { |timestamp, message, level, name| [timestamp.strftime(date_format), message, level, name] },
187
+ expectations: @expectations,
188
+ properties: @properties,
189
+ }
190
+ end
152
191
  end
153
192
 
154
193
  class Runner
155
- @@current = nil
156
-
157
194
  def self.current
158
- @@current
195
+ Thread.current.thread_variable_get('current_run')
196
+ end
197
+
198
+ def self.current= run
199
+ Thread.current.thread_variable_set('current_run', run)
159
200
  end
160
201
 
161
202
  def run specs
162
203
  runs = []
163
204
 
164
205
  specs.group_by { |x| x.subject }.each do |subject, subject_specs|
165
- Logging.log_subject subject do
206
+ Spectre::Logging.log_subject subject do
166
207
  subject_specs.group_by { |x| x.context }.each do |context, context_specs|
167
- Logging.log_context(context) do
208
+ Spectre::Logging.log_context(context) do
168
209
  runs.concat run_context(context, context_specs)
169
210
  end
170
211
  end
@@ -193,12 +234,12 @@ module Spectre
193
234
  spec.data
194
235
  .map { |x| x.is_a?(Hash) ? OpenStruct.new(x) : x }
195
236
  .each do |data|
196
- Logging.log_spec(spec, data) do
237
+ Spectre::Logging.log_spec(spec, data) do
197
238
  runs << run_spec(spec, data)
198
239
  end
199
240
  end
200
241
  else
201
- Logging.log_spec(spec) do
242
+ Spectre::Logging.log_spec(spec) do
202
243
  runs << run_spec(spec)
203
244
  end
204
245
  end
@@ -215,11 +256,11 @@ module Spectre
215
256
  def run_setup spec
216
257
  run_info = RunInfo.new(spec)
217
258
 
218
- @@current = run_info
259
+ Runner.current = run_info
219
260
 
220
261
  run_info.started = Time.now
221
262
 
222
- Logging.log_context(spec.context) do
263
+ Spectre::Logging.log_context(spec.context) do
223
264
  begin
224
265
  spec.block.call()
225
266
 
@@ -228,13 +269,13 @@ module Spectre
228
269
  run_info.failure = e
229
270
  rescue Exception => e
230
271
  run_info.error = e
231
- Logging.log_error(spec, e)
272
+ Spectre::Logging.log_error(spec, e)
232
273
  end
233
274
  end
234
275
 
235
276
  run_info.finished = Time.now
236
277
 
237
- @@current = nil
278
+ Runner.current = nil
238
279
 
239
280
  run_info
240
281
  end
@@ -242,7 +283,7 @@ module Spectre
242
283
  def run_spec spec, data=nil
243
284
  run_info = RunInfo.new(spec, data)
244
285
 
245
- @@current = run_info
286
+ Runner.current = run_info
246
287
 
247
288
  run_info.started = Time.now
248
289
 
@@ -250,7 +291,7 @@ module Spectre
250
291
  if spec.context.__before_blocks.count > 0
251
292
  before_ctx = SpecContext.new(spec.subject, 'before', spec.context)
252
293
 
253
- Logging.log_context before_ctx do
294
+ Spectre::Logging.log_context before_ctx do
254
295
  spec.context.__before_blocks.each do |block|
255
296
  block.call(data)
256
297
  end
@@ -262,18 +303,18 @@ module Spectre
262
303
  run_info.failure = e
263
304
  rescue SpectreSkip => e
264
305
  run_info.skipped = true
265
- Logging.log_skipped(spec, e.message)
306
+ Spectre::Logging.log_skipped(spec, e.message)
266
307
  rescue Interrupt
267
308
  run_info.skipped = true
268
- Logging.log_skipped(spec, 'canceled by user')
309
+ Spectre::Logging.log_skipped(spec, 'canceled by user')
269
310
  rescue Exception => e
270
311
  run_info.error = e
271
- Logging.log_error(spec, e)
312
+ Spectre::Logging.log_error(spec, e)
272
313
  ensure
273
314
  if spec.context.__after_blocks.count > 0
274
315
  after_ctx = SpecContext.new(spec.subject, 'after', spec.context)
275
316
 
276
- Logging.log_context after_ctx do
317
+ Spectre::Logging.log_context after_ctx do
277
318
  begin
278
319
  spec.context.__after_blocks.each do |block|
279
320
  block.call
@@ -284,7 +325,7 @@ module Spectre
284
325
  run_info.failure = e
285
326
  rescue Exception => e
286
327
  run_info.error = e
287
- Logging.log_error(spec, e)
328
+ Spectre::Logging.log_error(spec, e)
288
329
  end
289
330
  end
290
331
  end
@@ -292,7 +333,7 @@ module Spectre
292
333
 
293
334
  run_info.finished = Time.now
294
335
 
295
- @@current = nil
336
+ Runner.current = nil
296
337
 
297
338
  run_info
298
339
  end
@@ -319,9 +360,9 @@ module Spectre
319
360
  end
320
361
 
321
362
  def it desc, tags: [], with: [], &block
322
- spec_file = get_file()
363
+ spec_file, line = get_call_location()
323
364
 
324
- @__subject.add_spec(desc, tags, with, block, self, spec_file)
365
+ @__subject.add_spec(desc, tags, with, block, self, spec_file, line)
325
366
  end
326
367
 
327
368
  def before &block
@@ -333,19 +374,19 @@ module Spectre
333
374
  end
334
375
 
335
376
  def setup &block
336
- name = "#{@__subject.name}-setup"
337
- spec_file = get_file()
377
+ name = "#{@__subject.name}-setup-#{@__setup_blocks.count+1}"
378
+ spec_file, line = get_call_location()
338
379
 
339
380
  setup_ctx = SpecContext.new(@__subject, 'setup', self)
340
- @__setup_blocks << Spec.new(name, @__subject, 'setup', [], nil, block, setup_ctx, spec_file)
381
+ @__setup_blocks << Spec.new(name, @__subject, 'setup', [], nil, block, setup_ctx, spec_file, line)
341
382
  end
342
383
 
343
384
  def teardown &block
344
- name = "#{@__subject.name}-teardown"
345
- spec_file = get_file()
385
+ name = "#{@__subject.name}-teardown-#{@__teardown_blocks.count+1}"
386
+ spec_file, line = get_call_location()
346
387
 
347
388
  teardown_ctx = SpecContext.new(@__subject, 'teardown', self)
348
- @__teardown_blocks << Spec.new(name, @__subject, 'teardown', [], nil, block, teardown_ctx, spec_file)
389
+ @__teardown_blocks << Spec.new(name, @__subject, 'teardown', [], nil, block, teardown_ctx, spec_file, line)
349
390
  end
350
391
 
351
392
  def context desc=nil, &block
@@ -355,21 +396,11 @@ module Spectre
355
396
 
356
397
  private
357
398
 
358
- def get_file
359
- # Get the file, where the spec is defined.
360
- # Nasty, but it works
361
- # Maybe there is another way, but this works for now
362
-
363
- begin
364
- raise
365
- rescue => e
366
- return e.backtrace
367
- .select { |file| !file.include? 'lib/spectre' }
368
- .first
369
- .match(/(.*\.rb):\d+/)
370
- .captures
371
- .first
372
- end
399
+ def get_call_location
400
+ path_and_line = caller[1].split(':')
401
+ line = path_and_line[-2].to_i
402
+ file = path_and_line[0..-3].join(':')
403
+ [file, line]
373
404
  end
374
405
  end
375
406
 
@@ -409,8 +440,9 @@ module Spectre
409
440
  @@subjects = []
410
441
  @@modules = []
411
442
 
412
- attr_reader :file_log, :logger
413
-
443
+ def subjects
444
+ @@subjects
445
+ end
414
446
 
415
447
  def specs spec_filter=[], tags=[]
416
448
  @@subjects
@@ -443,6 +475,11 @@ module Spectre
443
475
  end
444
476
  end
445
477
 
478
+ def purge
479
+ @@subjects = []
480
+ @@modules = []
481
+ end
482
+
446
483
 
447
484
  ###########################################
448
485
  # Global Functions
@@ -470,7 +507,7 @@ module Spectre
470
507
  end
471
508
  end
472
509
 
473
- delegate :describe, :property, :skip, to: Spectre
510
+ delegate(:describe, :property, :skip, to: Spectre)
474
511
  end
475
512
 
476
513
 
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.14.2
4
+ version: 1.14.3
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-09-08 00:00:00.000000000 Z
11
+ date: 2023-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ectoplasm
@@ -58,10 +58,11 @@ files:
58
58
  - lib/spectre/http.rb
59
59
  - lib/spectre/http/basic_auth.rb
60
60
  - lib/spectre/http/keystone.rb
61
- - lib/spectre/logger.rb
62
- - lib/spectre/logger/console.rb
63
- - lib/spectre/logger/file.rb
61
+ - lib/spectre/logging.rb
62
+ - lib/spectre/logging/console.rb
63
+ - lib/spectre/logging/file.rb
64
64
  - lib/spectre/mixin.rb
65
+ - lib/spectre/reporter.rb
65
66
  - lib/spectre/reporter/console.rb
66
67
  - lib/spectre/resources.rb
67
68
  homepage: https://github.com/ionos-spectre/spectre-core
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  - !ruby/object:Gem::Version
87
88
  version: '0'
88
89
  requirements: []
89
- rubygems_version: 3.3.7
90
+ rubygems_version: 3.3.26
90
91
  signing_key:
91
92
  specification_version: 4
92
93
  summary: Describe and run automated tests