Sha256: a699163d7e466f3597ac20201fc376fce7d2f7b9fbc51b75d985f07dba8b8d24

Contents?: true

Size: 1.57 KB

Versions: 29

Compression:

Stored size: 1.57 KB

Contents

require 'cucumber/errors'

module Cucumber
  class Runtime

    class FeaturesLoader
      include Formatter::Duration

      def initialize(feature_files, filters, tag_expression)
        @feature_files, @filters, @tag_expression = feature_files, filters, tag_expression
      end

      def features
        load unless (defined? @features) and @features
        @features
      end

    private

      def load
        features = Ast::Features.new

        tag_counts = {}
        start = Time.new
        log.debug("Features:\n")
        @feature_files.each do |f|
          feature_file = FeatureFile.new(f)
          feature = feature_file.parse(@filters, tag_counts)
          if feature
            features.add_feature(feature)
            log.debug("  * #{f}\n")
          end
        end
        duration = Time.now - start
        log.debug("Parsing feature files took #{format_duration(duration)}\n\n")

        check_tag_limits(tag_counts)

        @features = features
      end

      def check_tag_limits(tag_counts)
        error_messages = []
        @tag_expression.limits.each do |tag_name, tag_limit|
          tag_locations = (tag_counts[tag_name] || [])
          tag_count = tag_locations.length
          if tag_count > tag_limit
            error = "#{tag_name} occurred #{tag_count} times, but the limit was set to #{tag_limit}\n  " +
              tag_locations.join("\n  ")
            error_messages << error
          end
        end
        raise TagExcess.new(error_messages) if error_messages.any?
      end

      def log
        Cucumber.logger
      end
    end

  end
end

Version data entries

29 entries across 27 versions & 2 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/cucumber-1.3.18/lib/cucumber/runtime/features_loader.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/cucumber-1.3.18/lib/cucumber/runtime/features_loader.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/cucumber-1.3.16/lib/cucumber/runtime/features_loader.rb
cucumber-1.3.20 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.19 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.18 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.17 lib/cucumber/runtime/features_loader.rb
cucumber-2.0.0.beta.2 lib/cucumber/runtime/features_loader.rb
cucumber-2.0.0.beta.1 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.16 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.15 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.14 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.13 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.12 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.11 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.10 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.9 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.8 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.7 lib/cucumber/runtime/features_loader.rb
cucumber-1.3.6 lib/cucumber/runtime/features_loader.rb