ruby-oembed 0.8.11 → 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.rdoc +7 -0
- data/lib/oembed/provider.rb +6 -1
- data/lib/oembed/providers/embedly_urls.yml +255 -136
- data/lib/oembed/providers.rb +20 -1
- data/lib/oembed/version.rb +1 -1
- data/spec/formatter/ducktype_backend_spec.rb +31 -31
- data/spec/formatter/json/jsongem_backend_spec.rb +29 -28
- data/spec/formatter/json/yaml_backend_spec.rb +27 -26
- data/spec/formatter/xml/nokogiri_backend_spec.rb +28 -27
- data/spec/formatter/xml/rexml_backend_spec.rb +26 -25
- data/spec/formatter/xml/xmlsimple_backend_spec.rb +28 -27
- data/spec/formatter_spec.rb +11 -9
- data/spec/provider_discovery_spec.rb +37 -37
- metadata +2 -2
data/lib/oembed/providers.rb
CHANGED
@@ -136,7 +136,7 @@ module OEmbed
|
|
136
136
|
# OEmbed::Providers::Youtube.endpoint += "?iframe=0"
|
137
137
|
# * To require https embed code
|
138
138
|
# OEmbed::Providers::Youtube.endpoint += "?scheme=https"
|
139
|
-
Youtube = OEmbed::Provider.new("http://www.youtube.com/oembed")
|
139
|
+
Youtube = OEmbed::Provider.new("http://www.youtube.com/oembed?scheme=https")
|
140
140
|
Youtube << "http://*.youtube.com/*"
|
141
141
|
Youtube << "https://*.youtube.com/*"
|
142
142
|
Youtube << "http://*.youtu.be/*"
|
@@ -179,6 +179,19 @@ module OEmbed
|
|
179
179
|
Vimeo << "https://*.vimeo.com/*"
|
180
180
|
add_official_provider(Vimeo)
|
181
181
|
|
182
|
+
# Provider for twitter.com
|
183
|
+
# https://dev.twitter.com/rest/reference/get/statuses/oembed
|
184
|
+
Twitter = OEmbed::Provider.new("https://api.twitter.com/1/statuses/oembed.{format}")
|
185
|
+
Twitter << "https://*.twitter.com/*/status/*"
|
186
|
+
add_official_provider(Twitter)
|
187
|
+
|
188
|
+
# Provider for vine.co
|
189
|
+
# https://dev.twitter.com/web/vine/oembed
|
190
|
+
Vine = OEmbed::Provider.new("https://vine.co/oembed.{format}")
|
191
|
+
Vine << "http://*.vine.co/v/*"
|
192
|
+
Vine << "https://*.vine.co/v/*"
|
193
|
+
add_official_provider(Vine)
|
194
|
+
|
182
195
|
# Provider for instagram.com
|
183
196
|
# http://instagr.am/developer/embedding/
|
184
197
|
Instagram = OEmbed::Provider.new("http://api.instagram.com/oembed", :json)
|
@@ -199,6 +212,12 @@ module OEmbed
|
|
199
212
|
Yfrog << "http://yfrog.com/*"
|
200
213
|
add_official_provider(Yfrog)
|
201
214
|
|
215
|
+
# Provider for imgur.com
|
216
|
+
Imgur = OEmbed::Provider.new("https://api.imgur.com/oembed.{format}")
|
217
|
+
Imgur << "https://*.imgur.com/gallery/*"
|
218
|
+
Imgur << "http://*.imgur.com/gallery/*"
|
219
|
+
add_official_provider(Imgur)
|
220
|
+
|
202
221
|
# provider for mlg-tv
|
203
222
|
# http://tv.majorleaguegaming.com/oembed
|
204
223
|
MlgTv = OEmbed::Provider.new("http://tv.majorleaguegaming.com/oembed")
|
data/lib/oembed/version.rb
CHANGED
@@ -9,7 +9,7 @@ class WorkingDuck
|
|
9
9
|
end
|
10
10
|
def parse_error; RuntimeError; end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# A WorkingDuck instance should work as a Backend
|
14
14
|
def decode(value)
|
15
15
|
self.class.decode(value)
|
@@ -29,33 +29,33 @@ describe "OEmbed::Formatter::JSON::Backends::DuckType" do
|
|
29
29
|
include OEmbedSpecHelper
|
30
30
|
|
31
31
|
it "should work with WorkingDuck Class" do
|
32
|
-
|
32
|
+
expect {
|
33
33
|
OEmbed::Formatter::JSON.backend = WorkingDuck
|
34
|
-
}.
|
35
|
-
OEmbed::Formatter::JSON.backend.
|
34
|
+
}.not_to raise_error
|
35
|
+
expect(OEmbed::Formatter::JSON.backend).to be WorkingDuck
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should work with a WorkingDuck instance" do
|
39
39
|
instance = WorkingDuck.new
|
40
|
-
|
40
|
+
expect {
|
41
41
|
OEmbed::Formatter::JSON.backend = instance
|
42
|
-
}.
|
43
|
-
OEmbed::Formatter::JSON.backend.
|
42
|
+
}.to_not raise_error
|
43
|
+
expect(OEmbed::Formatter::JSON.backend).to be instance
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should fail with FailingDuckDecode Class" do
|
47
|
-
|
47
|
+
expect {
|
48
48
|
OEmbed::Formatter::JSON.backend = FailingDuckDecode
|
49
|
-
}.
|
50
|
-
OEmbed::Formatter::JSON.backend.
|
49
|
+
}.to raise_error(LoadError)
|
50
|
+
expect(OEmbed::Formatter::JSON.backend).to_not be(FailingDuckDecode)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should fail with a FailingDuckDecode instance" do
|
54
54
|
instance = FailingDuckDecode.new
|
55
|
-
|
55
|
+
expect {
|
56
56
|
OEmbed::Formatter::JSON.backend = instance
|
57
|
-
}.
|
58
|
-
OEmbed::Formatter::JSON.backend.
|
57
|
+
}.to raise_error(LoadError)
|
58
|
+
expect(OEmbed::Formatter::JSON.backend).to_not be(instance)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -63,32 +63,32 @@ describe "OEmbed::Formatter::XML::Backends::DuckType" do
|
|
63
63
|
include OEmbedSpecHelper
|
64
64
|
|
65
65
|
it "should work with WorkingDuck Class" do
|
66
|
-
|
66
|
+
expect {
|
67
67
|
OEmbed::Formatter::XML.backend = WorkingDuck
|
68
|
-
}.
|
69
|
-
OEmbed::Formatter::XML.backend.
|
68
|
+
}.to_not raise_error
|
69
|
+
expect(OEmbed::Formatter::XML.backend).to be(WorkingDuck)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "should work with a WorkingDuck instance" do
|
73
73
|
instance = WorkingDuck.new
|
74
|
-
|
74
|
+
expect {
|
75
75
|
OEmbed::Formatter::XML.backend = instance
|
76
|
-
}.
|
77
|
-
OEmbed::Formatter::XML.backend.
|
76
|
+
}.to_not raise_error
|
77
|
+
expect(OEmbed::Formatter::XML.backend).to be(instance)
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it "should fail with FailingDuckDecode Class" do
|
81
|
-
|
81
|
+
expect {
|
82
82
|
OEmbed::Formatter::XML.backend = FailingDuckDecode
|
83
|
-
}.
|
84
|
-
OEmbed::Formatter::XML.backend.
|
83
|
+
}.to raise_error(LoadError)
|
84
|
+
expect(OEmbed::Formatter::XML.backend).to_not be(FailingDuckDecode)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it "should fail with a FailingDuckDecode instance" do
|
88
88
|
instance = FailingDuckDecode.new
|
89
|
-
|
89
|
+
expect {
|
90
90
|
OEmbed::Formatter::XML.backend = instance
|
91
|
-
}.
|
92
|
-
OEmbed::Formatter::XML.backend.
|
91
|
+
}.to raise_error(LoadError)
|
92
|
+
expect(OEmbed::Formatter::XML.backend).to_not be(instance)
|
93
93
|
end
|
94
94
|
end
|
@@ -4,55 +4,56 @@ describe "OEmbed::Formatter::JSON::Backends::JSONGem" do
|
|
4
4
|
include OEmbedSpecHelper
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
OEmbed::Formatter::JSON.backend = 'JSONGem'
|
9
|
-
}.
|
10
|
-
|
9
|
+
}.to raise_error(LoadError)
|
10
|
+
|
11
11
|
require 'json'
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
expect {
|
14
14
|
OEmbed::Formatter::JSON.backend = 'JSONGem'
|
15
|
-
}.
|
15
|
+
}.to_not raise_error
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should support JSON" do
|
19
|
-
|
20
|
-
|
19
|
+
expect {
|
20
|
+
OEmbed::Formatter.supported?(:json)
|
21
|
+
}.to_not raise_error
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
it "should be using the JSONGem backend" do
|
24
|
-
OEmbed::Formatter::JSON.backend.
|
25
|
+
expect(OEmbed::Formatter::JSON.backend).to eq(OEmbed::Formatter::JSON::Backends::JSONGem)
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
it "should decode a JSON String" do
|
28
29
|
decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
|
29
30
|
# We need to compare keys & values separately because we don't expect all
|
30
31
|
# non-string values to be recognized correctly.
|
31
|
-
decoded.keys.
|
32
|
-
decoded.values.map{|v|v.to_s}.
|
32
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
33
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
it "should raise an OEmbed::ParseError when decoding an invalid JSON String" do
|
36
|
-
|
37
|
+
expect {
|
37
38
|
decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_container', :json))
|
38
|
-
}.
|
39
|
-
|
39
|
+
}.to raise_error(OEmbed::ParseError)
|
40
|
+
expect {
|
40
41
|
decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_tag', :json))
|
41
|
-
}.
|
42
|
-
|
42
|
+
}.to raise_error(OEmbed::ParseError)
|
43
|
+
expect {
|
43
44
|
decode = OEmbed::Formatter.decode(:json, invalid_response('invalid_syntax', :json))
|
44
|
-
}.
|
45
|
+
}.to raise_error(OEmbed::ParseError)
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
|
48
49
|
error_to_raise = ArgumentError
|
49
|
-
OEmbed::Formatter::JSON.backend.parse_error.
|
50
|
-
|
51
|
-
::JSON.
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
expect(OEmbed::Formatter::JSON.backend.parse_error).to_not be_kind_of(error_to_raise)
|
51
|
+
|
52
|
+
expect(::JSON).to receive(:parse).
|
53
|
+
and_throw(error_to_raise.new("unknown error"))
|
54
|
+
|
55
|
+
expect {
|
55
56
|
decode = OEmbed::Formatter.decode(:json, valid_response(:json))
|
56
|
-
}.
|
57
|
+
}.to raise_error(OEmbed::ParseError)
|
57
58
|
end
|
58
59
|
end
|
@@ -4,51 +4,52 @@ describe "OEmbed::Formatter::JSON::Backends::Yaml" do
|
|
4
4
|
include OEmbedSpecHelper
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
OEmbed::Formatter::JSON.backend = 'Yaml'
|
9
|
-
}.
|
10
|
-
|
11
|
-
(!!defined?(YAML)).
|
9
|
+
}.to_not raise_error
|
10
|
+
|
11
|
+
expect(!!defined?(YAML)).to eq(true)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should support JSON" do
|
15
|
-
|
16
|
-
|
15
|
+
expect {
|
16
|
+
OEmbed::Formatter.supported?(:json)
|
17
|
+
}.to_not raise_error
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
it "should be using the Yaml backend" do
|
20
|
-
OEmbed::Formatter::JSON.backend.
|
21
|
+
expect(OEmbed::Formatter::JSON.backend).to eq(OEmbed::Formatter::JSON::Backends::Yaml)
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
it "should decode a JSON String" do
|
24
25
|
decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
|
25
26
|
# We need to compare keys & values separately because we don't expect all
|
26
27
|
# non-string values to be recognized correctly.
|
27
|
-
decoded.keys.
|
28
|
-
decoded.values.map{|v|v.to_s}.
|
28
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
29
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
it "should raise an OEmbed::ParseError when decoding an invalid JSON String" do
|
32
|
-
|
33
|
+
expect {
|
33
34
|
decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_container', :json))
|
34
|
-
}.
|
35
|
-
|
35
|
+
}.to raise_error(OEmbed::ParseError)
|
36
|
+
expect {
|
36
37
|
decode = OEmbed::Formatter.decode(:json, invalid_response('unclosed_tag', :json))
|
37
|
-
}.
|
38
|
-
|
38
|
+
}.to raise_error(OEmbed::ParseError)
|
39
|
+
expect {
|
39
40
|
decode = OEmbed::Formatter.decode(:json, invalid_response('invalid_syntax', :json))
|
40
|
-
}.
|
41
|
+
}.to raise_error(OEmbed::ParseError)
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
|
44
45
|
error_to_raise = ArgumentError
|
45
|
-
OEmbed::Formatter::JSON.backend.parse_error.
|
46
|
-
|
47
|
-
OEmbed::Formatter::JSON.backend.
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
expect(OEmbed::Formatter::JSON.backend.parse_error).to_not be_kind_of(error_to_raise)
|
47
|
+
|
48
|
+
expect(OEmbed::Formatter::JSON.backend).to receive(:convert_json_to_yaml).
|
49
|
+
and_throw(error_to_raise.new("unknown error"))
|
50
|
+
|
51
|
+
expect {
|
51
52
|
decode = OEmbed::Formatter.decode(:json, valid_response(:json))
|
52
|
-
}.
|
53
|
+
}.to raise_error(OEmbed::ParseError)
|
53
54
|
end
|
54
55
|
end
|
@@ -4,55 +4,56 @@ describe "OEmbed::Formatter::XML::Backends::Nokogiri" do
|
|
4
4
|
include OEmbedSpecHelper
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
OEmbed::Formatter::XML.backend = 'Nokogiri'
|
9
|
-
}.
|
10
|
-
|
9
|
+
}.to raise_error(LoadError)
|
10
|
+
|
11
11
|
require 'nokogiri'
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
expect {
|
14
14
|
OEmbed::Formatter::XML.backend = 'Nokogiri'
|
15
|
-
}.
|
15
|
+
}.to_not raise_error
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should support XML" do
|
19
|
-
|
20
|
-
|
19
|
+
expect {
|
20
|
+
OEmbed::Formatter.supported?(:xml)
|
21
|
+
}.to_not raise_error
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
it "should be using the Nokogiri backend" do
|
24
|
-
OEmbed::Formatter::XML.backend.
|
25
|
+
expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::Nokogiri)
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
it "should decode an XML String" do
|
28
29
|
decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
29
30
|
# We need to compare keys & values separately because we don't expect all
|
30
31
|
# non-string values to be recognized correctly.
|
31
|
-
decoded.keys.
|
32
|
-
decoded.values.map{|v|v.to_s}.
|
32
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
33
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
|
36
|
-
|
37
|
+
expect {
|
37
38
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
|
38
|
-
}.
|
39
|
-
|
39
|
+
}.to raise_error(OEmbed::ParseError)
|
40
|
+
expect {
|
40
41
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
|
41
|
-
}.
|
42
|
-
|
42
|
+
}.to raise_error(OEmbed::ParseError)
|
43
|
+
expect {
|
43
44
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
|
44
|
-
}.
|
45
|
+
}.to raise_error(OEmbed::ParseError)
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
|
48
49
|
error_to_raise = ArgumentError
|
49
|
-
OEmbed::Formatter::XML.backend.parse_error.
|
50
|
-
|
51
|
-
::Nokogiri::XML::Document.
|
50
|
+
expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
|
51
|
+
|
52
|
+
expect(::Nokogiri::XML::Document).to receive(:parse).
|
52
53
|
and_raise(error_to_raise.new("unknown error"))
|
53
|
-
|
54
|
-
|
54
|
+
|
55
|
+
expect {
|
55
56
|
decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
56
|
-
}.
|
57
|
+
}.to raise_error(OEmbed::ParseError)
|
57
58
|
end
|
58
59
|
end
|
@@ -4,51 +4,52 @@ describe "OEmbed::Formatter::XML::Backends::REXML" do
|
|
4
4
|
include OEmbedSpecHelper
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
OEmbed::Formatter::XML.backend = 'REXML'
|
9
|
-
}.
|
10
|
-
|
11
|
-
(!!defined?(REXML)).
|
9
|
+
}.to_not raise_error
|
10
|
+
|
11
|
+
expect((!!defined?(REXML))).to eq(true)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should support XML" do
|
15
|
-
|
16
|
-
|
15
|
+
expect {
|
16
|
+
OEmbed::Formatter.supported?(:xml)
|
17
|
+
}.to_not raise_error
|
17
18
|
end
|
18
|
-
|
19
|
+
|
19
20
|
it "should be using the XmlSimple backend" do
|
20
|
-
OEmbed::Formatter::XML.backend.
|
21
|
+
expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::REXML)
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
it "should decode an XML String" do
|
24
25
|
decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
25
26
|
# We need to compare keys & values separately because we don't expect all
|
26
27
|
# non-string values to be recognized correctly.
|
27
|
-
decoded.keys.
|
28
|
-
decoded.values.map{|v|v.to_s}.
|
28
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
29
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
29
30
|
end
|
30
|
-
|
31
|
+
|
31
32
|
it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
|
32
|
-
|
33
|
+
expect {
|
33
34
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
|
34
|
-
}.
|
35
|
-
|
35
|
+
}.to raise_error(OEmbed::ParseError)
|
36
|
+
expect {
|
36
37
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
|
37
|
-
}.
|
38
|
-
|
38
|
+
}.to raise_error(OEmbed::ParseError)
|
39
|
+
expect {
|
39
40
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
|
40
|
-
}.
|
41
|
+
}.to raise_error(OEmbed::ParseError)
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
|
44
45
|
error_to_raise = ArgumentError
|
45
|
-
OEmbed::Formatter::XML.backend.parse_error.
|
46
|
-
|
47
|
-
::REXML::Document.
|
46
|
+
expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
|
47
|
+
|
48
|
+
expect(::REXML::Document).to receive(:new).
|
48
49
|
and_raise(error_to_raise.new("unknown error"))
|
49
|
-
|
50
|
-
|
50
|
+
|
51
|
+
expect {
|
51
52
|
decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
52
|
-
}.
|
53
|
+
}.to raise_error(OEmbed::ParseError)
|
53
54
|
end
|
54
55
|
end
|
@@ -4,55 +4,56 @@ describe "OEmbed::Formatter::XML::Backends::XmlSimple" do
|
|
4
4
|
include OEmbedSpecHelper
|
5
5
|
|
6
6
|
before(:all) do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
OEmbed::Formatter::XML.backend = 'XmlSimple'
|
9
|
-
}.
|
10
|
-
|
9
|
+
}.to raise_error(LoadError)
|
10
|
+
|
11
11
|
require 'xmlsimple'
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
expect {
|
14
14
|
OEmbed::Formatter::XML.backend = 'XmlSimple'
|
15
|
-
}.
|
15
|
+
}.to_not raise_error
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should support XML" do
|
19
|
-
|
20
|
-
|
19
|
+
expect {
|
20
|
+
OEmbed::Formatter.supported?(:xml)
|
21
|
+
}.to_not raise_error
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
it "should be using the XmlSimple backend" do
|
24
|
-
OEmbed::Formatter::XML.backend.
|
25
|
+
expect(OEmbed::Formatter::XML.backend).to eq(OEmbed::Formatter::XML::Backends::XmlSimple)
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
it "should decode an XML String" do
|
28
29
|
decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
29
30
|
# We need to compare keys & values separately because we don't expect all
|
30
31
|
# non-string values to be recognized correctly.
|
31
|
-
decoded.keys.
|
32
|
-
decoded.values.map{|v|v.to_s}.
|
32
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
33
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
|
36
|
-
|
37
|
+
expect {
|
37
38
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
|
38
|
-
}.
|
39
|
-
|
39
|
+
}.to raise_error(OEmbed::ParseError)
|
40
|
+
expect {
|
40
41
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
|
41
|
-
}.
|
42
|
-
|
42
|
+
}.to raise_error(OEmbed::ParseError)
|
43
|
+
expect {
|
43
44
|
decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
|
44
|
-
}.
|
45
|
+
}.to raise_error(OEmbed::ParseError)
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
|
48
49
|
error_to_raise = ArgumentError
|
49
|
-
OEmbed::Formatter::XML.backend.parse_error.
|
50
|
-
|
51
|
-
::XmlSimple.
|
50
|
+
expect(OEmbed::Formatter::XML.backend.parse_error).to_not be_kind_of(error_to_raise)
|
51
|
+
|
52
|
+
expect(::XmlSimple).to receive(:xml_in).
|
52
53
|
and_raise(error_to_raise.new("unknown error"))
|
53
|
-
|
54
|
-
|
54
|
+
|
55
|
+
expect {
|
55
56
|
decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
56
|
-
}.
|
57
|
+
}.to raise_error(OEmbed::ParseError)
|
57
58
|
end
|
58
59
|
end
|
data/spec/formatter_spec.rb
CHANGED
@@ -4,32 +4,34 @@ describe OEmbed::Formatter do
|
|
4
4
|
include OEmbedSpecHelper
|
5
5
|
|
6
6
|
it "should support JSON" do
|
7
|
-
|
8
|
-
|
7
|
+
expect {
|
8
|
+
OEmbed::Formatter.supported?(:json)
|
9
|
+
}.to_not raise_error
|
9
10
|
end
|
10
11
|
|
11
12
|
it "should default to JSON" do
|
12
|
-
OEmbed::Formatter.default.
|
13
|
+
expect(OEmbed::Formatter.default).to eq('json')
|
13
14
|
end
|
14
15
|
|
15
16
|
it "should decode a JSON String" do
|
16
17
|
decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
|
17
18
|
# We need to compare keys & values separately because we don't expect all
|
18
19
|
# non-string values to be recognized correctly.
|
19
|
-
decoded.keys.
|
20
|
-
decoded.values.map{|v|v.to_s}.
|
20
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
21
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should support XML" do
|
24
|
-
|
25
|
-
|
25
|
+
expect {
|
26
|
+
OEmbed::Formatter.supported?(:xml)
|
27
|
+
}.to_not raise_error
|
26
28
|
end
|
27
29
|
|
28
30
|
it "should decode an XML String" do
|
29
31
|
decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
|
30
32
|
# We need to compare keys & values separately because we don't expect all
|
31
33
|
# non-string values to be recognized correctly.
|
32
|
-
decoded.keys.
|
33
|
-
decoded.values.map{|v|v.to_s}.
|
34
|
+
expect(decoded.keys).to eq(valid_response(:object).keys)
|
35
|
+
expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
34
36
|
end
|
35
37
|
end
|