class Cucumber::Core::Test::TagFilter::TagLimits

Constants

TAG_MATCHER

Attributes

limit_list[R]

Public Class Methods

new(filter_expressions) click to toggle source
# File lib/cucumber/core/test/filters/tag_filter.rb, line 61
def initialize(filter_expressions)
  @limit_list = Array(filter_expressions).flat_map do |raw_expression|
    raw_expression.split(/\s*,\s*/)
  end.map do |filter_expression|
    TAG_MATCHER.match(filter_expression)
  end.compact.each_with_object({}) do |matchdata, limit_list|
    limit_list[matchdata[:tag_name]] = Integer(matchdata[:limit])
  end
end

Public Instance Methods

enforce(test_cases) click to toggle source
# File lib/cucumber/core/test/filters/tag_filter.rb, line 71
def enforce(test_cases)
  limit_breaches = limit_list.reduce([]) do |breaches, (tag_name, limit)|
    tag_count = test_cases.with_tag_name(tag_name).count
    if tag_count > limit
      tag_locations = test_cases.with_tag_name(tag_name).map(&:location)
      breaches << TagLimitBreach.new(
        tag_count,
        limit,
        tag_name,
        tag_locations
      )
    end
    breaches
  end
  raise TagExcess.new(limit_breaches) if limit_breaches.any?
  self
end