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.



805
806
807
# File 'lib/oktest.rb', line 805

def __node
  @__node
end

Class Method Details

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

:nodoc:



830
831
832
833
834
# File 'lib/oktest.rb', line 830

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

.after(&block) ⇒ Object



866
867
868
869
870
# File 'lib/oktest.rb', line 866

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

.after_all(&block) ⇒ Object



878
879
880
881
882
# File 'lib/oktest.rb', line 878

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

.before(&block) ⇒ Object



860
861
862
863
864
# File 'lib/oktest.rb', line 860

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

.before_all(&block) ⇒ Object



872
873
874
875
876
# File 'lib/oktest.rb', line 872

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



822
823
824
825
826
827
828
# File 'lib/oktest.rb', line 822

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



816
817
818
819
820
# File 'lib/oktest.rb', line 816

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



852
853
854
855
856
857
858
# File 'lib/oktest.rb', line 852

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



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/oktest.rb', line 836

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



808
809
810
811
812
813
814
# File 'lib/oktest.rb', line 808

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