cleans up implied property and adds lots of specs for them

This commit is contained in:
Jessica Lynn Suttles 2013-02-14 13:52:47 -08:00
parent 3f2a627816
commit 10ea0256fc
15 changed files with 339 additions and 62 deletions

View file

@ -132,39 +132,4 @@ describe Microformats2::Collection do
end
end
end
describe ".h-card implied properties simple" do
before do
html = "spec/support/hcard-implied-simple.html"
@collection = Microformats2.parse(html)
end
describe "#parse" do
it "assigns .h-card .p-name to HCard#name" do
@collection.first.name.first.value.should == "@jlsuttles"
end
it "assigns .h-card .p-photo to HCard#photo" do
@collection.first.photo.first.value.should == "http://gravatar.com/jlsuttles"
end
it "assigns .h-card .p-url to HCard#url" do
@collection.first.url.first.value.should == "http://twitter.com/jlsuttles"
end
end
describe "#to_hash" do
it "returns the correct Hash" do
hash = {
:items => [{
:type => ["h-card"],
:properties => {
:name => ["@jlsuttles"],
:photo => ["http://gravatar.com/jlsuttles"],
:url => ["http://twitter.com/jlsuttles"]
}
}]
}
@collection.to_hash.should == hash
end
end
end
end

View file

@ -0,0 +1,29 @@
require "spec_helper"
require "microformats2"
describe Microformats2::ImpliedProperty::Name do
describe "name-pass.html" do
html = "spec/support/lib/microformats2/implied_property/name-pass.html"
collection = Microformats2.parse(html)
it "should have the correct number of formats" do
collection.all.length.should == 6
end
collection.all.each_with_index do |format, index|
it "passes case #{index+1}" do
format.name.first.value.should == "Jessica"
end
end
end
describe "name-fail.html" do
html = "spec/support/lib/microformats2/implied_property/name-fail.html"
collection = Microformats2.parse(html)
it "should have the correct number of formats" do
collection.all.length.should == 8
end
collection.all.each_with_index do |format, index|
it "fails case #{index+1}" do
format.name.first.value.should == ""
end
end
end
end

View file

@ -0,0 +1,29 @@
require "spec_helper"
require "microformats2"
describe Microformats2::ImpliedProperty::Photo do
describe "photo-pass.html" do
html = "spec/support/lib/microformats2/implied_property/photo-pass.html"
collection = Microformats2.parse(html)
it "should have the correct number of formats" do
collection.all.length.should == 6
end
collection.all.each_with_index do |format, index|
it "passes case #{index+1}" do
format.photo.first.value.should == "http://gravatar.com/jlsuttles"
end
end
end
describe "photo-fail.html" do
html = "spec/support/lib/microformats2/implied_property/photo-fail.html"
collection = Microformats2.parse(html)
it "should have the correct number of formats" do
collection.all.length.should == 8
end
collection.all.each_with_index do |format, index|
it "fails case #{index+1}" do
format.photo.should be_nil
end
end
end
end

View file

@ -0,0 +1,29 @@
require "spec_helper"
require "microformats2"
describe Microformats2::ImpliedProperty::Url do
describe "url-pass.html" do
html = "spec/support/lib/microformats2/implied_property/url-pass.html"
collection = Microformats2.parse(html)
it "should have the correct number of formats" do
collection.all.length.should == 2
end
collection.all.each_with_index do |format, index|
it "passes case #{index+1}" do
format.url.first.value.should == "http://github.com/jlsuttles"
end
end
end
describe "url-fail.html" do
html = "spec/support/lib/microformats2/implied_property/url-fail.html"
collection = Microformats2.parse(html)
it "should have the correct number of formats" do
collection.all.length.should == 2
end
collection.all.each_with_index do |format, index|
it "fails case #{index+1}" do
format.url.should be_nil
end
end
end
end