test/test_gman.rb in gman-2.1.3 vs test/test_gman.rb in gman-3.0.0

- old
+ new

@@ -42,39 +42,53 @@ should "not allow educational domains" do assert_equal false, Gman::valid?("foo@gwu.edu") end should "properly parse domains from strings" do - assert_equal "github.gov", Gman::get_domain("foo@github.gov") - assert_equal "foo.github.gov", Gman::get_domain("foo.github.gov") - assert_equal "github.gov", Gman::get_domain("http://github.gov") - assert_equal "github.gov", Gman::get_domain("https://github.gov") - assert_equal ".gov", Gman::get_domain(".gov") - assert_equal nil, Gman.get_domain("foo") + assert_equal "github.gov", Gman.new("foo@github.gov").domain + assert_equal "foo.github.gov", Gman::new("foo.github.gov").domain + assert_equal "github.gov", Gman::new("http://github.gov").domain + assert_equal "github.gov", Gman::new("https://github.gov").domain + assert_equal ".gov", Gman::new(".gov").domain + assert_equal nil, Gman.new("foo").domain end should "not err out on invalid domains" do assert_equal false, Gman.valid?("foo@gov.invalid") - assert_equal "gov.invalid", Gman.get_domain("foo@gov.invalid") - assert_equal nil, Gman.domain_parts("foo@gov.invalid") + assert_equal "gov.invalid", Gman.new("foo@gov.invalid").domain + assert_equal nil, Gman.new("foo@gov.invalid").domain_parts end should "return public suffix domain" do - assert_equal PublicSuffix::Domain, Gman.domain_parts("whitehouse.gov").class - assert_equal NilClass, Gman.domain_parts("foo.invalid").class + assert_equal PublicSuffix::Domain, Gman.new("whitehouse.gov").domain_parts.class + assert_equal NilClass, Gman.new("foo.invalid").domain_parts.class end should "parse domain parts" do - assert_equal "gov", Gman.domain_parts("foo@bar.gov").tld - assert_equal "bar", Gman.domain_parts("foo.bar.gov").sld - assert_equal "bar", Gman.domain_parts("https://foo.bar.gov").sld - assert_equal "bar.gov", Gman.domain_parts("foo@bar.gov").domain + assert_equal "gov", Gman.new("foo@bar.gov").domain_parts.tld + assert_equal "bar", Gman.new("foo.bar.gov").domain_parts.sld + assert_equal "bar", Gman.new("https://foo.bar.gov").domain_parts.sld + assert_equal "bar.gov", Gman.new("foo@bar.gov").domain_parts.domain end should "not err out on invalid hosts" do - assert_equal nil, Gman.get_domain("</@foo.com") + assert_equal nil, Gman.new("</@foo.com").domain end should "returns the path to domains.txt" do assert_equal true, File.exists?(Gman.list_path) + end + + should "parse the alpha2" do + assert_equal "us", Gman.new("whitehouse.gov").alpha2 + assert_equal "us", Gman.new("army.mil").alpha2 + assert_equal "gb", Gman.new("foo.gov.uk").alpha2 + assert_equal "ca", Gman.new("gov.ca").alpha2 + end + + should "determine a domain's country" do + assert_equal "United States", Gman.new("whitehouse.gov").country.name + assert_equal "United States", Gman.new("army.mil").country.name + assert_equal "United Kingdom", Gman.new("foo.gov.uk").country.name + assert_equal "Canada", Gman.new("foo.gc.ca").country.name end end