Sha256: 804ba2d80aad6576f6d2119ee1664ed8683de16c311b6d35fa8140ce4a899863

Contents?: true

Size: 928 Bytes

Versions: 5

Compression:

Stored size: 928 Bytes

Contents

require 'digest/sha2'

module Cucumber
  module Filters

    # Batches up all test cases, randomizes them, and then sends them on
    class Randomizer
      def initialize(seed, receiver=nil)
        @receiver = receiver
        @test_cases = []
        @seed = seed
      end

      def test_case(test_case)
        @test_cases << test_case
        self
      end

      def done
        shuffled_test_cases.each do |test_case|
          test_case.describe_to(@receiver)
        end
        @receiver.done
        self
      end

      def with_receiver(receiver)
        self.class.new(@seed, receiver)
      end

      private

      def shuffled_test_cases
        digester = Digest::SHA2.new(256)
        @test_cases.map.with_index.
          sort_by { |_, index| digester.digest((@seed + index).to_s) }.
          map { |test_case, _| test_case }
      end

      attr_reader :seed
      private :seed
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
cucumber-2.99.0 lib/cucumber/filters/randomizer.rb
mobiusloop-0.1.5 lib/cucumber/filters/randomizer.rb
cucumber-2.4.0 lib/cucumber/filters/randomizer.rb
mobiusloop-0.1.3 lib/cucumber/filters/randomizer.rb
mobiusloop-0.1.2 lib/cucumber/filters/randomizer.rb