File: invalid_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 (112 lines) | stat: -rw-r--r-- 3,828 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require "spec_helper"

RSpec.describe "invalid examples" do
  describe "plain" do
    it "says there are no tags" do
      expect {
        OpenGraphReader.parse! example_html "plain"
      }.to raise_error OpenGraphReader::NoOpenGraphDataError, /OpenGraph tags/
    end

    it "says there are no tags with title synthesization turend on" do
      OpenGraphReader.config.synthesize_title = true

      expect {
        OpenGraphReader.parse! example_html "plain"
      }.to raise_error OpenGraphReader::NoOpenGraphDataError, /OpenGraph tags/
    end
  end

  describe "min" do
    it "has missing required properties" do
      expect {
        OpenGraphReader.parse! example_html "min"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Missing required/
    end

    it "returns what's there if required property validation is disabled" do
      OpenGraphReader.config.validate_required = false
      object = OpenGraphReader.parse! example_html "min"
      expect(object.og.site_name).to eq "Open Graph protocol examples"
      expect(object.og.description).to eq "Content not on page"
    end
  end

  describe "filters/xss-image" do
    it "errors on the invaid URL in strict mode" do
      expect {
        OpenGraphReader.parse! example_html "filters/xss-image"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with http/
    end
  end

  describe "errors/article-date" do
    it "has an incorrectly formatted date" do
      expect {
        OpenGraphReader.parse! example_html "errors/article-date"
      }.to raise_error OpenGraphReader::InvalidObjectError, /ISO8601 datetime expected/
    end
  end

  describe "errors/book-author" do
    it "doesn't have a profile object as author" do
      expect {
        OpenGraphReader.parse! example_html "errors/book-author"
      }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with http/
    end
  end

  describe "errors/gender" do
    it "doesn't have a valid gender" do
      expect {
        OpenGraphReader.parse! example_html "errors/gender"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Expected one of/
    end
  end

  describe "errors/geo" do
    it "doesn't recognize the old elements in strict mode" do
      OpenGraphReader.config.strict = true

      expect {
        OpenGraphReader.parse! example_html "errors/geo"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined property/
    end

    it "parses in default mode" do
      object = OpenGraphReader.parse! example_html "errors/geo"

      expect(object.og.type).to eq "website"
      expect(object.og.title).to eq "Open Graph protocol 1.0 location data"
      expect(object.og.url).to eq "http://examples.opengraphprotocol.us/errors/geo.html"
      expect(object.og.image.url).to eq "http://examples.opengraphprotocol.us/media/images/50.png"
    end
  end

  describe "errors/type" do
    it "doesn't handle the unknown type in strict mode" do
      OpenGraphReader.config.strict = true

      expect {
        OpenGraphReader.parse! example_html "errors/type"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined type/
    end

    it "parses the known properties" do
      object = OpenGraphReader.parse! example_html "errors/type"

      expect(object.og.type).to eq "fubar"
      expect(object.og.title).to eq "Undefined global type"
      expect(object.og.url).to eq "http://examples.opengraphprotocol.us/errors/type.html"
      expect(object.og.image.url).to eq "http://examples.opengraphprotocol.us/media/images/50.png"
    end
  end

  describe "errors/video-duration" do
    it "only accepts integers" do
      expect {
        OpenGraphReader.parse! example_html "errors/video-duration"
      }.to raise_error OpenGraphReader::InvalidObjectError, /Integer expected/
    end
  end
end