Class: Oktest::Context

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

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from UtilHelper

partial_regexp, partial_regexp!

Class Attribute Details

.__nodeObject

Returns the value of attribute __node.



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

def __node
  @__node
end

Class Method Details

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

:nodoc:



893
894
895
896
897
# File 'lib/oktest.rb', line 893

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

.after(&block) ⇒ Object



932
933
934
935
936
# File 'lib/oktest.rb', line 932

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

.after_all(&block) ⇒ Object



944
945
946
947
948
# File 'lib/oktest.rb', line 944

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

.before(&block) ⇒ Object



926
927
928
929
930
# File 'lib/oktest.rb', line 926

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

.before_all(&block) ⇒ Object



938
939
940
941
942
# File 'lib/oktest.rb', line 938

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



882
883
884
885
886
887
888
889
890
891
# File 'lib/oktest.rb', line 882

def self.case_else(desc=nil, tag: nil, &block)
  #; [!hs1to] 1st parameter is optional.
  desc ||= "Else"
  #; [!j5gnp] target is a description which is 'Else'.
  #; [!3nn8d] not add 'Else ' if description starts with it.
  rexp = /^(\[!\w+\] )?[eE]lse\b/
  desc2 = desc =~ rexp ? desc : "Else #{desc}"
  #; [!oww4b] returns topic object.
  return __case_when(desc2, tag, &block)
end

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



873
874
875
876
877
878
879
880
# File 'lib/oktest.rb', line 873

def self.case_when(desc, tag: nil, &block)
  #; [!ofw1i] target is a description starting with 'When '.
  #; [!53qxv] not add 'When ' if description starts with it.
  rexp = /^(\[!\w+\] )?[wW]hen\b/
  desc2 = desc =~ rexp ? desc : "When #{desc}"
  #; [!g3cvh] returns topic object.
  return __case_when(desc2, tag, &block)
end

.fixture(name, &block) ⇒ Object



918
919
920
921
922
923
924
# File 'lib/oktest.rb', line 918

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

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



899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# File 'lib/oktest.rb', line 899

def self.spec(desc, tag: nil, fixture: nil, &block)
  node = @__node
  node.is_a?(Node)  or raise "internal error: node=#{node.inspect}"  # for debug
  #; [!4vkbl] error when `fixture:` keyword arg is not a Hash object.
  fixture.nil? || fixture.is_a?(Hash)  or
    raise ArgumentError, "spec(fixture: #{fixture.inspect}): fixture argument should be a Hash object, but got #{fixture.class.name} object."
  #; [!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_locations(1, 1).first
  end
  #; [!c8c8o] creates new spec object.
  spec = SpecLeaf.new(node, desc, tag: tag, fixture: fixture, location: location, &block)
  return spec
end

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



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

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