adds to_hash and to_json for collection
This commit is contained in:
parent
0826659f1e
commit
d54e2015a3
6 changed files with 286 additions and 183 deletions
29
spec/lib/microformats2/collection_spec.rb
Normal file
29
spec/lib/microformats2/collection_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,15 +10,16 @@ describe Microformats2 do
|
|||
|
||||
describe "::parse" do
|
||||
before do
|
||||
html = "spec/support/simple.html"
|
||||
@microformats2 = Microformats2.parse(@html)
|
||||
end
|
||||
it "returns an array of found root microformats" do
|
||||
@microformats2.first.should be_kind_of HCard
|
||||
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
|
||||
puts @microformats2.first.to_hash
|
||||
@microformats2.first.name.should == "Jessica Lynn Suttles"
|
||||
@microformats2.h_card.name.should == "Jessica Lynn Suttles"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue