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.



849
850
851
# File 'lib/oktest.rb', line 849

def __node
  @__node
end

Class Method Details

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

:nodoc:



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

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

.after(&block) ⇒ Object



913
914
915
916
917
# File 'lib/oktest.rb', line 913

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

.after_all(&block) ⇒ Object



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

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

.before(&block) ⇒ Object



907
908
909
910
911
# File 'lib/oktest.rb', line 907

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

.before_all(&block) ⇒ Object



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

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



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

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



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

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



899
900
901
902
903
904
905
# File 'lib/oktest.rb', line 899

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



880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/oktest.rb', line 880

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



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

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