class Oktest::FixtureManager
Public Instance Methods
get_fixture_value(name, node, spec, context, location=nil, _resolved={}, _resolving=[])
click to toggle source
# File lib/oktest.rb, line 1660 def get_fixture_value(name, node, spec, context, location=nil, _resolved={}, _resolving=[]) return _resolved[name] if _resolved.key?(name) location ||= spec.location 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}" #; [!4xghy] calls fixture block with context object as self. val = context.instance_exec(*args, &block) else val = context.instance_eval(&block) end #; [!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]) if location raise exc end end
get_fixture_values(names, node, spec, context, location=nil, _resolved={}, _resolving=[])
click to toggle source
# File lib/oktest.rb, line 1645 def get_fixture_values(names, node, spec, context, location=nil, _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. location ||= spec.location 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
Private Instance Methods
_looped_dependency_error(name, resolving, location)
click to toggle source
# File lib/oktest.rb, line 1696 def _looped_dependency_error(name, resolving, location) resolving << name i = resolving.index(name) s1 = resolving[0...i].join('->') s2 = resolving[i..-1].join('=>') loop = s1.empty? ? s2 : "#{s1}->#{s2}" #location = $1 if location =~ /(.*:\d+)/ exc = LoopedDependencyError.new("fixture dependency is looped: #{loop}") exc.set_backtrace([location]) return exc end