spec/document_spec.rb in mida-0.3.0 vs spec/document_spec.rb in mida-0.3.1

- old
+ new

@@ -28,20 +28,10 @@ element.should == expected_results[i] end end end -shared_examples_for 'one root itemscope' do - it 'should not match itemscopes with different names' do - @md.search(%r{nothing}).size.should == 0 - end - - it 'should find the correct number of itemscopes' do - @md.items.size.should == 1 - end -end - describe Mida::Document do before do html = ' <html><body> There is some text here @@ -76,10 +66,53 @@ organization.type.should == 'http://data-vocabulary.org/Organization' organization.properties['name'].should == ["An org name"] end end +describe Mida::Document, 'when initialized' do + before do + @html = ' + <html><body> + <div itemscope itemtype="http://data-vocabulary.org/Review"> + <span itemprop="itemreviewed">Romeo Pizza</span> + <span itemprop="itemreviewed">Some Other Pizza</span> + </div> + </body></html> + ' + + class Review < Mida::Vocabulary + itemtype %r{http://data-vocabulary.org/Review} + has_one 'item_reviewed' + end + end + + context 'with validation on' do + before do + @md = Mida::Document.new(@html) + end + + it 'should reject properties for items of known vocabularies that are not valid' do + @md.items[0].properties.should == {} + end + end + + context 'with validation off' do + before do + @md = Mida::Document.new(@html, false) + end + + it 'should accept properties for items of known vocabularies even if not valid' do + @md.items[0].properties['itemreviewed'].should == + ['Romeo Pizza', 'Some Other Pizza'] + end + end + + after do + Mida::Vocabulary.unregister(Review) + end +end + describe Mida::Document, 'when run against a full html document containing itemscopes with and without itemtypes' do before do html = ' <html><body> @@ -159,11 +192,10 @@ it 'should return all the properties and types with the correct values for 1st itemscope' do expected_results = [{ type: 'http://data-vocabulary.org/Review', - id: nil, properties: { 'itemreviewed' => ['Romeo Pizza'], 'rating' => ['4.5'] } }] @@ -171,11 +203,10 @@ end it 'should return all the properties from the text for 2nd itemscope' do expected_results = [{ type: 'http://data-vocabulary.org/Organization', - id: nil, properties: { 'name' => ['An org name'], 'url' => ['http://example.com'] } }] @@ -207,12 +238,18 @@ ' @md = Mida::Document.new(html) end - it_should_behave_like 'one root itemscope' + it 'should not match itemscopes with different names' do + @md.search(%r{nothing}).size.should == 0 + end + it 'should find the correct number of itemscopes' do + @md.items.size.should == 1 + end + it 'should return the correct number of itemscopes' do vocabularies = [ %r{http://data-vocabulary.org/Product}, %r{http://data-vocabulary.org/Review-aggregate} ] @@ -222,17 +259,15 @@ context "when looking at the outer vocabulary" do it 'should return all the properties from the text with the correct values' do expected_results = [{ type: 'http://data-vocabulary.org/Product', - id: nil, properties: { 'name' => ['DC07'], 'brand' => ['Dyson'], 'review' => [{ type: 'http://data-vocabulary.org/Review-aggregate', - id: nil, properties: { 'count' => ['1'], 'rating' => ['5.0'] } }] @@ -285,17 +320,15 @@ context "when no vocabulary specified or looking at the outer vocabulary" do it 'should return all the properties from the text with the correct values' do pending("get the contains: feature working") expected_result = { type: 'http://data-vocabulary.org/Product', - id: nil, properties: { 'name' => 'DC07', 'brand' => 'Dyson' }, contains: { type: 'http://data-vocabulary.org/Review-aggregate', - id: nil, properties: { 'count' => '1', 'rating' => '5.0' } }