Skip to content

Commit

Permalink
Spec cleanup (microformats#110)
Browse files Browse the repository at this point in the history
* Update configuration with lower values

* Update spec_helper, disabling WebMock net connections

* Clean up and organize spec files
  • Loading branch information
jgarber623 authored and Ben Roberts committed Aug 15, 2019
1 parent 8d788c7 commit ff279fa
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 205 deletions.
7 changes: 2 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ Metrics/BlockLength:
Metrics/LineLength:
Enabled: false

RSpec/ExampleLength:
Max: 15

RSpec/MultipleExpectations:
Max: 10
Max: 5

RSpec/NestedGroups:
Max: 6
Max: 4

Style/Documentation:
Enabled: false
Expand Down
59 changes: 59 additions & 0 deletions spec/lib/microformats/absolute_uri_absolutize_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
describe Microformats::AbsoluteUri, '#absolutize' do
subject { described_class.new(relative, base: base).absolutize }

context 'when relative is nil' do
let(:relative) { nil }
let(:base) { 'http://example.com' }

it { is_expected.to eq(base) }
end

context 'when relative is an empty string' do
let(:relative) { '' }
let(:base) { 'http://example.com' }

it { is_expected.to eq(base) }
end

context 'when relative is a valid absolute URI' do
let(:base) { nil }
let(:relative) { 'http://google.com' }

it { is_expected.to eq('http://google.com') }
end

context 'when relative is a valid non-absolute URI' do
let(:relative) { 'bar/qux' }

context 'when base is present but not absolute' do
let(:base) { 'foo' }

it { is_expected.to eq('bar/qux') }
end

context 'when base is present and absolute' do
let(:base) { 'http://google.com' }

it { is_expected.to eq('http://google.com/bar/qux') }
end

context 'when base is not present' do
let(:base) { nil }

it { is_expected.to eq('bar/qux') }
end

context 'when base has a subdir' do
let(:base) { 'http://google.com/asdf.html' }

it { is_expected.to eq('http://google.com/bar/qux') }
end
end

context 'when relative is an invalid URI' do
let(:base) { nil }
let(:relative) { 'git@github.com:indieweb/microformats-ruby.git' }

it { is_expected.to eq(relative) }
end
end
61 changes: 0 additions & 61 deletions spec/lib/microformats/absolute_uri_spec.rb

This file was deleted.

28 changes: 15 additions & 13 deletions spec/lib/microformats/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,51 @@

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

it 'is accessible as a hash []' do
expect(Microformats.parse(html)['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles')
expect(collection['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles')
end

it 'can convert to hash' do
expect(Microformats.parse(html).to_hash['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles')
expect(collection.to_hash['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles')
end

it 'can convert to hash by to_h' do
expect(Microformats.parse(html).to_h['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles')
expect(collection.to_h['items'][0]['properties']['name'][0]).to eq('Jessica Lynn Suttles')
end

it 'converts to string' do
expect(Microformats.parse(html).to_s).to eq('{"items"=>[{"type"=>["h-card"], "properties"=>{"name"=>["Jessica Lynn Suttles"]}}], "rels"=>{}, "rel-urls"=>{}}')
expect(collection.to_s).to eq('{"items"=>[{"type"=>["h-card"], "properties"=>{"name"=>["Jessica Lynn Suttles"]}}], "rels"=>{}, "rel-urls"=>{}}')
end
end

describe 'collection functions' do
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>' }
let(:collection) { parser.parse(html) }

it 'is has rels function' do
expect(Microformats.parse(html).rels['canonical'][0]).to eq('https://example.com/')
expect(collection.rels['canonical'][0]).to eq('https://example.com/')
end

it 'is has rel_urls function' do
expect(Microformats.parse(html).rel_urls['https://example.com/']['rels'][0]).to eq('canonical')
expect(collection.rel_urls['https://example.com/']['rels'][0]).to eq('canonical')
end

it 'has respond_to? function' do
expect(Microformats.parse(html)).to respond_to(:respond_to?)
expect(collection).to respond_to(:respond_to?)
end

it 'supports old parser function calls by h- name' do
expect(Microformats.parse(html).card.to_hash).to eq(Microformats.parse(html).items[0].to_hash)
expect(Microformats.parse(html).card(:all)[0].to_hash).to eq(Microformats.parse(html).items[0].to_hash)
expect(Microformats.parse(html).card(0).to_hash).to eq(Microformats.parse(html).items[0].to_hash)
expect(Microformats.parse(html).card(3).to_hash).to eq(Microformats.parse(html).items[0].to_hash)
expect(Microformats.parse(html).as_sample.to_hash).to eq(Microformats.parse(html).items[1].to_hash)
expect(collection.card.to_hash).to eq(collection.items[0].to_hash)
expect(collection.card(:all)[0].to_hash).to eq(collection.items[0].to_hash)
expect(collection.card(0).to_hash).to eq(collection.items[0].to_hash)
expect(collection.card(3).to_hash).to eq(collection.items[0].to_hash)
expect(collection.as_sample.to_hash).to eq(collection.items[1].to_hash)
end

it 'has an items function that returns an array of ParserResult objects' do
expect(Microformats.parse(html).items[0]).to be_kind_of(Microformats::ParserResult)
expect(collection.items[0]).to be_kind_of(Microformats::ParserResult)
end
end
end
6 changes: 3 additions & 3 deletions spec/lib/microformats/parser_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

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

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

it 'has respond_to? function' do
expect(item).to respond_to(:respond_to?)
end

it 'returns PropertySets' do
expect(item.properties).to be_kind_of Microformats::PropertySet
expect(item.properties).to be_kind_of(Microformats::PropertySet)
end

it 'supports old parser function calls by property name' do
Expand Down
Loading

0 comments on commit ff279fa

Please sign in to comment.