File: valid_examples_spec.rb

package info (click to toggle)
ruby-open-graph-reader 0.7.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 9,976 kB
  • sloc: ruby: 1,525; xml: 22; makefile: 2
file content (76 lines) | stat: -rw-r--r-- 2,217 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require "spec_helper"

RSpec.describe "valid examples" do
  %w(
    article-offset
    article-utc
    audio-array
    audio-url
    audio
    book-isbn10
    book
    canadian
    image-array
    image-toosmall
    image-url
    image
    index
    nomedia
    profile
    required
    video-array
    video-movie
    video
  ).each do |example|
    describe example do
      it "parses" do
        expect {
          OpenGraphReader.parse! example_html example
        }.to_not raise_error
      end
    end
  end

  describe "article" do
    let(:object) { OpenGraphReader.parse! example_html "article" }

    it "parses" do
      expect {
        object
      }.to_not raise_error
    end

    it "allows access to the first tag" do
      expect(object.article.tag).to eq "Watergate"
    end

    it "assigns correctly" do
      expect(object.og.title).to eq "5 Held in Plot to Bug Office"
      expect(object.og.site_name).to eq "Open Graph protocol examples"
      expect(object.og.type).to eq "article"
      expect(object.og.locale.to_s).to eq "en_US"
      expect(object.og.url).to eq "http://examples.opengraphprotocol.us/article.html"
      expect(object.og.image.content).to eq "http://examples.opengraphprotocol.us/media/images/50.png"
      expect(object.og.image.url).to eq "https://d72cgtgi6hvvl.cloudfront.net/media/images/50.png"
      expect(object.og.image.secure_url).to eq "https://d72cgtgi6hvvl.cloudfront.net/media/images/50.png"
      expect(object.og.image.width).to eq 50
      expect(object.og.image.height).to eq 50
      expect(object.og.image.type).to eq "image/png"
      expect(object.article.published_time).to eq DateTime.new(1972, 6, 18)
      expect(object.article.author.content).to eq "http://examples.opengraphprotocol.us/profile.html"
      expect(object.article.section).to eq "Front page"
      expect(object.article.tag).to eq "Watergate"
      expect(object.article.tags).to eq ["Watergate"]
    end
  end

  # Examples say this is invalid, but http://ogp.me defines isbn it as string,
  # so anything goes
  describe "errors/book" do
    it "parses" do
      expect {
        OpenGraphReader.parse! example_html "errors/book"
      }.to_not raise_error
    end
  end
end