Sha256: bcce90c3784d1b1a353fa67e777ee10db001f0844dd011d39e768aad247eddf7

Contents?: true

Size: 1.09 KB

Versions: 16

Compression:

Stored size: 1.09 KB

Contents

module ATP
  module Processors
    # Runs at the very end of a processor run, to do some final cleanup,
    # e.g. to assign generated IDs to tests that don't have one
    class PostCleaner < Processor
      # Returns a hash containing the IDs of all tests that have
      # been used
      attr_reader :ids

      # Extracts all ID values of tests within the given AST
      class ExtractTestIDs < Processor
        attr_reader :results

        def on_test(node)
          id = node.children.find { |n| n.type == :id }
          if id
            @results ||= {}
            @results[id] = true
          end
        end
      end

      def process(node)
        # On first call extract the test_result nodes from the given AST,
        # then process as normal thereafter
        if @first_call_done
          result = super
        else
          @first_call_done = true
          t = ExtractTestIDs.new
          t.process(node)
          @ids = t.results || {}
          result = super
          @first_call_done = false
        end
        result
      end

      def on_test(node)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
atp-0.8.0 lib/atp/processors/post_cleaner.rb
atp-0.7.0 lib/atp/processors/post_cleaner.rb
atp-0.6.0 lib/atp/processors/post_cleaner.rb
atp-0.5.4 lib/atp/processors/post_cleaner.rb
atp-0.5.3 lib/atp/processors/post_cleaner.rb
atp-0.5.0 lib/atp/processors/post_cleaner.rb
atp-0.4.3 lib/atp/processors/post_cleaner.rb
atp-0.4.2 lib/atp/processors/post_cleaner.rb
atp-0.4.1 lib/atp/processors/post_cleaner.rb
atp-0.4.0 lib/atp/processors/post_cleaner.rb
atp-0.3.3 lib/atp/processors/post_cleaner.rb
atp-0.3.2 lib/atp/processors/post_cleaner.rb
atp-0.3.1 lib/atp/processors/post_cleaner.rb
atp-0.3.0 lib/atp/processors/post_cleaner.rb
atp-0.2.1 lib/atp/processors/post_cleaner.rb
atp-0.2.0 lib/atp/processors/post_cleaner.rb