From e8d9e77e4178f14359af2d05387e16e4809d40da Mon Sep 17 00:00:00 2001 From: Michael Mitchell + Chris Stringer Date: Fri, 22 Mar 2013 16:03:51 -0700 Subject: [PATCH] InvalidPropertyPrefix error class Raise a InvalidPropertyPrefix error if the prefix is invalid. --- lib/microformats2.rb | 3 +++ lib/microformats2/format.rb | 1 + spec/lib/microformats2/collection_spec.rb | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/microformats2.rb b/lib/microformats2.rb index cb906d0..f1bca62 100644 --- a/lib/microformats2.rb +++ b/lib/microformats2.rb @@ -33,4 +33,7 @@ module Microformats2 html end end # class << self + + class InvalidPropertyPrefix < StandardError; end + end diff --git a/lib/microformats2/format.rb b/lib/microformats2/format.rb index 0378749..8460888 100644 --- a/lib/microformats2/format.rb +++ b/lib/microformats2/format.rb @@ -37,6 +37,7 @@ module Microformats2 prefix = property_class.split("-").first # find ruby class for kind of property klass = Microformats2::Property::PREFIX_CLASS_MAP[prefix] + raise InvalidPropertyPrefix unless klass # We don't have a nokogiri element so pass in nil property = klass.new(nil, property_class, value) assign_property(property) diff --git a/spec/lib/microformats2/collection_spec.rb b/spec/lib/microformats2/collection_spec.rb index 2ce4e47..1f51131 100644 --- a/spec/lib/microformats2/collection_spec.rb +++ b/spec/lib/microformats2/collection_spec.rb @@ -76,17 +76,22 @@ describe Microformats2::Collection do describe "Format.add_property" do let(:value) { "bar" } - before do - @collection.first.add_property("p-foo", value) - end it "creates the attr" do + @collection.first.add_property("p-foo", value) @collection.first.foo.to_s.should == value end it "allows json output of the attribute" do + @collection.first.add_property("p-foo", value) @collection.first.to_json.should include(value) end + + it "raises a InvalidPropertyPrefix error if the prefix is invalid" do + expect { + @collection.first.add_property("xxx-foo", value) + }.to raise_error Microformats2::InvalidPropertyPrefix + end end end