spectre-core 2.1.2 → 2.1.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 +4 -4
- data/lib/spectre/version.rb +1 -1
- data/lib/spectre.rb +69 -64
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e75cee429c0765480965f1e1177c85f5ecf769651332e7167b1be5db8601cda
|
|
4
|
+
data.tar.gz: 6ad3c26cf386b69b57db775bec8fb8e1ae011a8d6abfb21a1aa250fec6198104
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09f0c500ce8ed1416a418b75af0716a6f7bd1083abf3b2d402c0adf381c0ce60bf51e8cb8e06f6f26bb5d19c1c3e8d8034361bcc320821f82835d39b427189f5'
|
|
7
|
+
data.tar.gz: 23d0113096cb9b69f78f40b1ae5ad7c6aa9201593fa9ac3e885f95ad14f53a5343673cbd932aca8603904638b3ef10afea6f81a5e55d47167b604836dc5e310a
|
data/lib/spectre/version.rb
CHANGED
data/lib/spectre.rb
CHANGED
|
@@ -20,7 +20,7 @@ def get_call_location call_stack
|
|
|
20
20
|
.find { |x| x.label.include? 'Spectre::Engine#load_files' or x.base_label == '<top (required)>' }
|
|
21
21
|
|
|
22
22
|
[
|
|
23
|
-
loc.path.sub(
|
|
23
|
+
loc.path.sub(Dir.pwd, '.'),
|
|
24
24
|
loc.lineno
|
|
25
25
|
]
|
|
26
26
|
end
|
|
@@ -78,13 +78,6 @@ end
|
|
|
78
78
|
# The main module containing all logic for the framework
|
|
79
79
|
#
|
|
80
80
|
module Spectre
|
|
81
|
-
# Cache Dir.pwd to avoid repeated system calls
|
|
82
|
-
@pwd = Dir.pwd
|
|
83
|
-
|
|
84
|
-
def self.pwd
|
|
85
|
-
@pwd
|
|
86
|
-
end
|
|
87
|
-
|
|
88
81
|
##
|
|
89
82
|
# Exception to throw in order to abort a spec run
|
|
90
83
|
#
|
|
@@ -265,13 +258,14 @@ module Spectre
|
|
|
265
258
|
counter = 0
|
|
266
259
|
|
|
267
260
|
specs
|
|
268
|
-
.group_by { |x| x.parent.root }
|
|
261
|
+
.group_by { |x| x.parent.root.name }
|
|
269
262
|
.each_value do |spec_group|
|
|
270
|
-
spec_group
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
263
|
+
spec_group
|
|
264
|
+
.sort
|
|
265
|
+
.each do |spec|
|
|
266
|
+
spec_id = "[#{spec.name}]".send(@colors[counter % @colors.length])
|
|
267
|
+
@out.puts "#{spec_id} #{spec.full_desc} #{spec.tags.map { |x| "##{x}" }.join(' ').cyan}"
|
|
268
|
+
end
|
|
275
269
|
|
|
276
270
|
counter += 1
|
|
277
271
|
end
|
|
@@ -280,15 +274,15 @@ module Spectre
|
|
|
280
274
|
##
|
|
281
275
|
# Outputs all the specs for all contexts
|
|
282
276
|
#
|
|
283
|
-
def describe contexts, level = 0
|
|
284
|
-
contexts.each do |context|
|
|
277
|
+
def describe contexts, level = 0, parent: nil
|
|
278
|
+
contexts.select { |x| x.parent == parent }.each do |context|
|
|
285
279
|
@out.puts("#{' ' * level}#{context.desc.send(level.positive? ? :magenta : :blue)}")
|
|
286
280
|
|
|
287
281
|
context.specs.each do |spec|
|
|
288
282
|
@out.puts("#{' ' * (level + 1)}#{spec.desc}")
|
|
289
283
|
end
|
|
290
284
|
|
|
291
|
-
describe(
|
|
285
|
+
describe(contexts, level + 1, parent: context)
|
|
292
286
|
end
|
|
293
287
|
end
|
|
294
288
|
|
|
@@ -327,7 +321,7 @@ module Spectre
|
|
|
327
321
|
mixins.each_value do |mixin|
|
|
328
322
|
output = "#{mixin.desc.yellow}\n"
|
|
329
323
|
output += " params.....: #{mixin.params.join ', '}\n" if mixin.params.any?
|
|
330
|
-
output += " location...: #{mixin.file.sub(
|
|
324
|
+
output += " location...: #{mixin.file.sub(Dir.pwd, '.')}:#{mixin.line}"
|
|
331
325
|
paragraphs << output
|
|
332
326
|
end
|
|
333
327
|
|
|
@@ -1188,6 +1182,19 @@ module Spectre
|
|
|
1188
1182
|
@full_desc = "#{@parent.full_desc} #{@desc}"
|
|
1189
1183
|
end
|
|
1190
1184
|
|
|
1185
|
+
def <=>(other)
|
|
1186
|
+
# Split on dash: text part and numeric part
|
|
1187
|
+
self_parts = @name.split('-')
|
|
1188
|
+
other_parts = other.name.split('-')
|
|
1189
|
+
|
|
1190
|
+
text_compare = self_parts[0] <=> other_parts[0]
|
|
1191
|
+
|
|
1192
|
+
# If the text parts are already different, we can return here
|
|
1193
|
+
return text_compare unless text_compare.zero?
|
|
1194
|
+
|
|
1195
|
+
self_parts[1].to_i <=> other_parts[1].to_i
|
|
1196
|
+
end
|
|
1197
|
+
|
|
1191
1198
|
##
|
|
1192
1199
|
# Creates a new +RunContext+ and executes the spec,
|
|
1193
1200
|
# +before+ and +after+ blocks
|
|
@@ -1220,13 +1227,13 @@ module Spectre
|
|
|
1220
1227
|
class DefinitionContext
|
|
1221
1228
|
include Delegate
|
|
1222
1229
|
|
|
1223
|
-
attr_reader :id, :name, :desc, :parent, :full_desc, :
|
|
1230
|
+
attr_reader :id, :name, :desc, :parent, :full_desc, :specs, :file
|
|
1224
1231
|
|
|
1225
|
-
def initialize desc, file, parent = nil
|
|
1232
|
+
def initialize desc, file, engine, parent = nil
|
|
1233
|
+
@engine = engine
|
|
1226
1234
|
@parent = parent
|
|
1227
1235
|
@desc = desc
|
|
1228
1236
|
@file = file
|
|
1229
|
-
@children = []
|
|
1230
1237
|
@specs = []
|
|
1231
1238
|
|
|
1232
1239
|
@setups = []
|
|
@@ -1239,6 +1246,8 @@ module Spectre
|
|
|
1239
1246
|
@name = @parent.name + '-' + @name unless @parent.nil?
|
|
1240
1247
|
|
|
1241
1248
|
@full_desc = @parent.nil? ? @desc : "#{@parent.full_desc} #{@desc}"
|
|
1249
|
+
|
|
1250
|
+
@engine.contexts << self
|
|
1242
1251
|
end
|
|
1243
1252
|
|
|
1244
1253
|
##
|
|
@@ -1248,13 +1257,6 @@ module Spectre
|
|
|
1248
1257
|
@parent ? @parent.root : self
|
|
1249
1258
|
end
|
|
1250
1259
|
|
|
1251
|
-
##
|
|
1252
|
-
# A flattened list of all specs including those of child contexts.
|
|
1253
|
-
#
|
|
1254
|
-
def all_specs
|
|
1255
|
-
@specs + @children.map(&:all_specs).flatten
|
|
1256
|
-
end
|
|
1257
|
-
|
|
1258
1260
|
##
|
|
1259
1261
|
# Creates a new sub context with the given block.
|
|
1260
1262
|
#
|
|
@@ -1262,10 +1264,9 @@ module Spectre
|
|
|
1262
1264
|
file = caller
|
|
1263
1265
|
.first
|
|
1264
1266
|
.gsub(/:in .*/, '')
|
|
1265
|
-
.gsub(
|
|
1267
|
+
.gsub(Dir.pwd, '.')
|
|
1266
1268
|
|
|
1267
|
-
context = DefinitionContext.new(desc, file, self)
|
|
1268
|
-
@children << context
|
|
1269
|
+
context = DefinitionContext.new(desc, file, @engine, self)
|
|
1269
1270
|
context.instance_eval(&)
|
|
1270
1271
|
end
|
|
1271
1272
|
|
|
@@ -1312,12 +1313,18 @@ module Spectre
|
|
|
1312
1313
|
file = caller
|
|
1313
1314
|
.first
|
|
1314
1315
|
.gsub(/:in .*/, '')
|
|
1315
|
-
.gsub(
|
|
1316
|
+
.gsub(Dir.pwd, '.')
|
|
1316
1317
|
|
|
1317
1318
|
with ||= [nil]
|
|
1318
1319
|
|
|
1319
|
-
|
|
1320
|
-
|
|
1320
|
+
initial_index = @engine
|
|
1321
|
+
.contexts
|
|
1322
|
+
.select { |x| x.root.name == root.name }
|
|
1323
|
+
.flat_map(&:specs)
|
|
1324
|
+
.count + 1
|
|
1325
|
+
|
|
1326
|
+
with.each_with_index do |data, index|
|
|
1327
|
+
spec_index = initial_index + index
|
|
1321
1328
|
name = "#{root.name}-#{spec_index}"
|
|
1322
1329
|
|
|
1323
1330
|
spec = Specification.new(self, name, desc, tags, data, file, block)
|
|
@@ -1327,23 +1334,23 @@ module Spectre
|
|
|
1327
1334
|
end
|
|
1328
1335
|
|
|
1329
1336
|
# :nodoc:
|
|
1330
|
-
def run
|
|
1337
|
+
def run specs
|
|
1331
1338
|
runs = []
|
|
1332
1339
|
|
|
1333
|
-
return runs unless all_specs.any? { |x| specs.include? x }
|
|
1334
|
-
|
|
1335
1340
|
selected = @specs.select { |x| specs.include? x }
|
|
1336
1341
|
|
|
1337
|
-
|
|
1342
|
+
return runs if selected.empty?
|
|
1343
|
+
|
|
1344
|
+
@engine.formatter.scope(@desc, self) do
|
|
1338
1345
|
if selected.any?
|
|
1339
1346
|
setup_bag = nil
|
|
1340
1347
|
|
|
1341
1348
|
if @setups.any?
|
|
1342
|
-
setup_run = RunContext.new(engine, self, :setup) do |run_context|
|
|
1349
|
+
setup_run = RunContext.new(@engine, self, :setup) do |run_context|
|
|
1343
1350
|
@setups.each do |block|
|
|
1344
|
-
engine.formatter.scope('setup', :setup) do
|
|
1345
|
-
engine.logger.correlate do
|
|
1346
|
-
engine.logger.debug("setup \"#{@desc}\"")
|
|
1351
|
+
@engine.formatter.scope('setup', :setup) do
|
|
1352
|
+
@engine.logger.correlate do
|
|
1353
|
+
@engine.logger.debug("setup \"#{@desc}\"")
|
|
1347
1354
|
run_context.execute(nil, &block)
|
|
1348
1355
|
end
|
|
1349
1356
|
end
|
|
@@ -1358,18 +1365,18 @@ module Spectre
|
|
|
1358
1365
|
# Only run specs if setup was successful
|
|
1359
1366
|
if runs.all? { |x| x.status == :success }
|
|
1360
1367
|
runs += selected.map do |spec|
|
|
1361
|
-
engine.logger.correlate do
|
|
1362
|
-
spec.run(engine, @befores, @afters, setup_bag)
|
|
1368
|
+
@engine.logger.correlate do
|
|
1369
|
+
spec.run(@engine, @befores, @afters, setup_bag)
|
|
1363
1370
|
end
|
|
1364
1371
|
end
|
|
1365
1372
|
end
|
|
1366
1373
|
|
|
1367
1374
|
if @teardowns.any?
|
|
1368
|
-
runs << RunContext.new(engine, self, :teardown, setup_bag) do |run_context|
|
|
1375
|
+
runs << RunContext.new(@engine, self, :teardown, setup_bag) do |run_context|
|
|
1369
1376
|
@teardowns.each do |block|
|
|
1370
|
-
engine.formatter.scope('teardown', :teardown) do
|
|
1371
|
-
engine.logger.correlate do
|
|
1372
|
-
engine.logger.debug("teardown \"#{@desc}\"")
|
|
1377
|
+
@engine.formatter.scope('teardown', :teardown) do
|
|
1378
|
+
@engine.logger.correlate do
|
|
1379
|
+
@engine.logger.debug("teardown \"#{@desc}\"")
|
|
1373
1380
|
run_context.execute(nil, &block)
|
|
1374
1381
|
end
|
|
1375
1382
|
end
|
|
@@ -1378,9 +1385,12 @@ module Spectre
|
|
|
1378
1385
|
end
|
|
1379
1386
|
end
|
|
1380
1387
|
|
|
1381
|
-
@
|
|
1382
|
-
|
|
1383
|
-
|
|
1388
|
+
@engine
|
|
1389
|
+
.contexts
|
|
1390
|
+
.select { |x| x.parent == self }
|
|
1391
|
+
.each do |context|
|
|
1392
|
+
@engine.logger.correlate do
|
|
1393
|
+
runs += context.run(specs)
|
|
1384
1394
|
end
|
|
1385
1395
|
end
|
|
1386
1396
|
end
|
|
@@ -1581,9 +1591,6 @@ module Spectre
|
|
|
1581
1591
|
require module_name
|
|
1582
1592
|
end
|
|
1583
1593
|
end
|
|
1584
|
-
ensure
|
|
1585
|
-
# return to the previous working directory
|
|
1586
|
-
Dir.chdir(Spectre.pwd)
|
|
1587
1594
|
end
|
|
1588
1595
|
|
|
1589
1596
|
# :nodoc:
|
|
@@ -1609,8 +1616,7 @@ module Spectre
|
|
|
1609
1616
|
tag_filter = config['tags'] || []
|
|
1610
1617
|
|
|
1611
1618
|
@contexts
|
|
1612
|
-
.
|
|
1613
|
-
.flatten
|
|
1619
|
+
.flat_map(&:specs)
|
|
1614
1620
|
.select do |spec|
|
|
1615
1621
|
(spec_filter.empty? and tag_filter.empty?) or
|
|
1616
1622
|
spec_filter.any? { |x| spec.name.match?("^#{x.gsub('*', '.*')}$") } or
|
|
@@ -1632,10 +1638,9 @@ module Spectre
|
|
|
1632
1638
|
|
|
1633
1639
|
list
|
|
1634
1640
|
.group_by { |x| x.parent.root }
|
|
1635
|
-
.
|
|
1636
|
-
context.run(
|
|
1641
|
+
.flat_map do |context, specs|
|
|
1642
|
+
context.run(specs)
|
|
1637
1643
|
end
|
|
1638
|
-
.flatten
|
|
1639
1644
|
rescue Interrupt
|
|
1640
1645
|
# Do nothing here
|
|
1641
1646
|
end
|
|
@@ -1669,15 +1674,15 @@ module Spectre
|
|
|
1669
1674
|
##
|
|
1670
1675
|
# Describe a test subject
|
|
1671
1676
|
#
|
|
1672
|
-
def describe(
|
|
1677
|
+
def describe(desc, &)
|
|
1673
1678
|
file = caller
|
|
1674
1679
|
.first
|
|
1675
1680
|
.gsub(/:in .*/, '')
|
|
1676
|
-
.gsub(
|
|
1681
|
+
.gsub(Dir.pwd, '.')
|
|
1677
1682
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1683
|
+
DefinitionContext
|
|
1684
|
+
.new(desc, file, self)
|
|
1685
|
+
.instance_eval(&)
|
|
1681
1686
|
end
|
|
1682
1687
|
|
|
1683
1688
|
##
|