Sha256: 4258f31234c17a3a64d391c16d17b5adb7ba46d3441be18485fc43244781f33f
Contents?: true
Size: 1.42 KB
Versions: 5
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true module Cucumber module Filters class TagLimits class Verifier def initialize(tag_limits) @tag_limits = tag_limits end def verify!(test_case_index) breaches = collect_breaches(test_case_index) raise TagLimitExceededError.new(*breaches) unless breaches.empty? end private def collect_breaches(test_case_index) tag_limits.reduce([]) do |breaches, (tag_name, limit)| breaches.tap do |breaches| if test_case_index.count_by_tag_name(tag_name) > limit breaches << Breach.new(tag_name, limit, test_case_index.locations_of_tag_name(tag_name)) end end end end attr_reader :tag_limits class Breach INDENT = (' ' * 2).freeze def initialize(tag_name, limit, locations) @tag_name = tag_name @limit = limit @locations = locations end def to_s [ "#{tag_name} occurred #{tag_count} times, but the limit was set to #{limit}", *locations.map(&:to_s) ].join("\n#{INDENT}") end private def tag_count locations.count end attr_reader :tag_name attr_reader :limit attr_reader :locations end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems