Class: Probatio::Section

Inherits:
Node
  • Object
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

Methods included from Waiters

#monow, #wait_until

Methods included from Helpers

#beep, #jruby?, #time, #windows?

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"...



396
397
398
399
400
401
402
403
404
# File 'lib/probatio.rb', line 396

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



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/probatio.rb', line 500

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



406
407
408
409
# File 'lib/probatio.rb', line 406

def add_block(block)

  instance_eval(&block) if block
end

#add_file(path) ⇒ Object



411
412
413
414
415
416
# File 'lib/probatio.rb', line 411

def add_file(path)

  @path = path

  instance_eval(File.read(path), path, 1)
end

#add_section(section, block) ⇒ Object



527
528
529
530
531
# File 'lib/probatio.rb', line 527

def add_section(section, block)

  s = ((@sections ||= {})[section.name] ||= section)
  s.add_block(block)
end

#after(opts = {}, &block) ⇒ Object



449
450
451
# File 'lib/probatio.rb', line 449

def after(opts={}, &block)
  @children << Probatio::After.new(self, @path, nil, opts, block)
end

#aftersObject



470
471
472
473
474
475
476
477
# File 'lib/probatio.rb', line 470

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_testsObject



522
523
524
525
# File 'lib/probatio.rb', line 522

def all_tests

  tests + groups.inject([]) { |a, g| a.concat(g.all_tests) }
end

#around(opts = {}, &block) ⇒ Object



452
453
454
# File 'lib/probatio.rb', line 452

def around(opts={}, &block)
  @children << Probatio::Around.new(self, @path, nil, opts, block)
end

#aroundsObject



456
457
458
459
460
461
# File 'lib/probatio.rb', line 456

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



446
447
448
# File 'lib/probatio.rb', line 446

def before(opts={}, &block)
  @children << Probatio::Before.new(self, @path, nil, opts, block)
end

#beforesObject



463
464
465
466
467
468
# File 'lib/probatio.rb', line 463

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



481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/probatio.rb', line 481

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



389
390
391
392
393
# File 'lib/probatio.rb', line 389

def path=(pat)

  @path0 ||= @path
  @path = pat
end

#run(run_opts) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/probatio.rb', line 418

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



440
441
442
# File 'lib/probatio.rb', line 440

def setup(opts={}, &block)
  @children << Probatio::Setup.new(self, @path, nil, opts, block)
end

#skip?(run_opts) ⇒ Boolean

Returns:

  • (Boolean)


516
517
518
519
520
# File 'lib/probatio.rb', line 516

def skip?(run_opts)

  opts[:pending] ||
  tests_and_groups.all? { |n| n.skip?(run_opts) }
end

#teardown(opts = {}, &block) ⇒ Object



443
444
445
# File 'lib/probatio.rb', line 443

def teardown(opts={}, &block)
  @children << Probatio::Teardown.new(self, @path, nil, opts, block)
end