File: test_name_ja.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (51 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

require_relative 'helper'

class TestFakerNameJA < Test::Unit::TestCase
  class << self
    def startup
      FFaker::NameJA.const_set(:FIRST_NAMES, %w[あきら フミ 三郎])
      FFaker::NameJA.const_set(:LAST_NAMES, %w[佐藤 高橋 佐々木])
    end

    def shutdown
      FFaker::NameJA.class_eval { remove_const(:FIRST_NAMES) }
      FFaker::NameJA.class_eval { remove_const(:LAST_NAMES) }
    end
  end

  include DeterministicHelper

  assert_methods_are_deterministic(
    FFaker::NameJA,
    :last_name, :first_name, :last_first, :name
  )

  def setup
    @tester = FFaker::NameJA
  end

  def test_first_name
    assert_include(@tester::FIRST_NAMES, @tester.first_name)
  end

  def test_last_name
    assert_include(@tester::LAST_NAMES, @tester.last_name)
  end

  def test_last_first
    assert_last_first(@tester.last_first)
  end

  def test_name
    assert_last_first(@tester.name)
  end

  private

  def assert_last_first(actual)
    last_first_regexp = /(#{@tester::LAST_NAMES.join('|')})(#{@tester::FIRST_NAMES.join('|')})/
    assert_match(last_first_regexp, actual)
  end
end