Class: Oktest::Node
Instance Attribute Summary collapse
-
#context_class ⇒ Object
readonly
Returns the value of attribute context_class.
-
#fixtures ⇒ Object
readonly
Returns the value of attribute fixtures.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #_repr(depth = 0, buf = "") ⇒ Object
- #add_child(child) ⇒ Object
- #clear_children ⇒ Object
- #each_child(&b) ⇒ Object
- #get_fixture_block(name) ⇒ Object
- #get_hook_block(key) ⇒ Object
- #has_child? ⇒ Boolean
-
#initialize(parent, tag: nil) ⇒ Node
constructor
A new instance of Node.
- #new_context_object ⇒ Object
- #register_fixture_block(name, location, &block) ⇒ Object
- #register_hook_block(key, &block) ⇒ Object
- #remove_child_at(index) ⇒ Object
- #run_block_in_context_class(&block) ⇒ Object
- #topic? ⇒ Boolean
- #unlink_parent ⇒ Object
Methods inherited from Item
Constructor Details
#initialize(parent, tag: nil) ⇒ Node
Returns a new instance of Node.
909 910 911 912 913 914 915 916 917 918 |
# File 'lib/oktest.rb', line 909 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 |
Instance Attribute Details
#context_class ⇒ Object (readonly)
Returns the value of attribute context_class.
920 921 922 |
# File 'lib/oktest.rb', line 920 def context_class @context_class end |
#fixtures ⇒ Object (readonly)
Returns the value of attribute fixtures.
920 921 922 |
# File 'lib/oktest.rb', line 920 def fixtures @fixtures end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
920 921 922 |
# File 'lib/oktest.rb', line 920 def hooks @hooks end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
920 921 922 |
# File 'lib/oktest.rb', line 920 def parent @parent end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
920 921 922 |
# File 'lib/oktest.rb', line 920 def tag @tag end |
Instance Method Details
#_repr(depth = 0, buf = "") ⇒ Object
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'lib/oktest.rb', line 1007 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) ⇒ Object
924 925 926 927 928 929 |
# File 'lib/oktest.rb', line 924 def add_child(child) #; [!1fyk9] keeps children. @children << child #; [!w5r6l] returns self. self end |
#clear_children ⇒ Object
954 955 956 957 958 959 |
# File 'lib/oktest.rb', line 954 def clear_children() #; [!o8xfb] removes all children. @children.clear() #; [!cvaq1] return self. self end |
#each_child(&b) ⇒ Object
936 937 938 939 940 941 942 943 |
# File 'lib/oktest.rb', line 936 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) ⇒ Object
991 992 993 994 |
# File 'lib/oktest.rb', line 991 def get_fixture_block(name) #; [!f0105] returns fixture info. return @fixtures[name] end |
#get_hook_block(key) ⇒ Object
1002 1003 1004 1005 |
# File 'lib/oktest.rb', line 1002 def get_hook_block(key) #; [!u3fc6] returns block corresponding to key. return @hooks[key] end |
#has_child? ⇒ Boolean
931 932 933 934 |
# File 'lib/oktest.rb', line 931 def has_child? #; [!xb30d] return true when no children, else false. return !@children.empty? end |
#new_context_object ⇒ Object
974 975 976 977 978 979 980 |
# File 'lib/oktest.rb', line 974 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) ⇒ Object
982 983 984 985 986 987 988 989 |
# File 'lib/oktest.rb', line 982 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) ⇒ Object
996 997 998 999 1000 |
# File 'lib/oktest.rb', line 996 def register_hook_block(key, &block) #; [!zb66o] registers block with key. @hooks[key] = block self end |
#remove_child_at(index) ⇒ Object
945 946 947 948 949 950 951 952 |
# File 'lib/oktest.rb', line 945 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) ⇒ Object
969 970 971 972 |
# File 'lib/oktest.rb', line 969 def run_block_in_context_class(&block) #; [!j9qdh] run block in context class. @context_class.class_eval(&block) end |
#topic? ⇒ Boolean
922 |
# File 'lib/oktest.rb', line 922 def topic?; false; end |
#unlink_parent ⇒ Object
961 962 963 964 965 966 967 |
# File 'lib/oktest.rb', line 961 def unlink_parent() #; [!59m52] clears '@parent' instance variable. #; [!qksxv] returns parent object. parent = @parent @parent = nil return parent end |