test/test_internet.rb in ffaker-2.2.0 vs test/test_internet.rb in ffaker-2.3.0

- old
+ new

@@ -1,10 +1,19 @@ # encoding: utf-8 require '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 @@ -46,13 +55,17 @@ def test_domain_suffix assert @tester.domain_suffix.match(/^\w+(\.\w+)?/) end def test_uri - assert @tester.uri("ftp").match(/^ftp:\/\/.+/) - assert @tester.uri("http").match(/^http:\/\/.+/) - assert @tester.uri("https").match(/^https:\/\/.+/) + assert @tester.uri('ftp').match(/^ftp:\/\/.+/) + assert @tester.uri('http').match(/^http:\/\/.+/) + assert @tester.uri('https').match(/^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(/^http:\/\/.+/) end @@ -64,15 +77,17 @@ 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_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_match(/\A[a-z]+-[a-z]+\z/, @tester.slug(nil, '-')) + assert_deterministic { @tester.slug(nil, '-') } end def test_password assert_match(/\A[a-z]+\z/, @tester.password) end @@ -95,7 +110,23 @@ def test_password_strange_argument assert @tester.password(10, 2).length > 9 assert @tester.password(3, 1).length > 2 assert @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