faker 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +5 -0
  3. data/README.md +80 -6
  4. data/lib/faker.rb +8 -1
  5. data/lib/faker/address.rb +0 -1
  6. data/lib/faker/avatar.rb +3 -2
  7. data/lib/faker/book.rb +5 -1
  8. data/lib/faker/code.rb +18 -0
  9. data/lib/faker/commerce.rb +3 -3
  10. data/lib/faker/company.rb +9 -1
  11. data/lib/faker/hipster.rb +59 -0
  12. data/lib/faker/id_number.rb +36 -0
  13. data/lib/faker/internet.rb +68 -27
  14. data/lib/faker/number.rb +24 -2
  15. data/lib/faker/placeholdit.rb +20 -0
  16. data/lib/faker/shakespeare.rb +83 -0
  17. data/lib/faker/time.rb +10 -1
  18. data/lib/faker/version.rb +1 -1
  19. data/lib/locales/de.yml +6 -0
  20. data/lib/locales/en-AU.yml +3 -1
  21. data/lib/locales/en-NEP.yml +11 -1
  22. data/lib/locales/en-NZ.yml +25 -0
  23. data/lib/locales/en-SG.yml +31 -0
  24. data/lib/locales/en-US.yml +16 -1
  25. data/lib/locales/en-au-ocker.yml +5 -3
  26. data/lib/locales/en.yml +11 -1
  27. data/lib/locales/es.yml +10 -0
  28. data/lib/locales/fr.yml +6 -1
  29. data/lib/locales/he.yml +25 -0
  30. data/lib/locales/it.yml +6 -6
  31. data/lib/locales/ja.yml +22 -4
  32. data/lib/locales/nb-NO.yml +4 -1
  33. data/lib/locales/pl.yml +1 -1
  34. data/lib/locales/pt-BR.yml +2 -2
  35. data/lib/locales/sk.yml +2 -2
  36. data/lib/locales/zh-CN.yml +2 -0
  37. data/test/test_avatar.rb +9 -5
  38. data/test/test_en_au_locale.rb +24 -0
  39. data/test/test_en_au_ocker_locale.rb +7 -5
  40. data/test/test_en_locale.rb +10 -0
  41. data/test/test_en_nz_locale.rb +33 -0
  42. data/test/test_en_us_locale.rb +10 -0
  43. data/test/test_faker_book.rb +5 -1
  44. data/test/test_faker_code.rb +4 -0
  45. data/test/test_faker_commerce.rb +12 -4
  46. data/test/test_faker_company.rb +5 -1
  47. data/test/test_faker_date.rb +4 -3
  48. data/test/test_faker_hipster.rb +78 -0
  49. data/test/test_faker_internet.rb +36 -3
  50. data/test/test_faker_lorem.rb +3 -3
  51. data/test/test_faker_number.rb +30 -0
  52. data/test/test_faker_shakespeare.rb +53 -0
  53. data/test/test_faker_time.rb +24 -5
  54. data/test/test_placeholdit.rb +92 -0
  55. metadata +19 -2
@@ -79,6 +79,22 @@ class TestFakerInternet < Test::Unit::TestCase
79
79
  end
80
80
  end
81
81
 
82
+ def test_password_with_mixed_case
83
+ assert @tester.password.match(/[A-Z]+/)
84
+ end
85
+
86
+ def test_password_without_mixed_case
87
+ assert @tester.password(8, 12, false).match(/[^A-Z]+/)
88
+ end
89
+
90
+ def test_password_with_special_chars
91
+ assert @tester.password(8, 12, true, true).match(/[!@#\$%\^&\*]+/)
92
+ end
93
+
94
+ def test_password_without_special_chars
95
+ assert @tester.password(8, 12, true).match(/[^!@#\$%\^&\*]+/)
96
+ end
97
+
82
98
  def test_domain_name
83
99
  assert @tester.domain_name.match(/\w+\.\w+/)
84
100
  end
@@ -94,16 +110,33 @@ class TestFakerInternet < Test::Unit::TestCase
94
110
  def test_ip_v4_address
95
111
  assert_equal 3, @tester.ip_v4_address.count('.')
96
112
 
97
- 1000.times do
113
+ 100.times do
98
114
  assert @tester.ip_v4_address.split('.').map{|octet| octet.to_i}.max <= 255
99
115
  end
100
116
  end
101
117
 
118
+ def test_public_ip_v4_address
119
+ ten_dot = /^10\./
120
+ one_two_seven = /^127\./
121
+ one_six_nine = /^169\.254/
122
+ one_nine_two = /^192\.168\./
123
+ one_seven_two = /^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\./
124
+
125
+ 1000.times do
126
+ address = @tester.public_ip_v4_address
127
+ assert_not_match ten_dot, address
128
+ assert_not_match one_two_seven, address
129
+ assert_not_match one_six_nine, address
130
+ assert_not_match one_nine_two, address
131
+ assert_not_match one_seven_two, address
132
+ end
133
+ end
134
+
102
135
  def test_mac_address
103
136
  assert_equal 5, @tester.mac_address.count(':')
104
137
  assert_equal 5, @tester.mac_address("").count(':')
105
138
 
106
- 1000.times do
139
+ 100.times do
107
140
  assert @tester.mac_address.split(':').map{|d| d.to_i(16)}.max <= 255
108
141
  end
109
142
 
@@ -114,7 +147,7 @@ class TestFakerInternet < Test::Unit::TestCase
114
147
  def test_ip_v6_address
115
148
  assert_equal 7, @tester.ip_v6_address.count(':')
116
149
 
117
- 1000.times do
150
+ 100.times do
118
151
  assert @tester.ip_v6_address.split('.').map{|h| "0x#{h}".hex}.max <= 65535
119
152
  end
120
153
  end
@@ -12,7 +12,7 @@ class TestFakerLorem < Test::Unit::TestCase
12
12
  def test_character
13
13
  assert @tester.character.length == 1
14
14
  end
15
-
15
+
16
16
  def test_character_type
17
17
  assert @tester.character.class == String
18
18
  end
@@ -22,7 +22,7 @@ class TestFakerLorem < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_characters_with_args
25
- 1000.times { assert @tester.characters(500).length == 500 }
25
+ 100.times { assert @tester.characters(500).length == 500 }
26
26
  end
27
27
 
28
28
  # Words delivered by a standard request should be on the standard wordlist.
@@ -41,7 +41,7 @@ class TestFakerLorem < Test::Unit::TestCase
41
41
  def test_word
42
42
  @tester = Faker::Lorem
43
43
  @standard_wordlist = I18n.translate('faker.lorem.words')
44
- 1000.times { assert @standard_wordlist.include?(@tester.word) }
44
+ 100.times { assert @standard_wordlist.include?(@tester.word) }
45
45
  end
46
46
 
47
47
  def test_exact_count_param
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
+ require 'minitest/mock'
2
3
 
3
4
  class TestFakerNumber < Test::Unit::TestCase
4
5
  def setup
@@ -28,6 +29,21 @@ class TestFakerNumber < Test::Unit::TestCase
28
29
  assert (1..1000).collect {|i| @tester.digit == "9"}.include?(true)
29
30
  end
30
31
 
32
+ def test_even_distribution
33
+ assert stats = {}
34
+ assert times = 10000
35
+
36
+ times.times do
37
+ assert num = @tester.digit
38
+ stats[num] ||= 0
39
+ assert stats[num] += 1
40
+ end
41
+
42
+ stats.each do |k, v|
43
+ assert_in_delta 10.0, 100.0 * v / times, 2.0
44
+ end
45
+ end
46
+
31
47
  def test_between
32
48
  100.times do
33
49
  random_number = @tester.between(-50, 50)
@@ -74,4 +90,18 @@ class TestFakerNumber < Test::Unit::TestCase
74
90
  assert @tester.hexadecimal(4).match(/[0-9a-f]{4}/)
75
91
  assert @tester.hexadecimal(7).match(/[0-9a-f]{7}/)
76
92
  end
93
+
94
+ def test_insignificant_zero
95
+ Faker::Number.stub :digit, 0 do
96
+ assert_equal '0', @tester.number(1)
97
+ 100.times do
98
+ assert_match /^[1-9]0/, @tester.number(2)
99
+ end
100
+
101
+ assert_equal '0.0', @tester.decimal(1,1)
102
+ 100.times do
103
+ assert_match /^0\.0[1-9]/, @tester.decimal(1,2)
104
+ end
105
+ end
106
+ end
77
107
  end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
+
3
+ class TestFakerShakespeare < Test::Unit::TestCase
4
+ def setup
5
+ @romeo_and_juliet = Faker::Shakespeare.romeo_and_juliet
6
+ @king_richard_iii = Faker::Shakespeare.king_richard_iii
7
+ @as_you_like_it = Faker::Shakespeare.as_you_like_it
8
+ @hamlet = Faker::Shakespeare.hamlet
9
+ end
10
+
11
+ def test_quotes
12
+ assert @romeo_and_juliet.size == 11
13
+ @romeo_and_juliet.each do |quotes|
14
+ assert !quotes.nil?
15
+ assert quotes != ""
16
+ end
17
+
18
+ assert @king_richard_iii.size == 8
19
+ @king_richard_iii.each do |quotes|
20
+ assert !quotes.nil?
21
+ assert quotes != ""
22
+ end
23
+
24
+ assert @as_you_like_it.size == 8
25
+ @as_you_like_it.each do |quotes|
26
+ assert !quotes.nil?
27
+ assert quotes != ""
28
+ end
29
+
30
+ assert @hamlet.size == 18
31
+ @hamlet.each do |quotes|
32
+ assert !quotes.nil?
33
+ assert quotes != ""
34
+ end
35
+ end
36
+
37
+ def test_as_you_like_it_quote
38
+ assert Faker::Shakespeare.as_you_like_it_quote.match(/\w+/)
39
+ end
40
+
41
+ def test_king_richard_iii_quote
42
+ assert Faker::Shakespeare.king_richard_iii_quote.match(/\w+/)
43
+ end
44
+
45
+ def test_romeo_and_juliet_quote
46
+ assert Faker::Shakespeare.romeo_and_juliet_quote.match(/\w+/)
47
+ end
48
+
49
+ def test_hamlet_quote
50
+ assert Faker::Shakespeare.hamlet_quote.match(/\w+/)
51
+ end
52
+
53
+ end
@@ -1,14 +1,16 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
2
 
3
3
  class TestFakerTime < Test::Unit::TestCase
4
+ TEN_HOURS = 36000
5
+
4
6
  def setup
5
7
  @tester = Faker::Time
6
8
  @time_ranges = Faker::Time::TIME_RANGES
7
9
  end
8
10
 
9
- def test_between
10
- from = Time.local(2012, 01, 01, 0, 0, 0)
11
- to = Time.local(2013, 01, 01, 23, 59, 59)
11
+ def test_between_with_time_parameters
12
+ from = Time.local(2014, 12, 28, 06, 0, 0)
13
+ to = Time.local(2014, 12, 30, 13, 0, 0)
12
14
 
13
15
  100.times do
14
16
  random_time = @tester.between(from, to)
@@ -17,6 +19,17 @@ class TestFakerTime < Test::Unit::TestCase
17
19
  end
18
20
  end
19
21
 
22
+ def test_between_with_date_parameters
23
+ from = Date.parse("2014-12-28")
24
+ to = Date.parse("2014-12-30")
25
+
26
+ 100.times do
27
+ random_time = @tester.between(from, to)
28
+ assert random_time.to_date >= from, "Expected >= \"#{from}\", but got #{random_time}"
29
+ assert random_time.to_date <= to , "Expected <= \"#{to}\", but got #{random_time}"
30
+ end
31
+ end
32
+
20
33
  def test_forward
21
34
  today = Date.today
22
35
 
@@ -46,10 +59,16 @@ class TestFakerTime < Test::Unit::TestCase
46
59
 
47
60
  def test_return_type
48
61
  random_backward = @tester.backward(5)
49
- random_between = @tester.between(Date.today, Date.today + 5)
62
+ random_between_dates = @tester.between(Date.today, Date.today + 5)
63
+ random_between_times = @tester.between(Time.now, Time.now + TEN_HOURS)
50
64
  random_forward = @tester.forward(5)
51
65
 
52
- [random_backward, random_between, random_forward].each do |result|
66
+ [
67
+ random_backward,
68
+ random_between_dates,
69
+ random_between_times,
70
+ random_forward
71
+ ].each do |result|
53
72
  assert result.is_a?(Time), "Expected a Time object, but got #{result.class}"
54
73
  end
55
74
  end
@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
+
3
+ class TestPlaceholdit < Test::Unit::TestCase
4
+ def setup
5
+ @tester = Faker::Placeholdit
6
+ end
7
+
8
+ def test_placeholdit
9
+ assert @tester.image.match(/https:\/\/placehold\.it\/(.+)(png?)/)[1] != nil
10
+ end
11
+
12
+ def test_avatar_with_custom_size
13
+ assert @tester.image('3x3').match(/https:\/\/placehold\.it\/+(\d+x\d+)/)[1] == '3x3'
14
+ end
15
+
16
+ def test_avatar_with_incorrect_size
17
+ assert_raise ArgumentError do
18
+ @tester.image('300x300s')
19
+ end
20
+ end
21
+
22
+ def test_avatar_with_supported_format
23
+ assert @tester.image('300x300', 'jpg').match(/https:\/\/placehold\.it\/(.+)(jpg?)/)
24
+ end
25
+
26
+ def test_avatar_with_incorrect_format
27
+ assert_raise ArgumentError do
28
+ @tester.image('300x300', 'wrong_format')
29
+ end
30
+ end
31
+
32
+ def test_avatar_background_with_correct_six_char_hex
33
+ assert @tester.image('300x300', 'jpg', 'ffffff').match(/https:\/\/placehold\.it\/(.+)(jpg?)\/ffffff/)
34
+ end
35
+
36
+ def test_avatar_background_with_correct_three_char_hex
37
+ assert @tester.image('300x300', 'jpg', 'fff').match(/https:\/\/placehold\.it\/(.+)(jpg?)\/fff/)
38
+ end
39
+
40
+ def test_avatar_background_with_wrong_six_char_hex
41
+ assert_raise ArgumentError do
42
+ @tester.image('300x300', 'jpg', 'fffffz')
43
+ end
44
+ end
45
+
46
+ def test_avatar_background_with_wrong_hex
47
+ assert_raise ArgumentError do
48
+ @tester.image('300x300', 'jpg', 'ffff4')
49
+ end
50
+ end
51
+
52
+ def test_avatar_background_with_wrong_three_char_hex
53
+ assert_raise ArgumentError do
54
+ @tester.image('300x300', 'jpg', 'ffz')
55
+ end
56
+ end
57
+
58
+ def test_avatar_font_color_with_correct_six_char_hex
59
+ assert @tester.image('300x300', 'jpg', 'ffffff', '000000').match(/https:\/\/placehold\.it\/(.+)(jpg?)\/ffffff\/000000/)
60
+ end
61
+
62
+ def test_avatar_font_color_with_correct_three_char_hex
63
+ assert @tester.image('300x300', 'jpg', 'fff', '000').match(/https:\/\/placehold\.it\/(.+)(jpg?)\/fff/)
64
+ end
65
+
66
+ def test_avatar_font_color_with_wrong_six_char_hex
67
+ assert_raise ArgumentError do
68
+ @tester.image('300x300', 'jpg', 'ffffff', '900F0z')
69
+ end
70
+ end
71
+
72
+ def test_avatar_font_color_with_wrong_hex
73
+ assert_raise ArgumentError do
74
+ @tester.image('300x300', 'jpg', 'ffffff', 'x9')
75
+ end
76
+ end
77
+
78
+ def test_avatar_font_color_with_wrong_three_char_hex
79
+ assert_raise ArgumentError do
80
+ @tester.image('300x300', 'jpg', 'ffffff', '00p')
81
+ end
82
+ end
83
+
84
+ def test_text_not_present
85
+ assert @tester.image('300x300', 'jpg', 'fff', '000').match(/https:\/\/placehold\.it\/[^\\?]+$/)
86
+ end
87
+
88
+ def test_text_present
89
+ assert @tester.image('300x300', 'jpg', 'fff', '000', 'hello').match(/https:\/\/placehold\.it\/(.+)\?text=hello/)
90
+ end
91
+
92
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Curtis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -51,11 +51,15 @@ files:
51
51
  - lib/faker/date.rb
52
52
  - lib/faker/finance.rb
53
53
  - lib/faker/hacker.rb
54
+ - lib/faker/hipster.rb
55
+ - lib/faker/id_number.rb
54
56
  - lib/faker/internet.rb
55
57
  - lib/faker/lorem.rb
56
58
  - lib/faker/name.rb
57
59
  - lib/faker/number.rb
58
60
  - lib/faker/phone_number.rb
61
+ - lib/faker/placeholdit.rb
62
+ - lib/faker/shakespeare.rb
59
63
  - lib/faker/slack_emoji.rb
60
64
  - lib/faker/team.rb
61
65
  - lib/faker/time.rb
@@ -71,6 +75,8 @@ files:
71
75
  - lib/locales/en-GB.yml
72
76
  - lib/locales/en-IND.yml
73
77
  - lib/locales/en-NEP.yml
78
+ - lib/locales/en-NZ.yml
79
+ - lib/locales/en-SG.yml
74
80
  - lib/locales/en-UG.yml
75
81
  - lib/locales/en-US.yml
76
82
  - lib/locales/en-au-ocker.yml
@@ -78,6 +84,7 @@ files:
78
84
  - lib/locales/es.yml
79
85
  - lib/locales/fa.yml
80
86
  - lib/locales/fr.yml
87
+ - lib/locales/he.yml
81
88
  - lib/locales/it.yml
82
89
  - lib/locales/ja.yml
83
90
  - lib/locales/ko.yml
@@ -94,9 +101,11 @@ files:
94
101
  - lib/locales/zh-TW.yml
95
102
  - test/test_array_sample_method_compat.rb
96
103
  - test/test_avatar.rb
104
+ - test/test_en_au_locale.rb
97
105
  - test/test_en_au_ocker_locale.rb
98
106
  - test/test_en_ca_locale.rb
99
107
  - test/test_en_locale.rb
108
+ - test/test_en_nz_locale.rb
100
109
  - test/test_en_ug_locale.rb
101
110
  - test/test_en_us_locale.rb
102
111
  - test/test_es_locale.rb
@@ -112,10 +121,12 @@ files:
112
121
  - test/test_faker_company.rb
113
122
  - test/test_faker_date.rb
114
123
  - test/test_faker_hacker_talk.rb
124
+ - test/test_faker_hipster.rb
115
125
  - test/test_faker_internet.rb
116
126
  - test/test_faker_lorem.rb
117
127
  - test/test_faker_name.rb
118
128
  - test/test_faker_number.rb
129
+ - test/test_faker_shakespeare.rb
119
130
  - test/test_faker_slack_emoji.rb
120
131
  - test/test_faker_street.rb
121
132
  - test/test_faker_team.rb
@@ -125,6 +136,7 @@ files:
125
136
  - test/test_helper.rb
126
137
  - test/test_locale.rb
127
138
  - test/test_pl_locale.rb
139
+ - test/test_placeholdit.rb
128
140
  - test/test_uk_locale.rb
129
141
  homepage: https://github.com/stympy/faker
130
142
  licenses:
@@ -153,9 +165,11 @@ summary: Easily generate fake data
153
165
  test_files:
154
166
  - test/test_array_sample_method_compat.rb
155
167
  - test/test_avatar.rb
168
+ - test/test_en_au_locale.rb
156
169
  - test/test_en_au_ocker_locale.rb
157
170
  - test/test_en_ca_locale.rb
158
171
  - test/test_en_locale.rb
172
+ - test/test_en_nz_locale.rb
159
173
  - test/test_en_ug_locale.rb
160
174
  - test/test_en_us_locale.rb
161
175
  - test/test_es_locale.rb
@@ -171,10 +185,12 @@ test_files:
171
185
  - test/test_faker_company.rb
172
186
  - test/test_faker_date.rb
173
187
  - test/test_faker_hacker_talk.rb
188
+ - test/test_faker_hipster.rb
174
189
  - test/test_faker_internet.rb
175
190
  - test/test_faker_lorem.rb
176
191
  - test/test_faker_name.rb
177
192
  - test/test_faker_number.rb
193
+ - test/test_faker_shakespeare.rb
178
194
  - test/test_faker_slack_emoji.rb
179
195
  - test/test_faker_street.rb
180
196
  - test/test_faker_team.rb
@@ -184,4 +200,5 @@ test_files:
184
200
  - test/test_helper.rb
185
201
  - test/test_locale.rb
186
202
  - test/test_pl_locale.rb
203
+ - test/test_placeholdit.rb
187
204
  - test/test_uk_locale.rb