File: test_faker_address.rb

package info (click to toggle)
ruby-faker 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,596 kB
  • sloc: ruby: 20,656; sh: 6; makefile: 6
file content (101 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerAddress < Test::Unit::TestCase
  def setup
    @tester = Faker::Address
  end

  def test_city
    assert_match(/\w+/, @tester.city)
  end

  def test_city_with_state
    assert_match(/\w+,\s\w+/, @tester.city(options: { with_state: true }))
  end

  def test_street_name
    assert_match(/\w+\s\w+/, @tester.street_name)
  end

  def test_street_address
    assert_match(/\d+\s\w+\s\w+/, @tester.street_address)
  end

  def test_secondary_address
    assert_match(/\w+\.?\s\d+/, @tester.secondary_address)
  end

  def test_building_number
    assert_match(/\d+/, @tester.building_number)
  end

  def test_mail_box
    assert_match(/[\w ]+\d+/, @tester.mail_box)
  end

  def test_zip_code
    assert_match(/^\d+-?\d*$/, @tester.zip_code)
  end

  def test_time_zone
    assert_match %r{\w+/\w+}, @tester.time_zone
  end

  def test_street_suffix
    assert_match(/\w+/, @tester.street_suffix)
  end

  def test_city_suffix
    assert_match(/\w+/, @tester.city_suffix)
  end

  def test_city_prefix
    assert_match(/\w+/, @tester.city_prefix)
  end

  def test_state_abbr
    assert_match(/[A-Z]{2}/, @tester.state_abbr)
  end

  def test_state
    assert_match(/\w+/, @tester.state)
  end

  def test_country
    assert_match(/\w+/, @tester.country)
  end

  def test_country_by_code
    assert_match @tester.country_by_code(code: 'NL'), 'Netherlands'
  end

  def test_country_name_to_code
    assert_match @tester.country_name_to_code(name: 'united_states'), 'US'
  end

  def test_country_code
    assert_match(/[A-Z]{2}/, @tester.country_code)
  end

  def test_latitude
    assert_instance_of Float, @tester.latitude
  end

  def test_longitude
    assert_instance_of Float, @tester.longitude
  end

  def test_full_address
    assert_match(/\w*\.?\s?\d*\s?\d+\s\w+\s\w+,\s\w+\s?\w*,\s[A-Z]{2}\s\d+/, @tester.full_address)
  end

  def test_full_address_as_hash
    assert_instance_of Hash, @tester.full_address_as_hash
  end

  def test_full_address_as_hash_by_longitude
    assert_instance_of Float, @tester.full_address_as_hash(:longitude)[:longitude]
  end
end