spec/postrank-uri_spec.rb in postrank-uri-1.0.8 vs spec/postrank-uri_spec.rb in postrank-uri-1.0.9
- old
+ new
@@ -175,22 +175,29 @@
end
end
end
context "hash" do
- def h(uri)
- PostRank::URI.hash(uri)
+ def h(uri, opts = {})
+ PostRank::URI.hash(uri, opts)
end
it "should compute MD5 hash of the normalized URI" do
hash = '55fae8910d312b7878a3201ed653b881'
h('http://EverBurning.Com/feed/post/1').should == hash
h('Everburning.com/feed/post/1').should == hash
h('everburning.com/feed/post/1').should == hash
h('everburning.com/feed/post/1/').should == hash
end
+
+ it "should not clean the URI if requested" do
+ hash = '55fae8910d312b7878a3201ed653b881'
+
+ h('http://everburning.com/feed/post/1', :skip_clean => true).should == hash
+ h('everburning.com/feed/post/1', :skip_clean => true).should_not == hash
+ end
end
context "extract" do
def e(text)
PostRank::URI.extract(text)
@@ -263,8 +270,33 @@
i = PostRank::URI.extract_href("<a href='/stuff'>link to stuff</a>", "igvita.com").first
i.first.should == 'http://igvita.com/stuff'
i.last.should == 'link to stuff'
end
end
- end
+ context 'domain extraction' do
+ url_list = {"http://alex.pages.example.com" => "example.com",
+ "alex.pages.example.com" => "example.com",
+ "http://example.com/2011/04/01/blah" => "example.com",
+ "http://example.com" => "example.com",
+ "example.com" => "example.com",
+ "ExampLe.com" => "example.com",
+ "ExampLe.com:3000" => "example.com",
+ "http://alex.pages.example.COM" => "example.com",
+ "http://www.example.ag.it/2011/04/01/blah" => "example.ag.it",
+ "ftp://www.example.com/2011/04/01/blah" => nil,
+ "http://com" => nil,
+ "http://alex.pages.examplecom" => nil,
+ "example" => nil,
+ "http://127.0.0.1" => nil,
+ "localhost" => nil
+ }
+
+ url_list.each_pair do |url, expected_result|
+ it "should extract #{expected_result.inspect} from #{url}" do
+ u = PostRank::URI.clean(url, :raw => true)
+ u.domain.should == expected_result
+ end
+ end
+ end
+ end
end