Class: Oktest::FixtureManager

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

Instance Method Summary collapse

Instance Method Details

#get_fixture_value(name, node, spec, context, location, resolved = {}, _resolving = []) ⇒ Object



1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
# File 'lib/oktest.rb', line 1795

def get_fixture_value(name, node, spec, context, location, resolved={}, _resolving=[])
  return resolved[name] if resolved.key?(name)
  tuple = node.get_fixture_block(name)
  if tuple
    block, param_names, location = tuple
    #; [!2esaf] resolves fixture dependencies.
    if param_names
      _resolving << name
      args = get_fixture_values(param_names, node, spec, context, location, resolved, _resolving)
      (popped = _resolving.pop) == name  or
        raise "** assertion failed: name=#{name.inspect}, resolvng[-1]=#{popped.inspect}"
    else
      args = []
    end
    #; [!gyyst] overwrites keyword params by fixture values.
    kwnames = Util.keyword_param_names_of_block(block)
    kwargs = {}
    kwnames.each {|name| kwargs[name] = resolved[name] if resolved.key?(name) }
    #; [!4xghy] calls fixture block with context object as self.
    val = context.instance_exec(*args, **kwargs, &block)
    #; [!8t3ul] caches fixture value to call fixture block only once per spec.
    resolved[name] = val
    return val
  elsif node.parent
    #; [!4chb9] traverses parent topics if fixture not found in current topic.
    return get_fixture_value(name, node.parent, spec, context, location, resolved, _resolving)
  elsif ! node.equal?(THE_GLOBAL_SCOPE)
    #; [!wt3qk] suports global scope.
    return get_fixture_value(name, THE_GLOBAL_SCOPE, spec, context, location, resolved, _resolving)
  else
    #; [!nr79z] raises error when fixture not found.
    exc = FixtureNotFoundError.new("#{name}: fixture not found. (spec: #{spec.desc})")
    exc.set_backtrace([location.to_s]) if location
    raise exc
  end
end

#get_fixture_values(names, node, spec, context, location, resolved = {}, _resolving = []) ⇒ Object



1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
# File 'lib/oktest.rb', line 1781

def get_fixture_values(names, node, spec, context, location, resolved={}, _resolving=[])
  #; [!w6ffs] resolves 'this_topic' fixture name as target objec of current topic.
  resolved[:this_topic] = node.target if !resolved.key?(:this_topic) && node.topic?
  #; [!ja2ew] resolves 'this_spec' fixture name as description of current spec.
  resolved[:this_spec]  = spec.desc   if !resolved.key?(:this_spec)
  #; [!v587k] resolves fixtures.
  return names.collect {|name|
    #; [!np4p9] raises error when loop exists in dependency.
    ! _resolving.include?(name)  or
      raise _looped_dependency_error(name, _resolving, location)
    get_fixture_value(name, node, spec, context, location, resolved, _resolving)
  }
end