Sha256: 640d25b60cc32086d3c774cabc06e674e921f2b87fb1f132c47217648f74f7a9

Contents?: true

Size: 1.34 KB

Versions: 15

Compression:

Stored size: 1.34 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 |breach|
              breach << Breach.new(tag_name, limit, test_case_index.locations_of_tag_name(tag_name)) if test_case_index.count_by_tag_name(tag_name) > limit
            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, :limit, :locations
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
cucumber-9.2.0 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-9.1.2 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-9.1.1 lib/cucumber/filters/tag_limits/verifier.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/filters/tag_limits/verifier.rb
cucumber-9.1.0 lib/cucumber/filters/tag_limits/verifier.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/filters/tag_limits/verifier.rb
cucumber-9.0.2 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-9.0.1 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-9.0.0 lib/cucumber/filters/tag_limits/verifier.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/filters/tag_limits/verifier.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/filters/tag_limits/verifier.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/filters/tag_limits/verifier.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/filters/tag_limits/verifier.rb
cucumber-8.0.0 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-8.0.0.rc.1 lib/cucumber/filters/tag_limits/verifier.rb