spec/document_spec.rb in mida-0.1.3 vs spec/document_spec.rb in mida-0.2.0
- old
+ new
@@ -92,12 +92,14 @@
@md = Mida::Document.new(@html)
end
it 'should return all the properties and types with the correct values' do
expected_results = [
- { type: nil, id: nil, properties: {'link_field' => ['']} },
- { type: nil,
+ { vocabulary: Mida::Vocabulary::Generic,
+ type: nil, id: nil, properties: {'link_field' => ['']} },
+ { vocabulary: Mida::Vocabulary::Generic,
+ type: nil,
id: nil,
properties: {
'span_field' => ['Some span content'],
'dtreviewed' => ['2009-01-06'],
'meta_field' => ['Some meta content'],
@@ -128,15 +130,17 @@
@md = Mida::Document.new(@html, 'http://example.com/start/')
end
it 'should return all the properties and types with the correct values' do
expected_results = [
- { type: nil, id: nil, properties: {
+ { vocabulary: Mida::Vocabulary::Generic,
+ type: nil, id: nil, properties: {
'link_field' => ['http://example.com/start/stylesheet.css']
}
},
- { type: nil,
+ { vocabulary: Mida::Vocabulary::Generic,
+ type: nil,
id: nil,
properties: {
'span_field' => ['Some span content'],
'dtreviewed' => ['2009-01-06'],
'meta_field' => ['Some meta content'],
@@ -190,10 +194,11 @@
it_should_behave_like 'one root itemscope'
it 'should return all the properties and types with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'itemreviewed' => ['Romeo Pizza'],
'reviewer' => ['Ulysses Grant'],
@@ -236,15 +241,17 @@
it_should_behave_like 'one root itemscope'
it 'should return all the properties and types with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'itemreviewed' => ['Romeo Pizza'],
'address' => [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil, id: nil, properties: {
'firstline' => ['237 Italian Way'],
'country' => ['United Kingdom']
}
}],
@@ -285,19 +292,22 @@
it_should_behave_like 'one root itemscope'
it 'should return all the properties and types with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'itemreviewed' => ['Romeo Pizza'],
'address' => [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'firstline' => [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'number' => ['237'],
'road' => ['Italian Way']
@@ -349,10 +359,11 @@
@md.search(%r{http://data-vocabulary.org/Review}).first.type.should == 'http://data-vocabulary.org/Review'
end
it 'should return all the properties and types with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: 'http://data-vocabulary.org/Review',
id: nil,
properties: {
'itemreviewed' => ['Romeo Pizza'],
'reviewer' => ['Ulysses Grant'],
@@ -410,10 +421,11 @@
end
it 'should return all the properties and types with the correct values for 1st itemscope' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: 'http://data-vocabulary.org/Review',
id: nil,
properties: {
'itemreviewed' => ['Romeo Pizza'],
'rating' => ['4.5']
@@ -422,10 +434,11 @@
test_parsing(@md, %r{http://data-vocabulary.org/Review}, expected_results)
end
it 'should return all the properties from the text for 2nd itemscope' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: 'http://data-vocabulary.org/Organization',
id: nil,
properties: {
'name' => ['An org name'],
'url' => ['http://example.com']
@@ -472,16 +485,18 @@
end
context "when looking at the outer vocabulary" do
it 'should return all the properties from the text with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: 'http://data-vocabulary.org/Product',
id: nil,
properties: {
'name' => ['DC07'],
'brand' => ['Dyson'],
'review' => [{
+ vocabulary: Mida::Vocabulary::Generic,
type: 'http://data-vocabulary.org/Review-aggregate',
id: nil,
properties: {
'count' => ['1'],
'rating' => ['5.0']
@@ -578,15 +593,17 @@
@md = Mida::Document.new(html)
end
it 'should return all the properties from the text with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'name' => ['Amanda'],
'band' => [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'name' => ['Jazz Band'],
'size' => ['12']
@@ -632,17 +649,19 @@
vocabularies.each {|vocabulary| @md.search(vocabulary).size.should == 1}
end
it 'should return all the properties from the text with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: 'icecreams',
id: nil,
properties: {
'flavour' => [
'Lemon sorbet',
'Apricot sorbet',
- { type: 'icecream-type',
+ { vocabulary: Mida::Vocabulary::Generic,
+ type: 'icecream-type',
id: nil,
properties: {
'fruit' => ['Strawberry'],
'style' => ['Homemade']
}
@@ -669,16 +688,77 @@
@md = Mida::Document.new(html)
end
it 'should return all the properties from the text with the correct values' do
expected_results = [{
+ vocabulary: Mida::Vocabulary::Generic,
type: nil,
id: nil,
properties: {
'favourite-colour' => ['orange'],
'favourite-fruit' => ['orange']
}
}]
test_parsing(@md, %r{}, expected_results)
end
+end
+
+describe Mida::Document, 'when run against a full html document containing an itemtype that matches a registered vocabulary' do
+
+ before do
+ html = '
+ <html><body>
+ There is some text here
+ <div>
+ and also some here
+ <div itemscope itemtype="http://data-vocabulary.org/Review">
+ <span itemprop="itemreviewed">Romeo Pizza</span>
+ Reviewed by <span itemprop="reviewer">Ulysses Grant</span> on
+ <time itemprop="dtreviewed" datetime="2009-01-06">Jan 6</time>.
+ <span itemprop="summary">Delicious, tasty pizza in Eastlake!</span>
+ <span itemprop="description">This is a very nice pizza place.</span>
+ Rating: <span itemprop="rating">4.5</span>
+ </div>
+ </div>
+ </body></html>
+ '
+
+ class Review < Mida::VocabularyDesc
+ itemtype %r{http://data-vocabulary.org/Review}
+ has_one 'itemreviewed', 'reviewer', 'dtreviewed', 'summary'
+ has_one 'rating', 'description'
+ end
+ Mida::Vocabulary.register(Review)
+
+ @md = Mida::Document.new(html)
+
+ end
+
+ it_should_behave_like 'one root itemscope'
+
+ it '#search should match against Review' do
+ @md.search(Review).size.should == 1
+ end
+
+ it 'should specify the correct type' do
+ @md.search(Review).first.type.should == 'http://data-vocabulary.org/Review'
+ end
+
+ it 'should return all the properties and types with the correct values' do
+ expected_results = [{
+ vocabulary: Review,
+ type: 'http://data-vocabulary.org/Review',
+ id: nil,
+ properties: {
+ 'itemreviewed' => ['Romeo Pizza'],
+ 'reviewer' => ['Ulysses Grant'],
+ 'dtreviewed' => ['2009-01-06'],
+ 'summary' => ['Delicious, tasty pizza in Eastlake!'],
+ 'description' => ['This is a very nice pizza place.'],
+ 'rating' => ['4.5']
+ }
+ }]
+ test_parsing(@md, Review, expected_results)
+ end
+
end