Class: Probatio::Section
- Inherits:
-
Node
- Object
- Node
- Probatio::Section
show all
- Includes:
- Helpers, Waiters
- Defined in:
- lib/probatio.rb,
lib/probatio/helpers.rb,
lib/probatio/waiters.rb
Direct Known Subclasses
Group
Constant Summary
collapse
- ATTRS =
%i[ @parent @name @group_opts @path @children ].freeze
- METHS =
%i[
_group _section
_setup _teardown _before _after
_test
].freeze
Instance Attribute Summary
Attributes inherited from Node
#block, #children, #opts, #parent, #path
Instance Method Summary
collapse
-
#add_block(block) ⇒ Object
-
#add_file(path) ⇒ Object
-
#add_section(section, block) ⇒ Object
-
#after(opts = {}, &block) ⇒ Object
-
#afters ⇒ Object
-
#all_tests ⇒ Object
-
#around(opts = {}, &block) ⇒ Object
-
#arounds ⇒ Object
-
#before(opts = {}, &block) ⇒ Object
-
#befores ⇒ Object
-
#context(h = {}) ⇒ Object
-
#initialize(parent_group, path, name, opts, block) ⇒ Section
constructor
so it can be set when groups are “re-opened”…
-
#method_missing(name, *args, &block) ⇒ Object
-
#path=(pat) ⇒ Object
-
#run(run_opts) ⇒ Object
-
#setup(opts = {}, &block) ⇒ Object
-
#skip?(run_opts) ⇒ Boolean
-
#teardown(opts = {}, &block) ⇒ Object
Methods included from Waiters
#monow, #wait_until
Methods included from Helpers
#beep
Methods inherited from Node
#array_name, #depth, #filename, #full_name, #head, #last_line, #line, #location, #map, #name, #path_and_line, #pending?, #root, #test?, #to_s, #trail, #type
Constructor Details
#initialize(parent_group, path, name, opts, block) ⇒ Section
so it can be set when groups are “re-opened”…
362
363
364
365
366
367
368
369
370
|
# File 'lib/probatio.rb', line 362
def initialize(parent_group, path, name, opts, block)
@block_source_location = block && block.source_location
super(parent_group, path, name, opts, nil)
parent_group.add_section(self, block) \
if self.class == Probatio::Section
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
|
# File 'lib/probatio.rb', line 466
def method_missing(name, *args, &block)
if METHS.include?(name)
opts = args.find { |a| a.is_a?(Hash) }
args << {} unless opts; opts = args.last
opts[:pending] = true
send(name.to_s[1..-1], *args, &block)
else
super
end
end
|
Instance Method Details
#add_block(block) ⇒ Object
372
373
374
375
|
# File 'lib/probatio.rb', line 372
def add_block(block)
instance_eval(&block) if block
end
|
#add_file(path) ⇒ Object
377
378
379
380
381
382
|
# File 'lib/probatio.rb', line 377
def add_file(path)
@path = path
instance_eval(File.read(path), path, 1)
end
|
#add_section(section, block) ⇒ Object
493
494
495
496
497
|
# File 'lib/probatio.rb', line 493
def add_section(section, block)
s = ((@sections ||= {})[section.name] ||= section)
s.add_block(block)
end
|
#after(opts = {}, &block) ⇒ Object
415
416
417
|
# File 'lib/probatio.rb', line 415
def after(opts={}, &block)
@children << Probatio::After.new(self, @path, nil, opts, block)
end
|
#afters ⇒ Object
436
437
438
439
440
441
442
443
|
# File 'lib/probatio.rb', line 436
def afters
(
(@parent ? @parent.afters : []) +
group_sections.select { |c| c.is_a?(Probatio::After) } +
@children.select { |c| c.is_a?(Probatio::After) }
).reverse
end
|
#all_tests ⇒ Object
488
489
490
491
|
# File 'lib/probatio.rb', line 488
def all_tests
tests + groups.inject([]) { |a, g| a.concat(g.all_tests) }
end
|
#around(opts = {}, &block) ⇒ Object
418
419
420
|
# File 'lib/probatio.rb', line 418
def around(opts={}, &block)
@children << Probatio::Around.new(self, @path, nil, opts, block)
end
|
#arounds ⇒ Object
422
423
424
425
426
427
|
# File 'lib/probatio.rb', line 422
def arounds
(@parent ? @parent.arounds : []) +
group_sections.select { |s| s.is_a?(Probatio::Around) } +
@children.select { |c| c.is_a?(Probatio::Around) }
end
|
#before(opts = {}, &block) ⇒ Object
412
413
414
|
# File 'lib/probatio.rb', line 412
def before(opts={}, &block)
@children << Probatio::Before.new(self, @path, nil, opts, block)
end
|
#befores ⇒ Object
429
430
431
432
433
434
|
# File 'lib/probatio.rb', line 429
def befores
(@parent ? @parent.befores : []) +
group_sections.select { |s| s.is_a?(Probatio::Before) } +
@children.select { |c| c.is_a?(Probatio::Before) }
end
|
#context(h = {}) ⇒ Object
447
448
449
450
451
452
453
454
455
456
457
458
|
# File 'lib/probatio.rb', line 447
def context(h={})
fail ArgumentError.new('Probatio says "trailing RSpec context?"') \
unless h.is_a?(Hash)
instance_variables
.each { |k|
h[k] = instance_variable_get(k) unless ATTRS.include?(k) }
@parent.context(h) if @parent
h
end
|
#path=(pat) ⇒ Object
355
356
357
358
359
|
# File 'lib/probatio.rb', line 355
def path=(pat)
@path0 ||= @path
@path = pat
end
|
#run(run_opts) ⇒ Object
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# File 'lib/probatio.rb', line 384
def run(run_opts)
return Probatio.despatch(:group_excluded, self) \
if exclude?(run_opts)
return Probatio.despatch(:group_pending, self) \
if opts[:pending]
return Probatio.despatch(:group_skipped, self) \
if skip?(run_opts)
Probatio.despatch(:group_enter, self)
(
setups +
shuffle(tests_and_groups) +
teardowns
).each { |c| c.run(run_opts) }
Probatio.despatch(:group_leave, self)
end
|
#setup(opts = {}, &block) ⇒ Object
406
407
408
|
# File 'lib/probatio.rb', line 406
def setup(opts={}, &block)
@children << Probatio::Setup.new(self, @path, nil, opts, block)
end
|
#skip?(run_opts) ⇒ Boolean
482
483
484
485
486
|
# File 'lib/probatio.rb', line 482
def skip?(run_opts)
opts[:pending] ||
tests_and_groups.all? { |n| n.skip?(run_opts) }
end
|
#teardown(opts = {}, &block) ⇒ Object
409
410
411
|
# File 'lib/probatio.rb', line 409
def teardown(opts={}, &block)
@children << Probatio::Teardown.new(self, @path, nil, opts, block)
end
|