Sha256: 7f16eecde2d6e2c587a8831d421d99a6177587ce65d2371b98500f177d5f3280

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

# encoding: utf-8
require 'helper'

class TestFakerNameCS < Test::Unit::TestCase
  def setup
    @tester = Faker::NameCS
  end

  def test_name
    @words = @tester.name.split
    assert [2,3,4].include?(@words.size) # just name, or prefix, or prefix+suffix
  end

  def test_name_sex
    @words = @tester.name.split
    @words = @words[1..2] if @words.size > 2
    assert same_sex?(@words)
  end

  def test_male_last_name
    assert Faker::NameCS::LAST_NAMES[:male].include?(@tester.last_name(:male))
  end

  def test_male_first_name
    assert Faker::NameCS::FIRST_NAMES[:male].include?(@tester.first_name(:male))
  end

  def test_prefix
    assert Faker::NameCS::PREFIXES.include?(@tester.prefix)
  end

  def test_suffix
    assert Faker::NameCS::SUFFIXES.include?(@tester.suffix)
  end

  def test_with_same_sex
    names = []
    @tester.with_same_sex do
      names << @tester.last_name
      names << @tester.first_name
    end
    assert same_sex?(names)
  end

  def test_with_same_sex_for_male
    names = []
    @tester.with_same_sex(:male) do
      names << @tester.last_name
      names << @tester.first_name
    end
    assert same_sex?(names, :male)
  end

  # checks if every name is of the same sex
  def same_sex?(words, sex = :any)
    (sex == :any ? [:male, :female] : [sex]).any? do |sex|
      words.all? do |word|
        [Faker::NameCS::LAST_NAMES, Faker::NameCS::FIRST_NAMES].any? do |names|
          names[sex].include?(word)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffaker-1.21.0 test/test_faker_name_cs.rb
ffaker-1.20.0 test/test_faker_name_cs.rb
ffaker-1.19.0 test/test_faker_name_cs.rb