Class: Cucumber::Core::Test::TagFilter::TagLimits
- Inherits:
-
Object
- Object
- Cucumber::Core::Test::TagFilter::TagLimits
- 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+) #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
- #enforce(test_cases) ⇒ Object
-
#initialize(filter_expressions) ⇒ TagLimits
constructor
A new instance of TagLimits.
Constructor Details
#initialize(filter_expressions) ⇒ TagLimits
Returns a new instance of TagLimits.
61 62 63 64 65 66 67 68 69 |
# 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 |
Instance Method Details
#enforce(test_cases) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 |