|
3 | 3 |
|
4 | 4 | describe 'collection to hash or string' do
|
5 | 5 | let(:html) { '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>' }
|
| 6 | + let(:collection) { parser.parse(html) } |
6 | 7 |
|
7 | 8 | it 'is accessible as a hash []' do
|
8 |
| - expect(Microformats.parse(html)['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles') |
| 9 | + expect(collection['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles') |
9 | 10 | end
|
10 | 11 |
|
11 | 12 | it 'can convert to hash' do
|
12 |
| - expect(Microformats.parse(html).to_hash['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles') |
| 13 | + expect(collection.to_hash['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles') |
13 | 14 | end
|
14 | 15 |
|
15 | 16 | it 'can convert to hash by to_h' do
|
16 |
| - expect(Microformats.parse(html).to_h['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles') |
| 17 | + expect(collection.to_h['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles') |
17 | 18 | end
|
18 | 19 |
|
19 | 20 | it 'converts to string' do
|
20 |
| - expect(Microformats.parse(html).to_s).to eq('{"items"=>[{"type"=>["h-card"], "properties"=>{"name"=>["Jessica Lynn Suttles"]}}], "rels"=>{}, "rel-urls"=>{}}') |
| 21 | + expect(collection.to_s).to eq('{"items"=>[{"type"=>["h-card"], "properties"=>{"name"=>["Jessica Lynn Suttles"]}}], "rels"=>{}, "rel-urls"=>{}}') |
21 | 22 | end
|
22 | 23 | end
|
23 | 24 |
|
24 | 25 | describe 'collection functions' do
|
25 | 26 | let(:html) { '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p><a rel="canonical" class="u-url" href="https://example.com/">homepage</a></div><div class="h-as-sample"><p class="p-name">sample</p></div>' }
|
| 27 | + let(:collection) { parser.parse(html) } |
26 | 28 |
|
27 | 29 | it 'is has rels function' do
|
28 |
| - expect(Microformats.parse(html).rels['canonical'][0]).to eq('https://example.com/') |
| 30 | + expect(collection.rels['canonical'][0]).to eq('https://example.com/') |
29 | 31 | end
|
30 | 32 |
|
31 | 33 | it 'is has rel_urls function' do
|
32 |
| - expect(Microformats.parse(html).rel_urls['https://example.com/']['rels'][0]).to eq('canonical') |
| 34 | + expect(collection.rel_urls['https://example.com/']['rels'][0]).to eq('canonical') |
33 | 35 | end
|
34 | 36 |
|
35 | 37 | it 'has respond_to? function' do
|
36 |
| - expect(Microformats.parse(html)).to respond_to(:respond_to?) |
| 38 | + expect(collection).to respond_to(:respond_to?) |
37 | 39 | end
|
38 | 40 |
|
39 | 41 | it 'supports old parser function calls by h- name' do
|
40 |
| - expect(Microformats.parse(html).card.to_hash).to eq(Microformats.parse(html).items[0].to_hash) |
41 |
| - expect(Microformats.parse(html).card(:all)[0].to_hash).to eq(Microformats.parse(html).items[0].to_hash) |
42 |
| - expect(Microformats.parse(html).card(0).to_hash).to eq(Microformats.parse(html).items[0].to_hash) |
43 |
| - expect(Microformats.parse(html).card(3).to_hash).to eq(Microformats.parse(html).items[0].to_hash) |
44 |
| - expect(Microformats.parse(html).as_sample.to_hash).to eq(Microformats.parse(html).items[1].to_hash) |
| 42 | + expect(collection.card.to_hash).to eq(collection.items[0].to_hash) |
| 43 | + expect(collection.card(:all)[0].to_hash).to eq(collection.items[0].to_hash) |
| 44 | + expect(collection.card(0).to_hash).to eq(collection.items[0].to_hash) |
| 45 | + expect(collection.card(3).to_hash).to eq(collection.items[0].to_hash) |
| 46 | + expect(collection.as_sample.to_hash).to eq(collection.items[1].to_hash) |
45 | 47 | end
|
46 | 48 |
|
47 | 49 | it 'has an items function that returns an array of ParserResult objects' do
|
48 |
| - expect(Microformats.parse(html).items[0]).to be_kind_of(Microformats::ParserResult) |
| 50 | + expect(collection.items[0]).to be_kind_of(Microformats::ParserResult) |
49 | 51 | end
|
50 | 52 | end
|
51 | 53 | end
|
0 commit comments