Class: Cucumber::Core::Test::TagFilter::TagLimits

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/core/test/filters/tag_filter.rb

Constant Summary collapse

TAG_MATCHER =
/^
  (?:~)?                 #The tag negation symbol "~". This is optional and not captured.
  (?<tag_name>\@[\w\d]+) #Captures the tag name including the "@" symbol.
  \:                     #The seperator, ":", between the tag name and the limit.
  (?<limit>\d+)          #Caputres the limit number.
$/x

Instance Method Summary collapse

Constructor Details

#initialize(filter_expressions) ⇒ TagLimits

Returns a new instance of TagLimits.



59
60
61
62
63
64
65
66
67
# File 'lib/cucumber/core/test/filters/tag_filter.rb', line 59

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

Instance Method Details

#enforce(test_cases) ⇒ Object

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cucumber/core/test/filters/tag_filter.rb', line 69

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