Sha256: 38149b215e7eadf5ce5434d41e1698e6fa474f15f928aca2582033dbe4ee10b0

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

module ATP
  # This class is responsible for executing the given test flow based on a given
  # set of runtime conditions.
  # A subset of the input AST will be returned containing only the nodes that would
  # be hit when the flow is executed under the given conditions.
  class Runner < Processor
    def run(node, options = {})
      @options = options
      process(node)
    end

    def on_flow(node)
      @flow = []
      process_all(node.children)
      node.updated(nil, @flow)
    end

    def on_flow_flag(node)
      flag, enabled, *nodes = *node
      if (enabled && flow_flags.include?(flag)) ||
         (!enabled && !flow_flags.include?(flag))
        process_all(nodes)
      end
    end

    def on_test(node)
      if id = node.find(:id)
        id = id.to_a[0]
        if failed_test_ids.include?(id)
          node = node.add(n0(:failed))
        end
      end
      @flow << node
    end

    def on_test_result(node)
      id, passed, *nodes = *node
      if (passed && !failed_test_ids.include?(id)) ||
         (!passed && failed_test_ids.include?(id))
        process_all(nodes)
      end
    end

    def failed_test_ids
      @failed_test_ids ||= [@options[:failed_test_id] || @options[:failed_test_ids]].flatten.compact
    end

    # Returns an array of enabled flow flags
    def flow_flags
      @flow_flags ||= [@options[:flow_flag] || @options[:flow_flags]].flatten.compact
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
atp-0.2.1 lib/atp/runner.rb
atp-0.2.0 lib/atp/runner.rb