spec/document_spec.rb in mida-0.3.9 vs spec/document_spec.rb in mida-0.4.0
- old
+ new
@@ -9,25 +9,25 @@
test_properties(item, expected_result)
end
end
def test_to_h(item, expected_result)
- item.to_h.should == expected_result
+ expect(item.to_h).to eq(expected_result)
end
def test_properties(item, expected_result)
item.properties.each do |name, value|
- match_array(value, expected_result[:properties][name])
+ match_array_legacy(value, expected_result[:properties][name])
end
end
-def match_array(value_array, expected_results)
+def match_array_legacy(value_array, expected_results)
value_array.each_with_index do |element, i|
if element.is_a?(Mida::Item)
test_properties(element, expected_results[i])
else
- element.should == expected_results[i]
+ expect(element).to eq(expected_results[i])
end
end
end
describe Mida::Document do
@@ -47,27 +47,34 @@
</div>
</div>
</body></html>
'
+ @nokogiri_document = Nokogiri(html)
+
@md = Mida::Document.new(html)
end
it '#each should pass each item to the block' do
item_num = 0
- @md.each {|item| item.should == @md.items[item_num]; item_num += 1}
+ @md.each {|item| expect(item).to eq(@md.items[item_num]); item_num += 1}
end
it 'should have access to the Enumerable mixin methods such as #find' do
review = @md.find {|item| item.type == 'http://data-vocabulary.org/Review'}
- review.type.should == 'http://data-vocabulary.org/Review'
- review.properties['itemreviewed'].should == ["Romeo Pizza"]
+ expect(review.type).to eq('http://data-vocabulary.org/Review')
+ expect(review.properties['itemreviewed']).to eq(["Romeo Pizza"])
organization = @md.find {|item| item.type == 'http://data-vocabulary.org/Organization'}
- organization.type.should == 'http://data-vocabulary.org/Organization'
- organization.properties['name'].should == ["An org name"]
+ expect(organization.type).to eq('http://data-vocabulary.org/Organization')
+ expect(organization.properties['name']).to eq(["An org name"])
end
+
+ it 'should not re-parse a nokogiri document' do
+ md = Mida::Document.new(@nokogiri_document)
+ expect(md.instance_variable_get(:@doc).object_id).to eq(@nokogiri_document.object_id)
+ end
end
describe Mida::Document, 'when initialized' do
before do
@html = '
@@ -114,18 +121,18 @@
end
it '#search should be able to match against items without an itemtype' do
items = @md.search(%r{^$})
- items.size.should == 1
- items[0].properties['name'].should == ['An org name']
+ expect(items.size).to eq(1)
+ expect(items[0].properties['name']).to eq(['An org name'])
end
it '#search should be able to match against items with an itemtype' do
items = @md.search(%r{^.+$})
- items.size.should == 1
- items[0].type.should == 'http://data-vocabulary.org/Review'
+ expect(items.size).to eq(1)
+ expect(items[0].type).to eq('http://data-vocabulary.org/Review')
end
end
describe Mida::Document, 'when run against a full html document containing two non-nested itemscopes with itemtypes' do
@@ -150,11 +157,11 @@
@md = Mida::Document.new(html)
end
it 'should return all the itemscopes' do
- @md.items.size.should == 2
+ expect(@md.items.size).to eq(2)
end
it 'should give the type of each itemscope if none specified' do
itemscope_names = {
'http://data-vocabulary.org/Review' => 0,
@@ -163,12 +170,12 @@
@md.items.each do |item|
itemscope_names[item.type] += 1
end
- itemscope_names.size.should eq 2
- itemscope_names.each { |name, num| num.should == 1 }
+ expect(itemscope_names.size).to eq 2
+ itemscope_names.each { |name, num| expect(num).to eq(1) }
end
it 'should return all the properties and types with the correct values for 1st itemscope' do
expected_results = [{
@@ -218,23 +225,23 @@
@md = Mida::Document.new(html)
end
it 'should not match itemscopes with different names' do
- @md.search(%r{nothing}).size.should == 0
+ expect(@md.search(%r{nothing}).size).to eq(0)
end
it 'should find the correct number of itemscopes' do
- @md.items.size.should == 1
+ expect(@md.items.size).to eq(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}
]
- vocabularies.each {|vocabulary| @md.search(vocabulary).size.should == 1}
+ vocabularies.each {|vocabulary| expect(@md.search(vocabulary).size).to eq(1)}
end
context "when looking at the outer vocabulary" do
it 'should return all the properties from the text with the correct values' do
@@ -287,20 +294,20 @@
vocabularies = {
%r{} => 2,
%r{http://data-vocabulary.org/Product} => 1,
%r{http://data-vocabulary.org/Review-aggregate} => 1
}
- vocabularies.each {|vocabulary, num| @md.search(vocabulary).size.should == num}
+ vocabularies.each {|vocabulary, num| expect(@md.search(vocabulary).size).to eq(num)}
end
it 'should return the correct number of items' do
- @md.items.size.should == 2
+ expect(@md.items.size).to eq(2)
end
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")
+ skip("get the contains: feature working")
expected_result = {
type: 'http://data-vocabulary.org/Product',
properties: {
'name' => 'DC07',
'brand' => 'Dyson'
@@ -312,9 +319,9 @@
'rating' => '5.0'
}
}
}
- @md.search('http://data-vocabulary.org/Product').first.should == expected_result
+ expect(@md.search('http://data-vocabulary.org/Product').first).to eq(expected_result)
end
end
end