~srushe/indieweb-authorship

3d7ec243d188ff1355af506726a02e648191bfca — Stephen Rushe 2 years ago 620544e
Add tests
A .rspec => .rspec +3 -0
@@ 0,0 1,3 @@
--format documentation
--color
--require spec_helper

A spec/examples/about => spec/examples/about +23 -0
@@ 0,0 1,23 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Author</title>
</head>
<body>

  <div class="h-card">
    <a href="/about" class="u-url">
      <img src="/photo.jpg" class="u-photo">
      <span class="p-name">Author Full Name</span>
      <!-- includes a different name here than is used in the files that link here, in order to ensure they are not fetching this page -->
    </a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/about-no-url => spec/examples/about-no-url +22 -0
@@ 0,0 1,22 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Author</title>
</head>
<body>

  <div class="h-card">
    <h2 class="p-name">Author Full Name</h2>
    <a href="xmpp://user@host.example" class="u-url" rel="me">xmpp</a>
    <img src="/photo.jpg" class="u-photo">
  </div>
  <!-- this page has no u-url or rel=me pointing to itself but there is only one h-card -->
  
</body>
</html>
\ No newline at end of file

A spec/examples/about-rel-me => spec/examples/about-rel-me +23 -0
@@ 0,0 1,23 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Author</title>
  <link rel="me" href="/about-rel-me">
</head>
<body>

  <div class="h-card">
    <a href="/about-rel-me" class="u-url">
      <img src="/photo.jpg" class="u-photo">
      <span class="p-name">Author Full Name</span>
    </a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/about-url-uid => spec/examples/about-url-uid +22 -0
@@ 0,0 1,22 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Author</title>
</head>
<body>

  <div class="h-card">
    <a href="/about-url-uid" class="u-url u-uid">
      <img src="/photo.jpg" class="u-photo">
      <span class="p-name">Author Full Name</span>
    </a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/about-with-multiple-urls => spec/examples/about-with-multiple-urls +22 -0
@@ 0,0 1,22 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Author</title>
</head>
<body>

  <div class="h-card">
    <h2 class="p-name">Author Full Name</h2>
    <a href="xmpp://user@host.example" class="u-url" rel="me">xmpp</a>
    <a href="/about-with-multiple-urls" class="u-url" rel="me">Me</a>
    <img src="/photo.jpg" class="u-photo">
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/author-name-is-0 => spec/examples/author-name-is-0 +22 -0
@@ 0,0 1,22 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Author</title>
</head>
<body>

  <div class="h-card">
    <a href="/author-name-is-0" class="u-url">
      <img src="/photo.jpg" class="u-photo">
      <span class="p-name">0</span>
    </a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-name => spec/examples/h-entry-author-is-name +20 -0
@@ 0,0 1,20 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <div class="p-author">Author Name</div>
    <p class="p-name e-content">Hello World</p>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-rel-link-to-h-card-on-page => spec/examples/h-entry-author-is-rel-link-to-h-card-on-page +28 -0
@@ 0,0 1,28 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <p class="p-name e-content">Hello World</p>
  </div>

  <div class="h-card">
    <a href="/about" class="u-url">
      <img src="/photo.jpg" class="u-photo">
      <span class="p-name">Author</span>
    </a>
  </div>

  <a href="/about" rel="author">Author</a>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-rel-link-to-h-card-with-rel-me => spec/examples/h-entry-author-is-rel-link-to-h-card-with-rel-me +21 -0
@@ 0,0 1,21 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <p class="p-name e-content">Hello World</p>
  </div>

  <a href="/about-rel-me" rel="author">Author</a>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-rel-link-to-h-card-with-url-uid => spec/examples/h-entry-author-is-rel-link-to-h-card-with-url-uid +21 -0
@@ 0,0 1,21 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <p class="p-name e-content">Hello World</p>
  </div>

  <a href="/about-url-uid" rel="author">Author</a>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-url-to-h-card-on-page => spec/examples/h-entry-author-is-url-to-h-card-on-page +28 -0
@@ 0,0 1,28 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <p class="p-name e-content">Hello World</p>
    <a href="/about" class="u-author">Author</a>
    <a href="/h-entry-author-is-url-to-h-card-on-page" class="u-url">permalink</a>
  </div>

  <div class="h-card">
    <a href="/about" class="u-url">
      <img src="/photo.jpg" class="u-photo">
      <span class="p-name">Author</span>
    </a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-url-to-h-card-with-multiple-links => spec/examples/h-entry-author-is-url-to-h-card-with-multiple-links +21 -0
@@ 0,0 1,21 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <a href="/about-with-multiple-urls" class="u-author">Author</a>
    <p class="p-name e-content">Hello World</p>
    <a href="/h-entry-author-is-url-to-h-card-with-multiple-links" class="u-url">permalink</a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-author-is-url-to-h-card-with-no-url => spec/examples/h-entry-author-is-url-to-h-card-with-no-url +21 -0
@@ 0,0 1,21 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">
    <a href="/about-no-url" class="u-author">Author</a>
    <p class="p-name e-content">Hello World</p>
    <a href="/h-entry-author-is-url-to-h-card-with-no-url" class="u-url">permalink</a>
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-has-h-card-and-url-author => spec/examples/h-entry-has-h-card-and-url-author +31 -0
@@ 0,0 1,31 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">

    <a href="/about" class="u-author">Author</a>
    
    <div class="p-author h-card">
      <a href="/about" class="u-url">
        <img src="/photo.jpg" class="u-photo">
        <span class="p-name">Author</span>
      </a>
    </div>

    <p class="p-name e-content">Hello World</p>

    <a href="/h-entry-has-h-card-and-url-author" class="u-url">permalink</a>    
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-entry-has-h-card-author => spec/examples/h-entry-has-h-card-author +28 -0
@@ 0,0 1,28 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">

    <div class="p-author h-card">
      <a href="/about" class="u-url">
        <img src="/photo.jpg" class="u-photo">
        <span class="p-name">Author</span>
      </a>
    </div>

    <p class="p-name e-content">Hello World</p>
    
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-feed-has-h-card-author => spec/examples/h-feed-has-h-card-author +30 -0
@@ 0,0 1,30 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-feed">

    <div class="p-author h-card">
      <a href="/about" class="u-url">
        <img src="/photo.jpg" class="u-photo">
        <span class="p-name">Author</span>
      </a>
    </div>

    <div class="h-entry">
      <p class="p-name e-content">Hello World</p>
    </div>
    
  </div>

</body>
</html>
\ No newline at end of file

A spec/examples/h-feed-has-multiple-entries-with-different-authors => spec/examples/h-feed-has-multiple-entries-with-different-authors +23 -0
@@ 0,0 1,23 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-feed">

    <div class="h-entry">
      <p class="p-name e-content">Hello World</p>
    </div>
    
  </div>

</body>
</html>
\ No newline at end of file

A spec/h-entry-author-is-name_spec.rb => spec/h-entry-author-is-name_spec.rb +24 -0
@@ 0,0 1,24 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-name' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:expected_data) do
    {
      'url' => nil,
      'name' => 'Author Name',
      'photo' => nil
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-author-is-rel-link-to-h-card-on-page_spec.rb => spec/h-entry-author-is-rel-link-to-h-card-on-page_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-rel-link-to-h-card-on-page' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { URI('http://author.example.com/about') }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about',
      'name' => 'Author',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-author-is-rel-link-to-h-card-with-rel-me_spec.rb => spec/h-entry-author-is-rel-link-to-h-card-with-rel-me_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-rel-link-to-h-card-with-rel-me' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { URI('http://author.example.com/about-rel-me') }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about-rel-me',
      'name' => 'Author Full Name',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about-rel-me') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-author-is-rel-link-to-h-card-with-url-uid_spec.rb => spec/h-entry-author-is-rel-link-to-h-card-with-url-uid_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-rel-link-to-h-card-with-url-uid' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { URI('http://author.example.com/about-url-uid') }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about-url-uid',
      'name' => 'Author Full Name',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about-url-uid') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-author-is-url-to-h-card-on-page_spec.rb => spec/h-entry-author-is-url-to-h-card-on-page_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-url-to-h-card-on-page' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { URI('http://author.example.com/about') }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about',
      'name' => 'Author',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-author-is-url-to-h-card-with-multiple-links_spec.rb => spec/h-entry-author-is-url-to-h-card-with-multiple-links_spec.rb +27 -0
@@ 0,0 1,27 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-url-to-h-card-with-multiple-links' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { URI('http://author.example.com/about-with-multiple-urls') }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about-with-multiple-urls',
      'name' => 'Author Full Name',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about-rel-me') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end

end

A spec/h-entry-author-is-url-to-h-card-with-no-url_spec.rb => spec/h-entry-author-is-url-to-h-card-with-no-url_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-author-is-url-to-h-card-with-no-url' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { URI('http://author.example.com/about-no-url') }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about-no-url',
      'name' => 'Author Full Name',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about-no-url') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-has-h-card-and-url-author_spec.rb => spec/h-entry-has-h-card-and-url-author_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-has-h-card-and-url-author' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { 'http://author.example.com/about' }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about',
      'name' => 'Author',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-entry-has-h-card-author_spec.rb => spec/h-entry-has-h-card-author_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-has-h-card-author' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { 'http://author.example.com/about' }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about',
      'name' => 'Author',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/h-feed-has-h-card-author_spec.rb => spec/h-feed-has-h-card-author_spec.rb +25 -0
@@ 0,0 1,25 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-feed-has-h-card-author' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { 'http://author.example.com/about' }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about',
      'name' => 'Author',
      'photo' => 'http://author.example.com/photo.jpg'
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end

A spec/indieweb/authorship_spec.rb => spec/indieweb/authorship_spec.rb +5 -0
@@ 0,0 1,5 @@
RSpec.describe Indieweb::Authorship do
  it "has a version number" do
    expect(Indieweb::Authorship::VERSION).not_to be nil
  end
end

A spec/spec_helper.rb => spec/spec_helper.rb +20 -0
@@ 0,0 1,20 @@
require "bundler/setup"
require "indieweb/authorship"

Dir[
  File.join(__dir__, 'support/*rb')
].each { |file| require file }

RSpec.configure do |config|
  # Enable flags like --only-failures and --next-failure
  config.example_status_persistence_file_path = ".rspec_status"

  # Disable RSpec exposing methods globally on `Module` and `main`
  config.disable_monkey_patching!

  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

  config.include HtmlFor
end

A spec/support/html_for.rb => spec/support/html_for.rb +6 -0
@@ 0,0 1,6 @@
module HtmlFor
  def html_for(filename)
    file = File.join(File.dirname(__FILE__), '../examples', filename)
    File.read(file).sub(/.*?(<!DOCTYPE html>.*)/m, '\1')
  end
end