Sha256: 9bebbc77acaa7606e728df4944fea81727b6f9db43cdab35f6158167c493ec35

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

#the main module
module TheArrayComparator
  # helper for tests
  module TestingHelper

    # Generate data for the tests
    #
    # @param [Hash] options
    #
    # @option options [Array] :keywords
    #   the keywords which should be hidden in the data
    # 
    # @option options [Array] :raw_data
    #   the data which should be used to hide the keywords
    #
    # @option options [Integer] :count_of_data
    #   how much raw data should be generated if none is given
    #
    # @return [Array]
    #   the testdata (raw_data + keywords)
    def generate_testdata(options)
      opts = {
        keywords: [],
        raw_data: [],
        count_of_data: 100,
      }.merge options

      raw_data = options[:raw_data] || Faker::Lorem.sentences(opts[:count_of_data])
      dataset = DataSet.new(options[:keywords],raw_data)

      testdata = TestData.new(dataset)
      testdata.generate
    end
  end
end

module Kernel
  #
  # Captures the given stream and returns it:
  #
  #   stream = capture(:stdout) { puts 'Cool' }
  #   stream # => "Cool\n"
  def capture(stream)
    begin
      stream = stream.to_s
      eval "$#{stream} = StringIO.new"
      yield
      result = eval("$#{stream}").string
    ensure
      eval("$#{stream} = #{stream.upcase}")
    end

    result
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
the_array_comparator-0.5.0 lib/the_array_comparator/testing_helper.rb
the_array_comparator-0.4.0 lib/the_array_comparator/testing_helper.rb
the_array_comparator-0.3.4 lib/the_array_comparator/testing_helper.rb
the_array_comparator-0.3.1 lib/the_array_comparator/testing_helper.rb
the_array_comparator-0.3.0 lib/the_array_comparator/testing_helper.rb
the_array_comparator-0.2.0 lib/the_array_comparator/testing_helper.rb
the_array_comparator-0.1.1 lib/the_array_comparator/testing_helper.rb