Skip to content

Commit ff279fa

Browse files
jgarber623Ben Roberts
authored and
Ben Roberts
committed
Spec cleanup (#110)
* Update configuration with lower values * Update spec_helper, disabling WebMock net connections * Clean up and organize spec files
1 parent 8d788c7 commit ff279fa

11 files changed

+209
-205
lines changed

.rubocop.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ Metrics/BlockLength:
99
Metrics/LineLength:
1010
Enabled: false
1111

12-
RSpec/ExampleLength:
13-
Max: 15
14-
1512
RSpec/MultipleExpectations:
16-
Max: 10
13+
Max: 5
1714

1815
RSpec/NestedGroups:
19-
Max: 6
16+
Max: 4
2017

2118
Style/Documentation:
2219
Enabled: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
describe Microformats::AbsoluteUri, '#absolutize' do
2+
subject { described_class.new(relative, base: base).absolutize }
3+
4+
context 'when relative is nil' do
5+
let(:relative) { nil }
6+
let(:base) { 'http://example.com' }
7+
8+
it { is_expected.to eq(base) }
9+
end
10+
11+
context 'when relative is an empty string' do
12+
let(:relative) { '' }
13+
let(:base) { 'http://example.com' }
14+
15+
it { is_expected.to eq(base) }
16+
end
17+
18+
context 'when relative is a valid absolute URI' do
19+
let(:base) { nil }
20+
let(:relative) { 'http://google.com' }
21+
22+
it { is_expected.to eq('http://google.com') }
23+
end
24+
25+
context 'when relative is a valid non-absolute URI' do
26+
let(:relative) { 'bar/qux' }
27+
28+
context 'when base is present but not absolute' do
29+
let(:base) { 'foo' }
30+
31+
it { is_expected.to eq('bar/qux') }
32+
end
33+
34+
context 'when base is present and absolute' do
35+
let(:base) { 'http://google.com' }
36+
37+
it { is_expected.to eq('http://google.com/bar/qux') }
38+
end
39+
40+
context 'when base is not present' do
41+
let(:base) { nil }
42+
43+
it { is_expected.to eq('bar/qux') }
44+
end
45+
46+
context 'when base has a subdir' do
47+
let(:base) { 'http://google.com/asdf.html' }
48+
49+
it { is_expected.to eq('http://google.com/bar/qux') }
50+
end
51+
end
52+
53+
context 'when relative is an invalid URI' do
54+
let(:base) { nil }
55+
let(:relative) { '[email protected]:indieweb/microformats-ruby.git' }
56+
57+
it { is_expected.to eq(relative) }
58+
end
59+
end

spec/lib/microformats/absolute_uri_spec.rb

-61
This file was deleted.

spec/lib/microformats/collection_spec.rb

+15-13
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,51 @@
33

44
describe 'collection to hash or string' do
55
let(:html) { '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>' }
6+
let(:collection) { parser.parse(html) }
67

78
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')
910
end
1011

1112
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')
1314
end
1415

1516
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')
1718
end
1819

1920
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"=>{}}')
2122
end
2223
end
2324

2425
describe 'collection functions' do
2526
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) }
2628

2729
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/')
2931
end
3032

3133
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')
3335
end
3436

3537
it 'has respond_to? function' do
36-
expect(Microformats.parse(html)).to respond_to(:respond_to?)
38+
expect(collection).to respond_to(:respond_to?)
3739
end
3840

3941
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)
4547
end
4648

4749
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)
4951
end
5052
end
5153
end

spec/lib/microformats/parser_result_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
describe 'conversion functions' do
55
let(:html) { '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>' }
6-
let(:item) { Microformats.parse(html).items[0] }
6+
let(:item) { parser.parse(html).items[0] }
77

88
it 'is accessible as a hash []' do
99
expect(item['properties']['name'][0]).to eq('Jessica Lynn Suttles')
@@ -28,14 +28,14 @@
2828

2929
describe 'parser result functions' do
3030
let(: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-
let(:item) { Microformats.parse(html).items[0] }
31+
let(:item) { parser.parse(html).items[0] }
3232

3333
it 'has respond_to? function' do
3434
expect(item).to respond_to(:respond_to?)
3535
end
3636

3737
it 'returns PropertySets' do
38-
expect(item.properties).to be_kind_of Microformats::PropertySet
38+
expect(item.properties).to be_kind_of(Microformats::PropertySet)
3939
end
4040

4141
it 'supports old parser function calls by property name' do

0 commit comments

Comments
 (0)