File: test_internet.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 (134 lines) | stat: -rw-r--r-- 3,664 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# frozen_string_literal: true

require_relative 'helper'

class TestFakerInternet < Test::Unit::TestCase
  include DeterministicHelper

  assert_methods_are_deterministic(
    FFaker::Internet,
    :email, :free_email, :safe_email, :disposable_email,
    :user_name, :domain_name, :domain_word, :domain_suffix,
    :http_url, :ip_v4_address, :password, :slug, :mac
  )

  def setup
    @tester = FFaker::Internet
  end

  def test_email
    assert @tester.email.match(/.+@.+\.\w+/)
  end

  def test_email_frozen
    assert @tester.email.frozen? == false
  end

  def test_free_email
    assert @tester.free_email.match(/.+@(gmail|hotmail|yahoo)\.com/)
  end

  def test_disposable_email
    assert @tester.disposable_email.match(
      /.+@(mailinator\.com|suremail\.info|spamherelots\.com|binkmail\.com|safetymail\.info)/
    )
  end

  def test_safe_email
    assert @tester.safe_email.match(/.+@example.(com|net|org)/)
  end

  def test_user_name
    assert @tester.user_name.match(/[a-z]+((_|\.)[a-z]+)?/)
  end

  def test_user_name_with_arg
    assert @tester.user_name('bo peep').match(/(bo(_|\.)peep|peep(_|\.)bo)/)
  end

  def test_domain_name
    assert @tester.domain_name.match(/\w+\.\w+/)
  end

  def test_domain_word
    assert @tester.domain_word.match(/^\w+$/)
  end

  def test_domain_suffix
    assert @tester.domain_suffix.match(/^\w+(\.\w+)?/)
  end

  def test_uri
    assert @tester.uri('ftp').match(%r{^ftp://.+})
    assert @tester.uri('http').match(%r{^http://.+})
    assert @tester.uri('https').match(%r{^https://.+})

    assert_deterministic { @tester.uri('ftp') }
    assert_deterministic { @tester.uri('http') }
    assert_deterministic { @tester.uri('https') }
  end

  def test_http_url
    assert @tester.http_url.match(%r{^http://.+})
  end

  def test_ip_v4_address
    assert_match(/\A(?:\d{1,3}\.){3}\d{1,3}\z/, @tester.ip_v4_address)
  end

  def test_slug
    assert_match(/\A[a-z]+[_.-][a-z]+\z/, @tester.slug)
  end

  def test_slug_with_input_words
    assert_not_match(/&/, @tester.slug('Input Words&&Symbols'))
    assert_deterministic { @tester.slug('Input Words&&Symbols') }
  end

  def test_slug_with_specified_glue
    assert_match(/\A[a-z]+-[a-z]+\z/, @tester.slug(nil, '-'))
    assert_deterministic { @tester.slug(nil, '-') }
  end

  def test_password
    assert_match(/\A\w+\z/, @tester.password)
  end

  def test_password_min_length
    assert_greater_than @tester.password(3).length, 2
    assert_greater_than @tester.password(6).length, 5
    assert_greater_than @tester.password(15).length, 14
  end

  def test_password_max_length
    assert_less_than @tester.password(3, 10).length, 11
    assert_less_than @tester.password(7, 15).length, 16
    assert_less_than @tester.password(1, 3).length, 4
  end

  def test_password_fixed_length
    assert @tester.password(20, 20).length == 20
  end

  def test_password_strange_argument
    assert_greater_than @tester.password(10, 2).length, 9
    assert_greater_than @tester.password(3, 1).length, 2
    assert_greater_than @tester.password(8, 5).length, 7
  end

  def test_mac
    assert_match(/\A([a-z0-9]{2}:){5}[a-z0-9]{2}\z/, @tester.mac)
    assert @tester.mac.length == 17
  end

  def test_mac_delimiter_argument
    assert_match(/\A([a-z0-9]{2}-){5}[a-z0-9]{2}\z/, @tester.mac('-'))
    assert_match(/\A([a-z0-9]{2}\.){5}[a-z0-9]{2}\z/, @tester.mac('.'))
    assert_match(/\A([a-z0-9]{2}){6}\z/, @tester.mac(nil))
    assert_match(/\A([a-z0-9]{2}){6}\z/, @tester.mac(''))
    assert @tester.mac('-').length == 17
    assert @tester.mac('.').length == 17
    assert @tester.mac(nil).length == 12
    assert @tester.mac('').length == 12
  end
end