Sha256: e241e9ef2427a1c1b93fd5c1f9e9e46002434db8062414387426971e34335716

Contents?: true

Size: 1.39 KB

Versions: 21

Compression:

Stored size: 1.39 KB

Contents

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

21 entries across 21 versions & 2 rubygems

Version Path
cucumber-2.99.0 lib/cucumber/filters/tag_limits/verifier.rb
mobiusloop-0.1.5 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.4.0 lib/cucumber/filters/tag_limits/verifier.rb
mobiusloop-0.1.3 lib/cucumber/filters/tag_limits/verifier.rb
mobiusloop-0.1.2 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.3.3 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.3.2 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.3.1 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.3.0 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.2.0 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.1.0 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.2 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.1 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0.rc.5 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0.rc.4 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0.rc.3 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0.rc.2 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0.rc.1 lib/cucumber/filters/tag_limits/verifier.rb
cucumber-2.0.0.beta.5 lib/cucumber/filters/tag_limits/verifier.rb