Sha256: 002550bdb76c341deaca0eb97f6606cef86e2dfcedd8f7cc4f1be5474d646851

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require_relative 'helper'

class TestUniqueUtils < Test::Unit::TestCase
  def test_generates_unique_values
    unique_object = FFaker::UniqueUtils.new(FFaker::Name, 10_000)

    result = [unique_object.name, unique_object.name]
    assert_operator(result[0], :!=, result[1])
  end

  def test_returns_error_when_retries_exceeded
    stubbed_generator = Object.new
    def stubbed_generator.test
      1
    end

    unique_object = FFaker::UniqueUtils.new(stubbed_generator, 3)

    unique_object.test

    assert_raises FFaker::UniqueUtils::RetryLimitExceeded do
      unique_object.test
    end
  end

  def test_clears_unique_values
    stubbed_generator = Object.new
    def stubbed_generator.test
      1
    end

    unique_object = FFaker::UniqueUtils.new(stubbed_generator, 3)

    assert_equal(1, unique_object.test)

    assert_raises FFaker::UniqueUtils::RetryLimitExceeded do
      unique_object.test
    end

    FFaker::UniqueUtils.clear

    assert_equal(1, unique_object.test)

    assert_raises FFaker::UniqueUtils::RetryLimitExceeded do
      unique_object.test
    end

    unique_object.clear

    assert_equal(1, unique_object.test)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffaker-2.21.0 test/test_unique_utils.rb
ffaker-2.20.0 test/test_unique_utils.rb
ffaker-2.19.0 test/test_unique_utils.rb