class Oktest::Node

Attributes

context_class[R]
fixtures[R]
hooks[R]
parent[R]
tag[R]

Public Class Methods

new(parent, tag: nil) click to toggle source
# File lib/oktest.rb, line 908
def initialize(parent, tag: nil)
  @parent   = parent
  @tag      = tag
  @children = []
  parent.add_child(self) if parent
  @context_class = Class.new(parent ? parent.context_class : Oktest::Context)
  @context_class.__node = self
  @fixtures = {}       # {name: [[param], block]}
  @hooks    = {}       # {name: block}
end

Public Instance Methods

_repr(depth=0, buf="") click to toggle source
# File lib/oktest.rb, line 1006
def _repr(depth=0, buf="")
  #; [!bt5j8] builds debug string.
  if depth < 0
    id_str = "%x" % self.object_id
    return "#<#{self.class.name}:0x#{id_str}>"
  end
  indent = "  " * depth
  id_str = "%x" % self.object_id
  buf << "#{indent}- #<#{self.class.name}:0x#{id_str}>\n"
  instance_variables().sort.each do |name|
    next if name.to_s == "@children"
    val = instance_variable_get(name)
    next if val.nil?
    next if val.respond_to?(:empty?) && val.empty?
    if val.respond_to?(:_repr)
      buf << "#{indent}  #{name}: #{val._repr(-1)}\n"
    else
      buf << "#{indent}  #{name}: #{val.inspect}\n"
    end
  end
  @children.each {|child| child._repr(depth+1, buf) }
  return buf
end
add_child(child) click to toggle source
# File lib/oktest.rb, line 923
def add_child(child)
  #; [!1fyk9] keeps children.
  @children << child
  #; [!w5r6l] returns self.
  self
end
clear_children() click to toggle source
# File lib/oktest.rb, line 953
def clear_children()
  #; [!o8xfb] removes all children.
  @children.clear()
  #; [!cvaq1] return self.
  self
end
each_child(&b) click to toggle source
# File lib/oktest.rb, line 935
def each_child(&b)
  #; [!osoep] returns enumerator if block not given.
  return @children.each unless block_given?()
  #; [!pve8m] yields block for each child.
  @children.each(&b)
  #; [!8z6un] returns nil.
  nil
end
get_fixture_block(name) click to toggle source
# File lib/oktest.rb, line 990
def get_fixture_block(name)
  #; [!f0105] returns fixture info.
  return @fixtures[name]
end
get_hook_block(key) click to toggle source
# File lib/oktest.rb, line 1001
def get_hook_block(key)
  #; [!u3fc6] returns block corresponding to key.
  return @hooks[key]
end
has_child?() click to toggle source
# File lib/oktest.rb, line 930
def has_child?
  #; [!xb30d] return true when no children, else false.
  return !@children.empty?
end
new_context_object() click to toggle source
# File lib/oktest.rb, line 973
def new_context_object()
  #; [!p271z] creates new context object.
  context = @context_class.new()
  #; [!9hbxn] context object has 'ok()' method.
  context.extend SpecHelper
  return context
end
register_fixture_block(name, location, &block) click to toggle source
# File lib/oktest.rb, line 981
def register_fixture_block(name, location, &block)
  #; [!5ctsn] registers fixture name, block, and location.
  params = Util.required_param_names_of_block(block)  # [Symbol]
  params = nil if params.empty?
  @fixtures[name] = [block, params, location]
  #; [!hfcvo] returns self.
  self
end
register_hook_block(key, &block) click to toggle source
# File lib/oktest.rb, line 995
def register_hook_block(key, &block)
  #; [!zb66o] registers block with key.
  @hooks[key] = block
  self
end
remove_child_at(index) click to toggle source
# File lib/oktest.rb, line 944
def remove_child_at(index)
  #; [!hsomo] removes child at index.
  child = @children.delete_at(index)
  #; [!7fhx1] unlinks reference between parent and child.
  child.unlink_parent() if child
  #; [!hiz1b] returns removed child.
  return child
end
run_block_in_context_class(&block) click to toggle source
# File lib/oktest.rb, line 968
def run_block_in_context_class(&block)
  #; [!j9qdh] run block in context class.
  @context_class.class_eval(&block)
end
topic?() click to toggle source
# File lib/oktest.rb, line 921
def topic?; false; end