spectre-core 2.1.3 → 2.1.4
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 +105 -75
- 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: 0c4d07c24a6be8fbf1ed1ff1b4ec52860294be4b4c2d8580facf183231a3c4ed
|
|
4
|
+
data.tar.gz: 576889b489206a424462b087bc75590aa17339b918c4bc1076f072ceab2c29af
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a8c17b521b0e391942bf99a2ecd41d18349b5c79b63e5e71bdd1365284d347c1c31c0315f9b62976ff0068c29248f1a009a4e6eac8e53198ce4e41a8173f8a7
|
|
7
|
+
data.tar.gz: af4a92361d63d56b269a61b088635801b158dd217c4f9bd3400b5b19a0f0e20bad314589a488be101e5204935a6ed68e7d48c771ab257e450cdb6d166edd1df5
|
data/lib/spectre/version.rb
CHANGED
data/lib/spectre.rb
CHANGED
|
@@ -775,6 +775,10 @@ module Spectre
|
|
|
775
775
|
end
|
|
776
776
|
end
|
|
777
777
|
|
|
778
|
+
##
|
|
779
|
+
# The run context is passed to all specs and provides the
|
|
780
|
+
# DSL for assertions, expectations, logging, etc.
|
|
781
|
+
#
|
|
778
782
|
class RunContext
|
|
779
783
|
include Delegate
|
|
780
784
|
|
|
@@ -1158,7 +1162,7 @@ module Spectre
|
|
|
1158
1162
|
# Skip the run for this spec. This can be used to skip spec runs when a certain
|
|
1159
1163
|
# condition occurs.
|
|
1160
1164
|
#
|
|
1161
|
-
# skip 'subject is not yet ready to be
|
|
1165
|
+
# skip 'subject is not yet ready to be tested' unless service_is_ready()
|
|
1162
1166
|
#
|
|
1163
1167
|
def skip message
|
|
1164
1168
|
@skipped = true
|
|
@@ -1168,7 +1172,7 @@ module Spectre
|
|
|
1168
1172
|
end
|
|
1169
1173
|
|
|
1170
1174
|
class Specification
|
|
1171
|
-
attr_reader :id, :name, :desc, :full_desc, :parent, :root, :tags, :data, :file
|
|
1175
|
+
attr_reader :id, :name, :desc, :full_desc, :parent, :root, :tags, :data, :file, :block
|
|
1172
1176
|
|
|
1173
1177
|
def initialize parent, name, desc, tags, data, file, block
|
|
1174
1178
|
@parent = parent
|
|
@@ -1182,6 +1186,9 @@ module Spectre
|
|
|
1182
1186
|
@full_desc = "#{@parent.full_desc} #{@desc}"
|
|
1183
1187
|
end
|
|
1184
1188
|
|
|
1189
|
+
##
|
|
1190
|
+
# Natural sort comparison for spec names respecting numeric parts.
|
|
1191
|
+
#
|
|
1185
1192
|
def <=>(other)
|
|
1186
1193
|
# Split on dash: text part and numeric part
|
|
1187
1194
|
self_parts = @name.split('-')
|
|
@@ -1196,10 +1203,9 @@ module Spectre
|
|
|
1196
1203
|
end
|
|
1197
1204
|
|
|
1198
1205
|
##
|
|
1199
|
-
#
|
|
1200
|
-
# +before+ and +after+ blocks
|
|
1206
|
+
# Execute this specification with its before/after blocks
|
|
1201
1207
|
#
|
|
1202
|
-
def run
|
|
1208
|
+
def run(engine, befores, afters, bag)
|
|
1203
1209
|
RunContext.new(engine, self, :spec, bag) do |run_context|
|
|
1204
1210
|
engine.formatter.scope(@desc, self) do
|
|
1205
1211
|
befores.each do |block|
|
|
@@ -1227,7 +1233,8 @@ module Spectre
|
|
|
1227
1233
|
class DefinitionContext
|
|
1228
1234
|
include Delegate
|
|
1229
1235
|
|
|
1230
|
-
attr_reader :id, :name, :desc, :parent, :full_desc, :specs, :file
|
|
1236
|
+
attr_reader :id, :name, :desc, :parent, :full_desc, :specs, :file,
|
|
1237
|
+
:setups, :teardowns, :befores, :afters
|
|
1231
1238
|
|
|
1232
1239
|
def initialize desc, file, engine, parent = nil
|
|
1233
1240
|
@engine = engine
|
|
@@ -1257,6 +1264,93 @@ module Spectre
|
|
|
1257
1264
|
@parent ? @parent.root : self
|
|
1258
1265
|
end
|
|
1259
1266
|
|
|
1267
|
+
##
|
|
1268
|
+
# Returns all direct child contexts
|
|
1269
|
+
#
|
|
1270
|
+
def children
|
|
1271
|
+
@engine.contexts.select { |x| x.parent == self }
|
|
1272
|
+
end
|
|
1273
|
+
|
|
1274
|
+
##
|
|
1275
|
+
# Execute this context with its specs, setups, and teardowns.
|
|
1276
|
+
# Recursively executes child contexts using the tree structure.
|
|
1277
|
+
#
|
|
1278
|
+
def run(specs_set)
|
|
1279
|
+
runs = []
|
|
1280
|
+
|
|
1281
|
+
# Find specs in this context that should be executed
|
|
1282
|
+
selected = @specs.select { |x| specs_set.include? x }
|
|
1283
|
+
|
|
1284
|
+
# Check if any child contexts have specs to execute
|
|
1285
|
+
has_child_specs = children.any? { |child| child.specs_in_tree?(specs_set) }
|
|
1286
|
+
|
|
1287
|
+
# Skip this context if it has no matching specs and no children with specs
|
|
1288
|
+
return runs if selected.empty? && !has_child_specs
|
|
1289
|
+
|
|
1290
|
+
@engine.formatter.scope(@desc, self) do
|
|
1291
|
+
# Execute setup, specs, and teardown for this context
|
|
1292
|
+
if selected.any?
|
|
1293
|
+
setup_bag = nil
|
|
1294
|
+
|
|
1295
|
+
if @setups.any?
|
|
1296
|
+
setup_run = RunContext.new(@engine, self, :setup) do |run_context|
|
|
1297
|
+
@setups.each do |block|
|
|
1298
|
+
@engine.formatter.scope('setup', :setup) do
|
|
1299
|
+
@engine.logger.correlate do
|
|
1300
|
+
@engine.logger.debug("setup \"#{@desc}\"")
|
|
1301
|
+
run_context.execute(nil, &block)
|
|
1302
|
+
end
|
|
1303
|
+
end
|
|
1304
|
+
end
|
|
1305
|
+
end
|
|
1306
|
+
|
|
1307
|
+
setup_bag = setup_run.bag
|
|
1308
|
+
runs << setup_run
|
|
1309
|
+
end
|
|
1310
|
+
|
|
1311
|
+
# Only run specs if setup was successful
|
|
1312
|
+
if runs.all? { |x| x.status == :success }
|
|
1313
|
+
runs += selected.map do |spec|
|
|
1314
|
+
@engine.logger.correlate do
|
|
1315
|
+
spec.run(@engine, @befores, @afters, setup_bag)
|
|
1316
|
+
end
|
|
1317
|
+
end
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
if @teardowns.any?
|
|
1321
|
+
runs << RunContext.new(@engine, self, :teardown, setup_bag) do |run_context|
|
|
1322
|
+
@teardowns.each do |block|
|
|
1323
|
+
@engine.formatter.scope('teardown', :teardown) do
|
|
1324
|
+
@engine.logger.correlate do
|
|
1325
|
+
@engine.logger.debug("teardown \"#{@desc}\"")
|
|
1326
|
+
run_context.execute(nil, &block)
|
|
1327
|
+
end
|
|
1328
|
+
end
|
|
1329
|
+
end
|
|
1330
|
+
end
|
|
1331
|
+
end
|
|
1332
|
+
end
|
|
1333
|
+
|
|
1334
|
+
# Recursively execute child contexts
|
|
1335
|
+
children.each do |child_context|
|
|
1336
|
+
@engine.logger.correlate do
|
|
1337
|
+
runs += child_context.run(specs_set)
|
|
1338
|
+
end
|
|
1339
|
+
end
|
|
1340
|
+
end
|
|
1341
|
+
|
|
1342
|
+
runs
|
|
1343
|
+
end
|
|
1344
|
+
|
|
1345
|
+
##
|
|
1346
|
+
# Check recursively if this context or any of its children have specs in the filter set
|
|
1347
|
+
#
|
|
1348
|
+
def specs_in_tree?(specs_set)
|
|
1349
|
+
return true if @specs.any? { |x| specs_set.include? x }
|
|
1350
|
+
|
|
1351
|
+
children.any? { |child| child.specs_in_tree?(specs_set) }
|
|
1352
|
+
end
|
|
1353
|
+
|
|
1260
1354
|
##
|
|
1261
1355
|
# Creates a new sub context with the given block.
|
|
1262
1356
|
#
|
|
@@ -1332,71 +1426,6 @@ module Spectre
|
|
|
1332
1426
|
@specs << spec
|
|
1333
1427
|
end
|
|
1334
1428
|
end
|
|
1335
|
-
|
|
1336
|
-
# :nodoc:
|
|
1337
|
-
def run specs
|
|
1338
|
-
runs = []
|
|
1339
|
-
|
|
1340
|
-
selected = @specs.select { |x| specs.include? x }
|
|
1341
|
-
|
|
1342
|
-
return runs if selected.empty?
|
|
1343
|
-
|
|
1344
|
-
@engine.formatter.scope(@desc, self) do
|
|
1345
|
-
if selected.any?
|
|
1346
|
-
setup_bag = nil
|
|
1347
|
-
|
|
1348
|
-
if @setups.any?
|
|
1349
|
-
setup_run = RunContext.new(@engine, self, :setup) do |run_context|
|
|
1350
|
-
@setups.each do |block|
|
|
1351
|
-
@engine.formatter.scope('setup', :setup) do
|
|
1352
|
-
@engine.logger.correlate do
|
|
1353
|
-
@engine.logger.debug("setup \"#{@desc}\"")
|
|
1354
|
-
run_context.execute(nil, &block)
|
|
1355
|
-
end
|
|
1356
|
-
end
|
|
1357
|
-
end
|
|
1358
|
-
end
|
|
1359
|
-
|
|
1360
|
-
setup_bag = setup_run.bag
|
|
1361
|
-
|
|
1362
|
-
runs << setup_run
|
|
1363
|
-
end
|
|
1364
|
-
|
|
1365
|
-
# Only run specs if setup was successful
|
|
1366
|
-
if runs.all? { |x| x.status == :success }
|
|
1367
|
-
runs += selected.map do |spec|
|
|
1368
|
-
@engine.logger.correlate do
|
|
1369
|
-
spec.run(@engine, @befores, @afters, setup_bag)
|
|
1370
|
-
end
|
|
1371
|
-
end
|
|
1372
|
-
end
|
|
1373
|
-
|
|
1374
|
-
if @teardowns.any?
|
|
1375
|
-
runs << RunContext.new(@engine, self, :teardown, setup_bag) do |run_context|
|
|
1376
|
-
@teardowns.each do |block|
|
|
1377
|
-
@engine.formatter.scope('teardown', :teardown) do
|
|
1378
|
-
@engine.logger.correlate do
|
|
1379
|
-
@engine.logger.debug("teardown \"#{@desc}\"")
|
|
1380
|
-
run_context.execute(nil, &block)
|
|
1381
|
-
end
|
|
1382
|
-
end
|
|
1383
|
-
end
|
|
1384
|
-
end
|
|
1385
|
-
end
|
|
1386
|
-
end
|
|
1387
|
-
|
|
1388
|
-
@engine
|
|
1389
|
-
.contexts
|
|
1390
|
-
.select { |x| x.parent == self }
|
|
1391
|
-
.each do |context|
|
|
1392
|
-
@engine.logger.correlate do
|
|
1393
|
-
runs += context.run(specs)
|
|
1394
|
-
end
|
|
1395
|
-
end
|
|
1396
|
-
end
|
|
1397
|
-
|
|
1398
|
-
runs
|
|
1399
|
-
end
|
|
1400
1429
|
end
|
|
1401
1430
|
|
|
1402
1431
|
##
|
|
@@ -1636,11 +1665,12 @@ module Spectre
|
|
|
1636
1665
|
end
|
|
1637
1666
|
end
|
|
1638
1667
|
|
|
1639
|
-
list
|
|
1668
|
+
specs = list
|
|
1669
|
+
specs_set = Set.new(list)
|
|
1670
|
+
|
|
1671
|
+
specs
|
|
1640
1672
|
.group_by { |x| x.parent.root }
|
|
1641
|
-
.flat_map
|
|
1642
|
-
context.run(specs)
|
|
1643
|
-
end
|
|
1673
|
+
.flat_map { |context, _| context.run(specs_set) }
|
|
1644
1674
|
rescue Interrupt
|
|
1645
1675
|
# Do nothing here
|
|
1646
1676
|
end
|