faker 1.6.3 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +13 -0
  3. data/README.md +185 -23
  4. data/lib/faker.rb +20 -0
  5. data/lib/faker/app.rb +1 -1
  6. data/lib/faker/beer.rb +1 -1
  7. data/lib/faker/chuck_norris.rb +16 -0
  8. data/lib/faker/code.rb +59 -0
  9. data/lib/faker/company.rb +19 -0
  10. data/lib/faker/crypto.rb +19 -0
  11. data/lib/faker/date.rb +30 -2
  12. data/lib/faker/educator.rb +23 -0
  13. data/lib/faker/file.rb +23 -0
  14. data/lib/faker/internet.rb +24 -15
  15. data/lib/faker/lorem.rb +21 -7
  16. data/lib/faker/music.rb +21 -0
  17. data/lib/faker/name.rb +7 -0
  18. data/lib/faker/placeholdit.rb +3 -3
  19. data/lib/faker/space.rb +54 -0
  20. data/lib/faker/time.rb +7 -18
  21. data/lib/faker/vehicle.rb +37 -0
  22. data/lib/faker/version.rb +1 -1
  23. data/lib/faker/yoda.rb +10 -0
  24. data/lib/locales/de.yml +26 -8
  25. data/lib/locales/en-GB.yml +1 -1
  26. data/lib/locales/en-PAK.yml +17 -0
  27. data/lib/locales/en.yml +195 -4
  28. data/lib/locales/es-MX.yml +82 -0
  29. data/lib/locales/es.yml +4 -0
  30. data/lib/locales/fr.yml +7 -4
  31. data/lib/locales/pt-BR.yml +51 -23
  32. metadata +13 -103
  33. data/test/test_array_sample_method_compat.rb +0 -56
  34. data/test/test_avatar.rb +0 -43
  35. data/test/test_ca_cat_locale.rb +0 -35
  36. data/test/test_ca_locale.rb +0 -22
  37. data/test/test_da_dk_locale.rb +0 -32
  38. data/test/test_en_au_locale.rb +0 -24
  39. data/test/test_en_au_ocker_locale.rb +0 -25
  40. data/test/test_en_ca_locale.rb +0 -18
  41. data/test/test_en_locale.rb +0 -35
  42. data/test/test_en_nz_locale.rb +0 -33
  43. data/test/test_en_ug_locale.rb +0 -23
  44. data/test/test_en_us_locale.rb +0 -89
  45. data/test/test_es_locale.rb +0 -34
  46. data/test/test_faker.rb +0 -29
  47. data/test/test_faker_app.rb +0 -12
  48. data/test/test_faker_beer.rb +0 -41
  49. data/test/test_faker_bitcoin.rb +0 -14
  50. data/test/test_faker_book.rb +0 -24
  51. data/test/test_faker_boolean.rb +0 -23
  52. data/test/test_faker_business.rb +0 -34
  53. data/test/test_faker_cat.rb +0 -20
  54. data/test/test_faker_city.rb +0 -52
  55. data/test/test_faker_code.rb +0 -35
  56. data/test/test_faker_color.rb +0 -50
  57. data/test/test_faker_commerce.rb +0 -84
  58. data/test/test_faker_company.rb +0 -34
  59. data/test/test_faker_date.rb +0 -89
  60. data/test/test_faker_hacker_talk.rb +0 -37
  61. data/test/test_faker_hipster.rb +0 -78
  62. data/test/test_faker_internet.rb +0 -190
  63. data/test/test_faker_lorem.rb +0 -87
  64. data/test/test_faker_name.rb +0 -20
  65. data/test/test_faker_number.rb +0 -107
  66. data/test/test_faker_shakespeare.rb +0 -53
  67. data/test/test_faker_slack_emoji.rb +0 -45
  68. data/test/test_faker_star_wars.rb +0 -74
  69. data/test/test_faker_street.rb +0 -58
  70. data/test/test_faker_superhero.rb +0 -16
  71. data/test/test_faker_team.rb +0 -25
  72. data/test/test_faker_time.rb +0 -93
  73. data/test/test_faker_university.rb +0 -20
  74. data/test/test_fi_locale.rb +0 -33
  75. data/test/test_flexible.rb +0 -62
  76. data/test/test_helper.rb +0 -12
  77. data/test/test_locale.rb +0 -47
  78. data/test/test_pl_locale.rb +0 -24
  79. data/test/test_placeholdit.rb +0 -92
  80. data/test/test_pt_locale.rb +0 -27
  81. data/test/test_sv_locale.rb +0 -28
  82. data/test/test_uk_locale.rb +0 -44
@@ -1,20 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
-
3
- class TestFakerCat < Test::Unit::TestCase
4
- def setup
5
- @tester = Faker::Cat
6
- end
7
-
8
- def test_name
9
- assert @tester.name.match(/\w+\.?/)
10
- end
11
-
12
- def test_breed
13
- assert @tester.breed.match(/\w+\.?/)
14
- end
15
-
16
- def test_registry
17
- assert @tester.registry.match(/\w+\.?/)
18
- end
19
-
20
- end
@@ -1,52 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestFakerCity < Test::Unit::TestCase
4
- def setup
5
- @old_locales = I18n.config.available_locales
6
- xx = {
7
- :faker => {
8
- :name => {:first_name => ['alice'], :last_name => ['smith']},
9
- :address => {:city_prefix => ['west'], :city_suffix => ['burg']}
10
- }
11
- }
12
- I18n.backend.store_translations(:xx, xx)
13
- I18n.config.available_locales += [ :xx ]
14
-
15
- xy = {
16
- :faker => {
17
- :address => {
18
- :city_prefix => ['big'],
19
- :city_root => ['rock'],
20
- :city_root_suffix => ['ing'],
21
- :city_suffix => ['town'],
22
- :city => ['#{city_prefix} #{city_root}#{city_root_suffix} #{city_suffix}']
23
- }
24
- }
25
- }
26
- I18n.backend.store_translations(:xy, xy)
27
- I18n.config.available_locales += [ :xy ]
28
- end
29
-
30
- def teardown
31
- I18n.config.available_locales = @old_locales
32
- end
33
-
34
- def test_default_city_formats
35
- I18n.with_locale(:xx) do
36
- 100.times do
37
- cities = ["west alice", "west smith", "west aliceburg", "west smithburg", "aliceburg", "smithburg"]
38
- city = Faker::Address.city
39
- assert cities.include?(city), "Expected <#{cities.join(' / ')}>, but got #{city}"
40
- end
41
- end
42
- end
43
-
44
- def test_city_formats_are_flexible
45
- I18n.with_locale(:xy) do
46
- cities = ['big rocking town']
47
- city = Faker::Address.city
48
- assert cities.include?(city), "Expected <#{cities.join(' / ')}>, but got #{city}"
49
- end
50
- end
51
-
52
- end
@@ -1,35 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestFakerCode < Test::Unit::TestCase
4
- def setup
5
- @tester = Faker::Code
6
- end
7
-
8
- def test_npi_regexp
9
- assert @tester.npi.match(/[0-9]{10}/)
10
- end
11
-
12
- def test_default_isbn_regexp
13
- assert @tester.isbn.match(/^\d{9}-[\d|X]$/)
14
- end
15
-
16
- def test_default_isbn13_regexp
17
- assert @tester.isbn(13).match(/^\d{12}-\d$/)
18
- end
19
-
20
- def test_default_ean_regexp
21
- assert @tester.ean.match(/^\d{13}$/)
22
- end
23
-
24
- def test_default_ean8_regexp
25
- assert @tester.ean(8).match(/^\d{8}$/)
26
- end
27
-
28
- def test_rut
29
- assert @tester.rut.match(/^\d{1,8}-(\d|k)$/)
30
- end
31
-
32
- def test_nric
33
- assert @tester.nric.match(/^(S|T)\d{7}[A-JZ]$/)
34
- end
35
- end
@@ -1,50 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
-
3
- class TestFakerColor < Test::Unit::TestCase
4
- def setup
5
- @tester = Faker::Color
6
- end
7
-
8
- def test_color_name
9
- assert @tester.color_name.match(/[a-z]+\.?/)
10
- end
11
-
12
- def test_hex_color
13
- assert @tester.hex_color.match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
14
- end
15
-
16
- def test_single_rgb_color
17
- assert @tester.single_rgb_color.between?(0, 255)
18
- end
19
-
20
- def test_rgb_color
21
- @result = @tester.rgb_color
22
- assert @result.length == 3
23
-
24
- @result.each do |color|
25
- assert color.between?(0, 255)
26
- end
27
- end
28
-
29
- def test_single_hsl_color
30
- assert @tester.single_hsl_color.between?(0.0, 360.0)
31
- end
32
-
33
- def test_hsl_color
34
- @result = @tester.hsl_color
35
- assert @result.length == 3
36
-
37
- @result.each do |color|
38
- assert color.between?(0.0, 360.0)
39
- end
40
- end
41
-
42
- def test_hsla_color
43
- @result = @tester.hsla_color
44
- assert @result.length == 4
45
-
46
- @result.each do |color|
47
- assert color.between?(0.0, 360.0) || color.between?(0.0, 1.0)
48
- end
49
- end
50
- end
@@ -1,84 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
-
3
- class TestFakerCommerce < Test::Unit::TestCase
4
-
5
- def setup
6
- @tester = Faker::Commerce
7
- end
8
-
9
- def test_color
10
- assert @tester.color.match(/[a-z]+\.?/)
11
- end
12
-
13
- def test_department
14
- assert @tester.department.match(/[A-Z][a-z]+\.?/)
15
- end
16
-
17
- def test_single_department_should_not_contain_separators
18
- assert_match(/\A[A-Za-z]+\z/, @tester.department(1))
19
- end
20
-
21
- def test_department_should_have_ampersand_as_default_separator
22
- assert_match ' & ', @tester.department(2, true)
23
- end
24
-
25
- def test_department_should_accept_localized_separator
26
- @old_locales = I18n.config.available_locales
27
- data = {
28
- :faker => {
29
- :separator => ' + ',
30
- :commerce => {
31
- :department => ['Books', 'Movies']
32
- }
33
- }
34
- }
35
-
36
- I18n.backend.store_translations(:xy, data)
37
- I18n.config.available_locales += [ :xy ]
38
- I18n.with_locale(:xy) do
39
- assert_match ' + ', @tester.department(2, true)
40
- end
41
- I18n.config.available_locales = @old_locales
42
- end
43
-
44
- def test_department_should_have_exact_number_of_categories_when_fixed_amount
45
- assert_match(/\A([A-Za-z]+, ){8}[A-Za-z]+ & [A-Za-z]+\z/, @tester.department(10, true))
46
- end
47
-
48
- def test_department_should_never_exceed_the_max_number_of_categories_when_random_amount
49
- 100.times do
50
- assert_match(/\A([A-Za-z]+(, | & )){0,5}[A-Za-z]+\z/, @tester.department(6))
51
- end
52
- end
53
-
54
- def test_department_should_have_no_duplicate_categories
55
- department = @tester.department(10, true)
56
-
57
- departments = department.split(/[,& ]+/)
58
- assert_equal departments, departments.uniq
59
- end
60
-
61
- def test_product_name
62
- assert @tester.product_name.match(/[A-Z][a-z]+\.?/)
63
- end
64
-
65
- def test_material
66
- assert @tester.material.match(/[A-Z][a-z]+\.?/)
67
- end
68
-
69
- def test_price
70
- assert_includes 0..100, @tester.price
71
- assert_instance_of Float, @tester.price(5..6)
72
- assert_includes 5..6, @tester.price(5..6)
73
- assert_includes 990...1000, @tester.price(990...1000)
74
- end
75
-
76
- def test_price_with_srand
77
- srand(12345)
78
- assert_equal 92.96, @tester.price
79
- end
80
-
81
- def test_price_is_float
82
- assert @tester.price.is_a? Float
83
- end
84
- end
@@ -1,34 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
-
3
- class TestFakerCompany < Test::Unit::TestCase
4
- def setup
5
- @tester = Faker::Company
6
- end
7
-
8
- def test_ein
9
- assert @tester.ein.match(/\d\d-\d\d\d\d\d\d\d/)
10
- end
11
-
12
- def test_duns_number
13
- assert @tester.duns_number.match(/\d\d-\d\d\d-\d\d\d\d/)
14
- end
15
-
16
- def test_logo
17
- assert @tester.logo.match(%r{https://pigment.github.io/fake-logos/logos/medium/color/\d+\.png})
18
- end
19
-
20
- def test_buzzword
21
- assert @tester.buzzword.match(/\w+\.?/)
22
- end
23
-
24
- def test_swedish_organisation_number
25
- org_no = @tester.swedish_organisation_number
26
- assert org_no.match(/\d{10}/)
27
- assert org_no[9] == @tester.send(:luhn_algorithm, org_no[0..8]).to_s
28
- end
29
-
30
- def test_profession
31
- assert @tester.profession.match(/[a-z ]+\.?/)
32
- end
33
-
34
- end
@@ -1,89 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
-
3
- class TestFakerDate < Test::Unit::TestCase
4
- def setup
5
- @tester = Faker::Date
6
- end
7
-
8
- def test_between
9
- from = Date.parse("2012-01-01")
10
- to = Date.parse("2013-01-01")
11
-
12
- 100.times do
13
- random_date = @tester.between(from, to)
14
- assert random_date >= from, "Expected >= \"#{from}\", but got #{random_date}"
15
- assert random_date <= to , "Expected <= \"#{to}\", but got #{random_date}"
16
- end
17
- end
18
-
19
- def test_between_except
20
- from = Date.parse("2012-01-01")
21
- to = Date.parse("2012-01-05")
22
- excepted = Date.parse("2012-01-03")
23
-
24
- 100.times do
25
- random_date = @tester.between_except(from, to, excepted)
26
- assert random_date != excepted, "Expected != \"#{excepted}\", but got #{random_date}"
27
- end
28
- end
29
-
30
- def test_forward
31
- today = Date.today
32
-
33
- 100.times do
34
- random_date = @tester.forward(5)
35
- assert random_date > today, "Expected > \"#{today}\", but got #{random_date}"
36
- end
37
- end
38
-
39
- def test_backward
40
- today = Date.today
41
-
42
- 100.times do
43
- random_date = @tester.backward(5)
44
- assert random_date < today, "Expected < \"#{today}\", but got #{random_date}"
45
- end
46
- end
47
-
48
- def test_return_type
49
- random_forward = @tester.forward(5)
50
- random_backward = @tester.backward(5)
51
- random_between = @tester.between(Date.today, Date.today + 5)
52
-
53
- [random_forward, random_backward, random_between].each do |result|
54
- assert result.is_a?(Date), "Expected a Date object, but got #{result.class}"
55
- end
56
- end
57
-
58
- def test_invalid_date
59
- assert_raise ArgumentError do
60
- @tester.between("9999-99-99", "9999-99-99")
61
- end
62
- end
63
-
64
- def test_birthday
65
- min = 40
66
- max = 90
67
- 100.times do
68
- t = Date.today
69
- date_min = Date.new(t.year - min, t.month, t.day)
70
- date_max = Date.new(t.year - max, t.month, t.day)
71
- birthday = @tester.birthday(min, max)
72
- assert birthday >= date_max, "Expect > \"#{date_max}\", but got #{birthday}"
73
- assert birthday <= date_min, "Expect > \"#{date_max}\", but got #{birthday}"
74
- end
75
- end
76
-
77
- def test_default_birthday
78
- min = 10
79
- max = 65
80
- 100.times do
81
- t = Date.today
82
- date_min = Date.new(t.year - min, t.month, t.day)
83
- date_max = Date.new(t.year - max, t.month, t.day)
84
- birthday = @tester.birthday
85
- assert birthday >= date_max, "Expect > \"#{date_max}\", but got #{birthday}"
86
- assert birthday < date_min, "Expect > \"#{date_max}\", but got #{birthday}"
87
- end
88
- end
89
- end
@@ -1,37 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
-
3
- class TestFakerHacker < Test::Unit::TestCase
4
- def setup
5
- @hacker = Faker::Hacker
6
- @phrases = @hacker.phrases
7
- end
8
-
9
- def test_phrases
10
- assert @phrases.size == 8
11
- @phrases.each do |phrase|
12
- assert !phrase.nil?
13
- assert phrase != ""
14
- end
15
- end
16
-
17
- def test_noun
18
- assert @hacker.noun.match(/\w+/)
19
- end
20
-
21
- def test_abbreviation
22
- assert @hacker.abbreviation.match(/\w+/)
23
- end
24
-
25
- def test_adjective
26
- assert @hacker.adjective.match(/\w+/)
27
- end
28
-
29
- def test_verb
30
- assert @hacker.verb.match(/\w+/)
31
- end
32
-
33
- def test_ingverb
34
- assert @hacker.ingverb.match(/\w+/)
35
- end
36
-
37
- end
@@ -1,78 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestFakerHipster < Test::Unit::TestCase
4
-
5
- def setup
6
- @tester = Faker::Hipster
7
- @standard_wordlist = I18n.translate('faker.hipster.words')
8
- @complete_wordlist =
9
- @standard_wordlist + I18n.translate('faker.lorem.words')
10
- end
11
-
12
- # Words delivered by a standard request should be on the standard wordlist.
13
- def test_words
14
- @words = @tester.words(1000)
15
- @words.each { |w| assert @standard_wordlist.include?(w) }
16
- end
17
-
18
- # Words should not return any word with spaces
19
- def test_words_without_spaces
20
- @words = @tester.words(1000)
21
- @words.each { |w| assert !w.match(/\s/) }
22
- end
23
-
24
- # Words requested from the supplemental list should all be in that list.
25
- def test_supplemental_words
26
- @words = @tester.words(10000, true)
27
- @words.each { |w| assert @complete_wordlist.include?(w) }
28
- end
29
-
30
- # Faker::Hipster.word generates random word from standart wordlist
31
- def test_word
32
- @tester = Faker::Hipster
33
- @standard_wordlist = I18n.translate('faker.hipster.words')
34
- 1000.times { assert @standard_wordlist.include?(@tester.word) }
35
- end
36
-
37
- # Word should not return any word with spaces
38
- def test_word_without_spaces
39
- @tester = Faker::Hipster
40
- 1000.times { assert !@tester.word.match(/\s/) }
41
- end
42
-
43
- def test_exact_count_param
44
- assert(@tester.words(2).length == 2)
45
- assert(@tester.sentences(2).length == 2)
46
- assert(@tester.paragraphs(2).length == 2)
47
- end
48
-
49
- def test_range_count_param
50
- ws = @tester.words(2..5)
51
- ss = @tester.sentences(2..5)
52
- ps = @tester.paragraphs(2..5)
53
-
54
- assert(2 <= ws.length && ws.length <= 5)
55
- assert(2 <= ss.length && ss.length <= 5)
56
- assert(2 <= ps.length && ps.length <= 5)
57
- end
58
-
59
- def test_array_count_param
60
- ws = @tester.words([1,4])
61
- ss = @tester.sentences([1,4])
62
- ps = @tester.paragraphs([1,4])
63
-
64
- assert(ws.length == 1 || ws.length == 4)
65
- assert(ss.length == 1 || ss.length == 4)
66
- assert(ps.length == 1 || ps.length == 4)
67
- end
68
-
69
- def test_words_with_large_count_params
70
- exact = @tester.words(500)
71
- range = @tester.words(250..500)
72
- array = @tester.words([250, 500])
73
-
74
- assert(exact.length == 500)
75
- assert(250 <= range.length && range.length <= 500)
76
- assert(array.length == 250 || array.length == 500)
77
- end
78
- end