open_graph_reader 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe "invalid examples" do
4
- %w(plain error).each do |example|
5
- describe example do
6
- it "says there are no tags" do
7
- expect {
8
- OpenGraphReader.parse! example_html 'plain'
9
- }.to raise_error OpenGraphReader::NoOpenGraphDataError, /OpenGraph tags/
10
- end
4
+ describe "plain" do
5
+ it "says there are no tags" do
6
+ expect {
7
+ OpenGraphReader.parse! example_html 'plain'
8
+ }.to raise_error OpenGraphReader::NoOpenGraphDataError, /OpenGraph tags/
9
+ end
10
+
11
+ it "says there are no tags with title synthesization turend on" do
12
+ OpenGraphReader.config.synthesize_title = true
13
+
14
+ expect {
15
+ OpenGraphReader.parse! example_html 'plain'
16
+ }.to raise_error OpenGraphReader::NoOpenGraphDataError, /OpenGraph tags/
11
17
  end
12
18
  end
13
19
 
14
- # Most parsers synthesize missing required properties, however
15
- # we do not (yet), making this example an invalid object
16
20
  describe "min" do
17
21
  it "has missing required properties" do
18
22
  expect {
@@ -79,7 +79,7 @@ RSpec.describe "real world examples" do
79
79
  end
80
80
 
81
81
  describe "undefined_property" do
82
- it "parses" do
82
+ it "parses (1)" do
83
83
  object = OpenGraphReader.parse! fixture_html 'real_world/undefined_property'
84
84
 
85
85
  expect(object.og.locale.to_s).to eq "es_ES"
@@ -91,13 +91,33 @@ RSpec.describe "real world examples" do
91
91
  expect(object.og.image.url).to eq "http://regeneracion.mx/wp-content/uploads/2014/12/Infiltrados.jpg"
92
92
  end
93
93
 
94
- it "does not parse in strict mode" do
94
+ it "does not parse in strict mode (1)" do
95
95
  OpenGraphReader.config.strict = true
96
96
 
97
97
  expect {
98
98
  OpenGraphReader.parse! fixture_html 'real_world/undefined_property'
99
99
  }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined property/
100
100
  end
101
+
102
+ it "parses (2)" do
103
+ object = OpenGraphReader.parse! fixture_html 'real_world/undefined_property_2'
104
+
105
+
106
+ expect(object.og.title).to eq "Emergency call system for all new cars by 2018"
107
+ expect(object.og.type).to eq "article"
108
+ expect(object.og.description).to eq "The European Parliament and EU member states have agreed that new cars must be fitted with an automated system to alert emergency services in event of a crash."
109
+ expect(object.og.site_name).to eq "BBC News"
110
+ expect(object.og.url).to eq "http://www.bbc.co.uk/news/technology-30337272"
111
+ expect(object.og.image.url).to eq "http://news.bbcimg.co.uk/media/images/79520000/jpg/_79520623_79519885.jpg"
112
+ end
113
+
114
+ it "does not parse in strict mode (2)" do
115
+ OpenGraphReader.config.strict = true
116
+
117
+ expect {
118
+ OpenGraphReader.parse! fixture_html 'real_world/undefined_property_2'
119
+ }.to raise_error OpenGraphReader::InvalidObjectError, /Undefined property/
120
+ end
101
121
  end
102
122
 
103
123
  describe "unknown_namespace" do
@@ -118,4 +138,42 @@ RSpec.describe "real world examples" do
118
138
  }.to raise_error OpenGraphReader::InvalidObjectError, /is not a registered namespace/
119
139
  end
120
140
  end
141
+
142
+
143
+ describe "missing_title" do
144
+ it "does not parse" do
145
+ expect {
146
+ OpenGraphReader.parse! fixture_html 'real_world/missing_title'
147
+ }.to raise_error OpenGraphReader::InvalidObjectError, /Missing required/
148
+ end
149
+
150
+ it "does parse when synthesizing titles" do
151
+ OpenGraphReader.config.synthesize_title = true
152
+
153
+ object = OpenGraphReader.parse! fixture_html 'real_world/missing_title'
154
+
155
+ expect(object.og.type).to eq "website"
156
+ expect(object.og.title).to eq "Ultra Conservative Christian Lady Goes To Museum, Tries To Debunk Evolution, Fails Beyond Miserably | Geekologie"
157
+ expect(object.og.image.url).to eq "http://geekologie.com/assets_c/2014/11/crazy-lady-goes-to-the-museum-thumb-640x389-29314.jpg"
158
+ end
159
+ end
160
+
161
+ describe "image_path" do
162
+ it "does not parse" do
163
+ expect {
164
+ OpenGraphReader.parse! fixture_html 'real_world/image_path'
165
+ }.to raise_error OpenGraphReader::InvalidObjectError, /does not start with/
166
+ end
167
+
168
+ it "parses with image paths turned on" do
169
+ OpenGraphReader.config.synthesize_image_url = true
170
+
171
+ object = OpenGraphReader.parse! fixture_html('real_world/image_path'), 'http://fritzing.org/download/'
172
+
173
+ expect(object.og.title).to eq "Fritzing"
174
+ expect(object.og.type).to eq "website"
175
+ expect(object.og.image.url).to eq "http://fritzing.org/static/img/fritzing.png"
176
+ expect(object.og.url).to eq "http://fritzing.org/"
177
+ end
178
+ end
121
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_graph_reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonne Haß
@@ -165,11 +165,14 @@ files:
165
165
  - spec/fixtures/examples/video-array.html
166
166
  - spec/fixtures/examples/video-movie.html
167
167
  - spec/fixtures/examples/video.html
168
+ - spec/fixtures/real_world/image_path.html
168
169
  - spec/fixtures/real_world/missing_image.html
170
+ - spec/fixtures/real_world/missing_title.html
169
171
  - spec/fixtures/real_world/mixed_case_properties.html
170
172
  - spec/fixtures/real_world/mixed_case_type.html
171
173
  - spec/fixtures/real_world/not_a_reference.html
172
174
  - spec/fixtures/real_world/undefined_property.html
175
+ - spec/fixtures/real_world/undefined_property_2.html
173
176
  - spec/fixtures/real_world/unknown_namespace.html
174
177
  - spec/fixtures/real_world/unknown_type.html
175
178
  - spec/integration/invalid_examples_spec.rb
@@ -249,11 +252,14 @@ test_files:
249
252
  - spec/fixtures/examples/video-array.html
250
253
  - spec/fixtures/examples/video-movie.html
251
254
  - spec/fixtures/examples/video.html
255
+ - spec/fixtures/real_world/image_path.html
252
256
  - spec/fixtures/real_world/missing_image.html
257
+ - spec/fixtures/real_world/missing_title.html
253
258
  - spec/fixtures/real_world/mixed_case_properties.html
254
259
  - spec/fixtures/real_world/mixed_case_type.html
255
260
  - spec/fixtures/real_world/not_a_reference.html
256
261
  - spec/fixtures/real_world/undefined_property.html
262
+ - spec/fixtures/real_world/undefined_property_2.html
257
263
  - spec/fixtures/real_world/unknown_namespace.html
258
264
  - spec/fixtures/real_world/unknown_type.html
259
265
  - spec/integration/invalid_examples_spec.rb