Class: Oktest::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/oktest.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.__nodeObject

Returns the value of attribute __node.



559
560
561
# File 'lib/oktest.rb', line 559

def __node
  @__node
end

Class Method Details

.__case_when(desc, tag, &block) ⇒ Object

:nodoc:



584
585
586
587
588
# File 'lib/oktest.rb', line 584

def self.__case_when(desc, tag, &block)  #:nodoc:
  to = topic(desc, tag: tag, &block)
  to._prefix = '-'
  return to
end

.after(&block) ⇒ Object



620
621
622
623
624
# File 'lib/oktest.rb', line 620

def self.after(&block)
  #; [!ngkvz] registers 'after' hook block.
  @__node.register_hook_block(:after, &block)
  self
end

.after_all(&block) ⇒ Object



632
633
634
635
636
# File 'lib/oktest.rb', line 632

def self.after_all(&block)
  #; [!0w5ik] registers 'after_all' hook block.
  @__node.register_hook_block(:after_all, &block)
  self
end

.before(&block) ⇒ Object



614
615
616
617
618
# File 'lib/oktest.rb', line 614

def self.before(&block)
  #; [!275zr] registers 'before' hook block.
  @__node.register_hook_block(:before, &block)
  self
end

.before_all(&block) ⇒ Object



626
627
628
629
630
# File 'lib/oktest.rb', line 626

def self.before_all(&block)
  #; [!8v1y4] registers 'before_all' hook block.
  @__node.register_hook_block(:before_all, &block)
  self
end

.case_else(desc = nil, tag: nil, &block) ⇒ Object



576
577
578
579
580
581
582
# File 'lib/oktest.rb', line 576

def self.case_else(desc=nil, tag: nil, &block)
  #; [!hs1to] 1st parameter is optional.
  desc = desc ? "Else #{desc}" : "Else"
  #; [!oww4b] returns topic object.
  #; [!j5gnp] target is a description which is 'Else'.
  return __case_when(desc, tag, &block)
end

.case_when(desc, tag: nil, &block) ⇒ Object



570
571
572
573
574
# File 'lib/oktest.rb', line 570

def self.case_when(desc, tag: nil, &block)
  #; [!g3cvh] returns topic object.
  #; [!ofw1i] target is a description starting with 'When '.
  return __case_when("When #{desc}", tag, &block)
end

.fixture(name, &block) ⇒ Object



606
607
608
609
610
611
612
# File 'lib/oktest.rb', line 606

def self.fixture(name, &block)
  #; [!8wfrq] registers fixture factory block.
  #; [!y3ks3] retrieves block parameter names.
  location = caller(1).first  # caller() makes performance slower, but necessary.
  @__node.register_fixture_block(name, location, &block)
  self
end

.spec(desc, tag: nil, &block) ⇒ Object



590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/oktest.rb', line 590

def self.spec(desc, tag: nil, &block)
  node = @__node
  node.is_a?(Node)  or raise "internal error: node=#{node.inspect}"  # for debug
  #; [!ala78] provides raising TodoException block if block not given.
  block ||= proc { raise TodoException, "not implemented yet" }
  #; [!x48db] keeps called location only when block has parameters.
  if block.parameters.empty?
    location = nil
  else
    location = caller(1).first  # caller() makes performance slower, but necessary.
  end
  #; [!c8c8o] creates new spec object.
  spec = SpecLeaf.new(node, desc, tag: tag, location: location, &block)
  return spec
end

.topic(target, tag: nil, &block) ⇒ Object



562
563
564
565
566
567
568
# File 'lib/oktest.rb', line 562

def self.topic(target, tag: nil, &block)
  #; [!0gfvq] creates new topic node.
  node = @__node
  topic = TopicNode.new(node, target, tag: tag)
  topic.run_block_in_context_class(&block)
  return topic
end