factory-helper 1.7.5 → 1.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/factory-helper/version.rb +1 -1
- data/spec/config_spec.rb +18 -0
- data/spec/factory_helper/my_sql_spec.rb +123 -0
- data/spec/factory_helper/string_spec.rb +55 -0
- data/spec/rspec_locale_hooks_spec.rb +28 -0
- data/spec/spec_helper.rb +92 -0
- data/test/legacy/test_array_sample_method_compat.rb +56 -0
- data/test/legacy/test_avatar.rb +36 -0
- data/test/legacy/test_en_au_ocker_locale.rb +23 -0
- data/test/legacy/test_en_ca_locale.rb +18 -0
- data/test/legacy/test_en_locale.rb +25 -0
- data/test/legacy/test_en_us_locale.rb +79 -0
- data/test/legacy/test_es_locale.rb +34 -0
- data/test/legacy/test_faker.rb +29 -0
- data/test/legacy/test_faker_app.rb +12 -0
- data/test/legacy/test_faker_bitcoin.rb +14 -0
- data/test/legacy/test_faker_business.rb +33 -0
- data/test/legacy/test_faker_city.rb +46 -0
- data/test/legacy/test_faker_code.rb +27 -0
- data/test/legacy/test_faker_commerce.rb +74 -0
- data/test/legacy/test_faker_company.rb +19 -0
- data/test/legacy/test_faker_date.rb +77 -0
- data/test/legacy/test_faker_hacker_talk.rb +37 -0
- data/test/legacy/test_faker_internet.rb +146 -0
- data/test/legacy/test_faker_lorem.rb +87 -0
- data/test/legacy/test_faker_name.rb +20 -0
- data/test/legacy/test_faker_number.rb +77 -0
- data/test/legacy/test_faker_street.rb +53 -0
- data/test/legacy/test_faker_team.rb +13 -0
- data/test/legacy/test_faker_time.rb +74 -0
- data/test/legacy/test_flexible.rb +57 -0
- data/test/legacy/test_locale.rb +45 -0
- data/test/legacy/test_pl_locale.rb +27 -0
- data/test/test_avatar.rb +36 -0
- data/test/test_determinism.rb +57 -0
- data/test/test_en_au_ocker_locale.rb +23 -0
- data/test/test_en_ca_locale.rb +18 -0
- data/test/test_en_locale.rb +25 -0
- data/test/test_en_us_locale.rb +79 -0
- data/test/test_es_locale.rb +34 -0
- data/test/test_factory_helper.rb +28 -0
- data/test/test_factory_helper_app.rb +12 -0
- data/test/test_factory_helper_bitcoin.rb +14 -0
- data/test/test_factory_helper_business.rb +33 -0
- data/test/test_factory_helper_city.rb +46 -0
- data/test/test_factory_helper_code.rb +27 -0
- data/test/test_factory_helper_commerce.rb +70 -0
- data/test/test_factory_helper_company.rb +23 -0
- data/test/test_factory_helper_date.rb +78 -0
- data/test/test_factory_helper_hacker_talk.rb +37 -0
- data/test/test_factory_helper_internet.rb +155 -0
- data/test/test_factory_helper_lorem.rb +87 -0
- data/test/test_factory_helper_name.rb +54 -0
- data/test/test_factory_helper_number.rb +77 -0
- data/test/test_factory_helper_slack_emoji.rb +45 -0
- data/test/test_factory_helper_street.rb +53 -0
- data/test/test_factory_helper_team.rb +13 -0
- data/test/test_factory_helper_time.rb +74 -0
- data/test/test_flexible.rb +57 -0
- data/test/test_fr_locale.rb +34 -0
- data/test/test_helper.rb +15 -0
- data/test/test_locale.rb +45 -0
- data/test/test_pl_locale.rb +27 -0
- metadata +144 -20
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TesetFakerEnCaLocale < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@previous_locale = Faker::Config.locale
|
6
|
+
Faker::Config.locale = 'en-CA'
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
Faker::Config.locale = @previous_locale
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_ca_postcode
|
14
|
+
expected = /[A-VX-Y][0-9][A-CEJ-NPR-TV-Z] ?[0-9][A-CEJ-NPR-TV-Z][0-9]/
|
15
|
+
assert_match(expected, Faker::Address.postcode)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TesetFakerEnLocale < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Faker::Config.locale = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
Faker::Config.locale = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_us_states_only_include_states
|
13
|
+
assert_equal LoadedYaml['en']['address']['state'].size, 50
|
14
|
+
assert_equal LoadedYaml['en']['address']['state'], ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming']
|
15
|
+
assert_equal LoadedYaml['en']['address']['state_abbr'].size, 50
|
16
|
+
assert_equal LoadedYaml['en']['address']['state_abbr'], ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_us_zip_codes
|
20
|
+
Faker::Config.locale = 'en-US'
|
21
|
+
expected = /\d{5}(\-\d{4})?/
|
22
|
+
assert_match(expected, Faker::Address.zip_code)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TesetFakerEnUsLocale < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Faker::Config.locale = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
Faker::Config.locale = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_us_phone_methods_return_nil_for_nil_locale
|
13
|
+
assert_nil Faker::PhoneNumber.area_code
|
14
|
+
assert_nil Faker::PhoneNumber.exchange_code
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_subscriber_number_method
|
18
|
+
assert Faker::PhoneNumber.subscriber_number.is_a? String
|
19
|
+
assert_equal Faker::PhoneNumber.subscriber_number.length, 4
|
20
|
+
assert_equal Faker::PhoneNumber.subscriber_number(10).length, 10
|
21
|
+
assert_equal Faker::PhoneNumber.method(:extension), Faker::PhoneNumber.method(:subscriber_number)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_us_phone_methods_with_en_us_locale
|
25
|
+
Faker::Config.locale = 'en-US'
|
26
|
+
|
27
|
+
assert Faker::PhoneNumber.area_code.is_a? String
|
28
|
+
assert Faker::PhoneNumber.area_code.to_i.is_a? Integer
|
29
|
+
assert_equal Faker::PhoneNumber.area_code.length, 3
|
30
|
+
|
31
|
+
assert Faker::PhoneNumber.exchange_code.is_a? String
|
32
|
+
assert Faker::PhoneNumber.exchange_code.to_i.is_a? Integer
|
33
|
+
assert_equal Faker::PhoneNumber.exchange_code.length, 3
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_validity_of_phone_method_output
|
37
|
+
Faker::Config.locale = 'en-US'
|
38
|
+
|
39
|
+
# got the following regex from http://stackoverflow.com/a/123666/1210055 as an expression of the NANP standard.
|
40
|
+
us_number_validation_regex = /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/
|
41
|
+
assert_match(us_number_validation_regex, Faker::PhoneNumber.phone_number)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_us_invalid_state_raises_exception
|
45
|
+
Faker::Config.locale = 'en-US'
|
46
|
+
assert_raise I18n::MissingTranslationData do Faker::Address.zip_code('NA') end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_us_zip_codes_match_state
|
50
|
+
|
51
|
+
Faker::Config.locale = 'en-US'
|
52
|
+
|
53
|
+
state_abbr = 'AZ'
|
54
|
+
expected = /^850\d\d$/
|
55
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
56
|
+
|
57
|
+
# disjointed ranges for these states
|
58
|
+
# http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf
|
59
|
+
state_abbr = 'AR'
|
60
|
+
expected = /^717\d\d$/
|
61
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
62
|
+
state_abbr = 'GA'
|
63
|
+
expected = /^301\d\d$/
|
64
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
65
|
+
state_abbr = 'MA'
|
66
|
+
expected = /^026\d\d$/
|
67
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
68
|
+
state_abbr = 'NY'
|
69
|
+
expected = /^122\d\d$/
|
70
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
71
|
+
state_abbr = 'TX'
|
72
|
+
expected = /^798\d\d$/
|
73
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
74
|
+
state_abbr = 'VA'
|
75
|
+
expected = /^222\d\d$/
|
76
|
+
assert_match(expected, Faker::Address.zip_code(state_abbr))
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
LoadedFakerEsYaml = ['en', 'es'].inject({}) do |h, locale|
|
4
|
+
h[locale] = YAML.load_file(File.expand_path(File.dirname(__FILE__) + "/../../lib/locales/#{locale}.yml"))[locale]['factory_helper']
|
5
|
+
h
|
6
|
+
end
|
7
|
+
|
8
|
+
class TestFakerEsLocale < Test::Unit::TestCase
|
9
|
+
def teardown
|
10
|
+
Faker::Config.locale = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_locale_separate_from_i18n
|
14
|
+
I18n.locale = :en
|
15
|
+
Faker::Config.locale = :es
|
16
|
+
assert Faker::Address.street_name.match(//)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_configured_locale_translation
|
20
|
+
Faker::Config.locale = 'es'
|
21
|
+
assert_equal Faker::Base.translate('factory_helper.address.city_prefix').first, LoadedFakerEsYaml['es']['address']['city_prefix'].first
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_locale_override_when_calling_translate
|
25
|
+
Faker::Config.locale = 'es'
|
26
|
+
assert_equal Faker::Base.translate('factory_helper.lorem.words', :locale => :en).first, LoadedFakerEsYaml['en']['lorem']['words'].first
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_translation_fallback
|
30
|
+
Faker::Config.locale = 'es'
|
31
|
+
assert_nil LoadedFakerEsYaml['es']['company']['bs']
|
32
|
+
assert_equal Faker::Base.translate('factory_helper.company.bs'), LoadedFakerEsYaml['en']['company']['bs']
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TestFaker < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_numerify
|
9
|
+
100.times do
|
10
|
+
assert Faker::Base.numerify('###').match(/[1-9]\d{2}/)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_letterify
|
15
|
+
assert Faker::Base.letterify('???').match(/[A-Z]{3}/)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_regexify
|
19
|
+
{
|
20
|
+
'uk post code' => /^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/,
|
21
|
+
'us phone' => /^(1-?)[2-8][0-1][0-9]-\d{3}-\d{4}$/
|
22
|
+
}.each do |label, re|
|
23
|
+
10.times do
|
24
|
+
assert re.match(result = Faker::Base.regexify(re)), "#{result} is not a match for #{label}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
|
2
|
+
|
3
|
+
class TestFakerBitcoin < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_address
|
6
|
+
assert Faker::Bitcoin.address.match(/^[13][1-9A-Za-z][^OIl]{20,40}/)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_testnet_address
|
10
|
+
assert_match(/\A[mn][1-9A-Za-z]{32,34}\Z/, Faker::Bitcoin.testnet_address)
|
11
|
+
assert_not_match(/[OIl]/, Faker::Bitcoin.testnet_address)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class TestFakerBusiness < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@tester = Faker::Business
|
7
|
+
@credit_card_number_list = I18n.translate('factory_helper.business.credit_card_numbers')
|
8
|
+
@credit_card_number_expiry_dates = I18n.translate('factory_helper.business.credit_card_expiry_dates')
|
9
|
+
@credit_card_types = I18n.translate('factory_helper.business.credit_card_types')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_credit_card_number
|
13
|
+
number1 = @tester.credit_card_number
|
14
|
+
number2 = @tester.credit_card_number
|
15
|
+
assert @credit_card_number_list.include?(number1)
|
16
|
+
assert @credit_card_number_list.include?(number2)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_credit_card_expiry_date
|
20
|
+
date1 = @tester.credit_card_expiry_date
|
21
|
+
date2 = @tester.credit_card_expiry_date
|
22
|
+
assert @credit_card_number_expiry_dates.collect{|d| Date.parse(d)}.include?(date1)
|
23
|
+
assert @credit_card_number_expiry_dates.collect{|d| Date.parse(d)}.include?(date2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_credit_card_type
|
27
|
+
type1 = @tester.credit_card_type
|
28
|
+
type2 = @tester.credit_card_type
|
29
|
+
assert @credit_card_types.include?(type1)
|
30
|
+
assert @credit_card_types.include?(type2)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
class TestFakerCity < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
I18n.reload!
|
6
|
+
xx = {
|
7
|
+
:factory_helper => {
|
8
|
+
:name => {:female_first_name => ['alice'], :male_first_name => ['alice'], :last_name => ['smith']},
|
9
|
+
:address => {:city_prefix => ['west'], :city_suffix => ['burg']}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
I18n.backend.store_translations(:xx, xx)
|
13
|
+
|
14
|
+
xy = {
|
15
|
+
:factory_helper => {
|
16
|
+
:address => {
|
17
|
+
:city_prefix => ['big'],
|
18
|
+
:city_root => ['rock'],
|
19
|
+
:city_root_suffix => ['ing'],
|
20
|
+
:city_suffix => ['town'],
|
21
|
+
:city => ['#{city_prefix} #{city_root}#{city_root_suffix} #{city_suffix}']
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
I18n.backend.store_translations(:xy, xy)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_default_city_formats
|
29
|
+
I18n.with_locale(:xx) do
|
30
|
+
100.times do
|
31
|
+
cities = ["west alice", "west smith", "west aliceburg", "west smithburg", "aliceburg", "smithburg"]
|
32
|
+
city = Faker::Address.city
|
33
|
+
assert cities.include?(city), "Expected <#{cities.join(' / ')}>, but got #{city}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_city_formats_are_flexible
|
39
|
+
I18n.with_locale(:xy) do
|
40
|
+
cities = ['big rocking town']
|
41
|
+
city = Faker::Address.city
|
42
|
+
assert cities.include?(city), "Expected <#{cities.join(' / ')}>, but got #{city}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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_default_isbn_regexp
|
9
|
+
assert @tester.isbn.match(/^\d{9}-[\d|X]$/)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_default_isbn13_regexp
|
13
|
+
assert @tester.isbn(13).match(/^\d{12}-\d$/)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_default_ean_regexp
|
17
|
+
assert @tester.ean.match(/^\d{13}$/)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_default_ean8_regexp
|
21
|
+
assert @tester.ean(8).match(/^\d{8}$/)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_rut
|
25
|
+
assert @tester.rut.match(/^\d{1,8}-(\d|k)$/)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,74 @@
|
|
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
|
+
data = {
|
27
|
+
:factory_helper => {
|
28
|
+
:separator => ' + ',
|
29
|
+
:commerce => {
|
30
|
+
:department => ['Books', 'Movies']
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
I18n.reload!
|
36
|
+
I18n.backend.store_translations(:xy, data)
|
37
|
+
I18n.with_locale(:xy) do
|
38
|
+
assert_match ' + ', @tester.department(2, true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_department_should_have_exact_number_of_categories_when_fixed_amount
|
43
|
+
assert_match(/\A([A-Za-z]+, ){8}[A-Za-z]+ & [A-Za-z]+\z/, @tester.department(10, true))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_department_should_never_exceed_the_max_number_of_categories_when_random_amount
|
47
|
+
100.times do
|
48
|
+
assert_match(/\A([A-Za-z]+(, | & )){0,5}[A-Za-z]+\z/, @tester.department(6))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_department_should_have_no_duplicate_categories
|
53
|
+
department = @tester.department(10, true)
|
54
|
+
|
55
|
+
departments = department.split(/[,& ]+/)
|
56
|
+
assert_equal departments, departments.uniq
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_product_name
|
60
|
+
assert @tester.product_name.match(/[A-Z][a-z]+\.?/)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_material
|
64
|
+
assert @tester.material.match(/[A-Z][a-z]+\.?/)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_price
|
68
|
+
assert_includes 0..100, @tester.price
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_price_is_float
|
72
|
+
assert @tester.price.is_a? Float
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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{http://pigment.github.io/fake-logos/logos/medium/color/\d+\.png})
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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_forward
|
20
|
+
today = Date.today
|
21
|
+
|
22
|
+
100.times do
|
23
|
+
random_date = @tester.forward(5)
|
24
|
+
assert random_date > today, "Expected > \"#{today}\", but got #{random_date}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_backward
|
29
|
+
today = Date.today
|
30
|
+
|
31
|
+
100.times do
|
32
|
+
random_date = @tester.backward(5)
|
33
|
+
assert random_date < today, "Expected < \"#{today}\", but got #{random_date}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_return_type
|
38
|
+
random_forward = @tester.forward(5)
|
39
|
+
random_backward = @tester.backward(5)
|
40
|
+
random_between = @tester.between(Date.today, Date.today + 5)
|
41
|
+
|
42
|
+
[random_forward, random_backward, random_between].each do |result|
|
43
|
+
assert result.is_a?(Date), "Expected a Date object, but got #{result.class}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_invalid_date
|
48
|
+
assert_raise ArgumentError do
|
49
|
+
@tester.between("9999-99-99", "9999-99-99")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_birthday
|
54
|
+
min = 40
|
55
|
+
max = 90
|
56
|
+
100.times do
|
57
|
+
t = Date.today
|
58
|
+
date_min = Date.new(t.year - min, t.month, t.day)
|
59
|
+
date_max = Date.new(t.year - max, t.month, t.day)
|
60
|
+
birthday = @tester.birthday(min, max)
|
61
|
+
assert birthday > date_max, "Expect > \"#{date_max}\", but got #{birthday}"
|
62
|
+
assert birthday < date_min, "Expect > \"#{date_max}\", but got #{birthday}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
def test_default_birthday
|
66
|
+
min = 10
|
67
|
+
max = 65
|
68
|
+
100.times do
|
69
|
+
t = Date.today
|
70
|
+
date_min = Date.new(t.year - min, t.month, t.day)
|
71
|
+
date_max = Date.new(t.year - max, t.month, t.day)
|
72
|
+
birthday = @tester.birthday
|
73
|
+
assert birthday > date_max, "Expect > \"#{date_max}\", but got #{birthday}"
|
74
|
+
assert birthday < date_min, "Expect > \"#{date_max}\", but got #{birthday}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|