adds specs for all property types
This commit is contained in:
parent
a02055fd93
commit
9fae5c7248
6 changed files with 60 additions and 40 deletions
|
@ -2,28 +2,45 @@ require "spec_helper"
|
|||
require "microformats2"
|
||||
|
||||
describe Microformats2::Collection do
|
||||
before do
|
||||
@html = <<-HTML.strip
|
||||
<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>
|
||||
HTML
|
||||
@collection = Microformats2::Collection.new.parse(Nokogiri::HTML(@html))
|
||||
end
|
||||
|
||||
describe "#to_hash" do
|
||||
it "returns the correct Hash" do
|
||||
hash = {items: [
|
||||
{type: ["h-card"], properties: {name: "Jessica Lynn Suttles"}}
|
||||
]}
|
||||
@collection.to_hash.should == hash
|
||||
describe "with simple h-card" do
|
||||
before do
|
||||
html = "spec/support/simple_hcard.html"
|
||||
@collection = Microformats2.parse(html)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_json" do
|
||||
it "returns the correct JSON" do
|
||||
json = {items: [
|
||||
{type: ["h-card"], properties: {name: "Jessica Lynn Suttles"}}
|
||||
]}.to_json
|
||||
@collection.to_json.should == json
|
||||
describe "#parse" do
|
||||
it "creates ruby class HCard" do
|
||||
@collection.h_card.should be_kind_of HCard
|
||||
end
|
||||
it "assigns .h-card .p-name to HCard#name" do
|
||||
@collection.h_card.name.should == "Jessica Lynn Suttles"
|
||||
end
|
||||
it "assigns .h-card .u-url to HCard#url" do
|
||||
@collection.h_card.url.should == "http://twitter.com/jlsuttles"
|
||||
end
|
||||
it "assings .h-card .dt-bday to HCard#bday" do
|
||||
@collection.h_card.bday.should be_kind_of DateTime
|
||||
@collection.h_card.bday.to_s.should == "1990-10-15T20:45:33-08:00"
|
||||
end
|
||||
it "assigns .h-card .e-content to HCard#content" do
|
||||
@collection.h_card.content.should == "Vegan. Cat lover. Coder."
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_hash" do
|
||||
it "returns the correct Hash" do
|
||||
hash = {
|
||||
:items => [{ :type => ["h-card"],
|
||||
:properties => {
|
||||
:url => "http://twitter.com/jlsuttles",
|
||||
:name => "Jessica Lynn Suttles",
|
||||
:bday => "1990-10-15T20:45:33-08:00",
|
||||
:content => "Vegan. Cat lover. Coder."
|
||||
}
|
||||
}]
|
||||
}
|
||||
@collection.to_hash.should == hash
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,17 +9,8 @@ describe Microformats2 do
|
|||
end
|
||||
|
||||
describe "::parse" do
|
||||
before do
|
||||
@microformats2 = Microformats2.parse(@html)
|
||||
end
|
||||
it "returns a collection" do
|
||||
@microformats2.should be_kind_of Microformats2::Collection
|
||||
end
|
||||
it "assigns root formats to collection" do
|
||||
@microformats2.h_card.should be_kind_of HCard
|
||||
end
|
||||
it "assigns properties to found root microformats" do
|
||||
@microformats2.h_card.name.should == "Jessica Lynn Suttles"
|
||||
Microformats2.parse(@html).should be_kind_of Microformats2::Collection
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,8 +19,8 @@ describe Microformats2 do
|
|||
Microformats2.read_html(@html).should include @html
|
||||
end
|
||||
it "can be a file path to html" do
|
||||
html = "spec/support/simple.html"
|
||||
Microformats2.read_html(html).should include @html
|
||||
html = "spec/support/simple_hcard.html"
|
||||
Microformats2.read_html(html).should include "<div class=\"h-card\">"
|
||||
end
|
||||
it "can be a url to html" do
|
||||
html = "http://google.com"
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<html>
|
||||
<body>
|
||||
<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>
|
||||
</body>
|
||||
</html>
|
16
spec/support/simple_hcard.html
Normal file
16
spec/support/simple_hcard.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<html>
|
||||
<body>
|
||||
<div class="h-card">
|
||||
<a href="http://twitter.com/jlsuttles" class="u-url p-name">
|
||||
Jessica Lynn Suttles
|
||||
</a>
|
||||
<time class="dt-bday" datetime="1990-10-15T20:45:33-08:00">
|
||||
October 15, 1990
|
||||
</time>
|
||||
<div class="e-content">
|
||||
Vegan. Cat lover. Coder.
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue