Sha256: 5f26c2bfd9778916c5f93d486ea5e218886da122390592780de634855eeac6a4

Contents?: true

Size: 1.97 KB

Versions: 37

Compression:

Stored size: 1.97 KB

Contents

require 'gherkin/parser'

module ParallelTests
  module Gherkin
    class Listener
      attr_reader :collect

      attr_writer :ignore_tag_pattern

      def initialize
        @steps, @uris = [], []
        @collect = {}
        reset_counters!
      end

      def feature(feature)
        @feature = feature
      end

      def background(*args)
        @background = 1
      end

      def scenario(scenario)
        @outline = @background = 0
        return if should_ignore(scenario)
        @scenarios += 1
      end

      def scenario_outline(outline)
        return if should_ignore(outline)
        @outline = 1
      end

      def step(*args)
        return if @ignoring
        if @background == 1
          @background_steps += 1
        elsif @outline > 0
          @outline_steps += 1
        else
          @collect[@uri] += 1
        end
      end

      def uri(path)
        @uri = path
        @collect[@uri] = 0
      end

      #
      # @param  [Gherkin::Formatter::Model::Examples]  examples
      #
      def examples(examples)
        if examples.rows.size > 0
          @collect[@uri] += (@outline_steps * examples.rows.size)
        end
      end

      def eof(*args)
        @collect[@uri] += (@background_steps * @scenarios)
        reset_counters!
      end

      def reset_counters!
        @outline = @outline_steps = @background = @background_steps = @scenarios = 0
        @ignoring = nil
      end

      # ignore lots of other possible callbacks ...
      def method_missing(*args)
      end

      private

      # Return a combination of tags declared on this scenario/outline and the feature it belongs to
      def all_tags(scenario)
        (scenario.tags || []) + ((@feature && @feature.tags) || [])
      end

      # Set @ignoring if we should ignore this scenario/outline based on its tags
      def should_ignore(scenario)
        @ignoring = @ignore_tag_pattern && all_tags(scenario).find{ |tag| @ignore_tag_pattern === tag.name }
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
parallel_tests-2.29.1 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.29.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.28.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.27.1 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.27.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.26.2 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.26.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.25.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.24.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.23.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.22.1 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.22.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.21.3 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.21.2 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.21.1 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.21.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.20.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.19.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.18.0 lib/parallel_tests/gherkin/listener.rb
parallel_tests-2.17.1 lib/parallel_tests/gherkin/listener.rb