Skip to content

Commit 472d5a5

Browse files
Ben Robertsjgarber623
Ben Roberts
authored andcommitted
work on test coverage
1 parent 21d45f3 commit 472d5a5

File tree

7 files changed

+144
-52
lines changed

7 files changed

+144
-52
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ Gemfile.lock
3232

3333
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3434
.rvmrc
35+
36+
#vim files being edited
37+
*.swp

lib/microformats/results/parser_result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def to_json
2020
def to_s
2121
return @hash['value'] if @hash['value']
2222

23-
super
23+
@hash.to_s
2424
end
2525

2626
def [](key)

lib/microformats/results/property_set.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def [](key)
2121
@hash[key]
2222
end
2323

24+
def to_s
25+
@hash.to_s
26+
end
27+
2428
def respond_to?(sym, include_private = false)
2529
key?(sym) || super(sym, include_private)
2630
end
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
describe Microformats::Collection do
2+
let(:parser) { Microformats::Parser.new }
3+
4+
5+
describe "collection to hash or string" do
6+
before do
7+
@html = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
8+
@html.freeze
9+
end
10+
11+
it "is accessible as a hash []" do
12+
expect(Microformats.parse(@html)['items'][0]['properties']['name'][0]).to eq("Jessica Lynn Suttles")
13+
end
14+
it "can convert to hash" do
15+
expect(Microformats.parse(@html).to_hash['items'][0]['properties']['name'][0]).to eq("Jessica Lynn Suttles")
16+
end
17+
it "can convert to hash by to_h" do
18+
expect(Microformats.parse(@html).to_h['items'][0]['properties']['name'][0]).to eq("Jessica Lynn Suttles")
19+
end
20+
it "converts to string" do
21+
expect(Microformats.parse(@html).to_s).to eq("{\"items\"=>[{\"type\"=>[\"h-card\"], \"properties\"=>{\"name\"=>[\"Jessica Lynn Suttles\"]}}], \"rels\"=>{}, \"rel-urls\"=>{}}")
22+
end
23+
end
24+
25+
describe "collection functions" do
26+
before do
27+
@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>'
28+
@html.freeze
29+
end
30+
31+
it "is has rels function" do
32+
expect(Microformats.parse(@html).rels['canonical'][0]).to eq('https://example.com/')
33+
end
34+
35+
it "is has rel_urls function" do
36+
expect(Microformats.parse(@html).rel_urls['https://example.com/']['rels'][0]).to eq('canonical')
37+
end
38+
39+
it "has respond_to? function" do
40+
expect(Microformats.parse(@html)).to respond_to(:respond_to?)
41+
end
42+
43+
it "supports old parser function calls by h- name" do
44+
expect(Microformats.parse(@html).card.to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
45+
expect(Microformats.parse(@html).card(:all)[0].to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
46+
expect(Microformats.parse(@html).card(0).to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
47+
expect(Microformats.parse(@html).card(3).to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
48+
expect(Microformats.parse(@html).as_sample.to_hash).to eq(Microformats.parse(@html).items[1].to_hash)
49+
end
50+
51+
it "has an items function that returns an array of ParserResult objects" do
52+
expect(Microformats.parse(@html).items[0]).to be_kind_of Microformats::ParserResult
53+
end
54+
55+
end
56+
57+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
describe Microformats::ParserResult do
2+
let(:parser) { Microformats::Parser.new }
3+
4+
describe "conversion functions" do
5+
before do
6+
@html = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
7+
@html.freeze
8+
@item = Microformats.parse(@html).items[0]
9+
end
10+
11+
it "is accessible as a hash []" do
12+
expect(@item['properties']['name'][0]).to eq("Jessica Lynn Suttles")
13+
end
14+
it "can convert to hash" do
15+
expect(@item.to_hash['properties']['name'][0]).to eq("Jessica Lynn Suttles")
16+
end
17+
it "can convert to hash by to_h" do
18+
expect(@item.to_h['properties']['name'][0]).to eq("Jessica Lynn Suttles")
19+
end
20+
it "converts to json" do
21+
expect(@item.to_json).to eq("{\"type\":[\"h-card\"],\"properties\":{\"name\":[\"Jessica Lynn Suttles\"]}}")
22+
end
23+
it "converts to string" do
24+
expect(@item.to_s).to eq(@item.to_h.to_s)
25+
end
26+
end
27+
28+
describe "parser result functions" do
29+
before do
30+
@html = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p><a rel="canonical" class="u-url u-like-of" href="https://example.com/">homepage</a></div>'
31+
@html.freeze
32+
@item = Microformats.parse(@html).items[0]
33+
end
34+
35+
it "has respond_to? function" do
36+
expect(@item).to respond_to(:respond_to?)
37+
end
38+
39+
it "returns PropertySets" do
40+
expect(@item.properties).to be_kind_of Microformats::PropertySet
41+
end
42+
43+
it "supports old parser function calls by property name" do
44+
expect(@item.name).to eq("Jessica Lynn Suttles")
45+
expect(@item.url).to eq("https://example.com/")
46+
expect(@item.like_of).to eq("https://example.com/")
47+
end
48+
end
49+
50+
51+
end

spec/lib/microformats/parser_spec.rb

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -81,57 +81,6 @@
8181
end
8282
end
8383

84-
describe "#paser_results_classes" do
85-
86-
describe "collection to hash or string" do
87-
before do
88-
@html = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
89-
@html.freeze
90-
end
91-
92-
it "is accessible as a hash []" do
93-
expect(Microformats.parse(@html)['items'][0]['properties']['name'][0]).to eq("Jessica Lynn Suttles")
94-
end
95-
it "can convert to hash" do
96-
expect(Microformats.parse(@html).to_hash['items'][0]['properties']['name'][0]).to eq("Jessica Lynn Suttles")
97-
end
98-
it "can convert to hash by to_h" do
99-
expect(Microformats.parse(@html).to_h['items'][0]['properties']['name'][0]).to eq("Jessica Lynn Suttles")
100-
end
101-
it "converts to string" do
102-
expect(Microformats.parse(@html).to_s).to eq("{\"items\"=>[{\"type\"=>[\"h-card\"], \"properties\"=>{\"name\"=>[\"Jessica Lynn Suttles\"]}}], \"rels\"=>{}, \"rel-urls\"=>{}}")
103-
end
104-
end
105-
106-
describe "collection functions" do
107-
before do
108-
@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>'
109-
@html.freeze
110-
end
111-
112-
it "is has rels function" do
113-
expect(Microformats.parse(@html).rels['canonical'][0]).to eq('https://example.com/')
114-
end
115-
116-
it "is has rel_urls function" do
117-
expect(Microformats.parse(@html).rel_urls['https://example.com/']['rels'][0]).to eq('canonical')
118-
end
119-
120-
it "has respond_to? function" do
121-
expect(Microformats.parse(@html)).to respond_to(:respond_to?)
122-
end
123-
124-
it "supports old parser function calls by h- name" do
125-
expect(Microformats.parse(@html).card.to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
126-
expect(Microformats.parse(@html).card(:all)[0].to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
127-
expect(Microformats.parse(@html).card(0).to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
128-
expect(Microformats.parse(@html).card(3).to_hash).to eq(Microformats.parse(@html).items[0].to_hash)
129-
expect(Microformats.parse(@html).as_sample.to_hash).to eq(Microformats.parse(@html).items[1].to_hash)
130-
end
131-
end
132-
end
133-
134-
13584
describe "edge cases" do
13685
cases_dir = "spec/support/lib/edge_cases/"
13786
Dir[File.join(cases_dir, "*")].keep_if { |f| f =~ /([.]js$)/ }.each do |json_file|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
describe Microformats::PropertySet do
2+
let(:parser) { Microformats::Parser.new }
3+
4+
describe "conversion functions" do
5+
before do
6+
@html = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
7+
@html.freeze
8+
@set = Microformats.parse(@html).items[0].properties
9+
end
10+
11+
it "is accessible as a hash []" do
12+
expect(@set['name'][0]).to eq("Jessica Lynn Suttles")
13+
end
14+
it "can convert to hash" do
15+
expect(@set.to_hash['name'][0]).to eq("Jessica Lynn Suttles")
16+
end
17+
it "can convert to hash by to_h" do
18+
expect(@set.to_h['name'][0]).to eq("Jessica Lynn Suttles")
19+
end
20+
it "converts to json" do
21+
expect(@set.to_json).to eq("{\"name\":[\"Jessica Lynn Suttles\"]}")
22+
end
23+
it "converts to string" do
24+
expect(@set.to_s).to eq(@set.to_h.to_s)
25+
end
26+
end
27+
28+
end

0 commit comments

Comments
 (0)