ruby-oembed 0.8.14 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile +8 -0
- data/lib/oembed/http_helper.rb +64 -0
- data/lib/oembed/provider.rb +21 -62
- data/lib/oembed/provider_discovery.rb +28 -32
- data/lib/oembed/providers.rb +7 -5
- data/lib/oembed/providers/embedly_urls.yml +142 -8
- data/lib/oembed/version.rb +2 -2
- data/spec/cassettes/OEmbed_ProviderDiscovery.yml +14874 -3782
- data/spec/provider_discovery_spec.rb +22 -1
- data/spec/providers_spec.rb +66 -66
- data/spec/response_spec.rb +85 -75
- data/spec/spec_helper.rb +8 -2
- metadata +4 -4
- data/.rvmrc +0 -1
@@ -113,4 +113,25 @@ describe OEmbed::ProviderDiscovery do
|
|
113
113
|
|
114
114
|
end # each service
|
115
115
|
|
116
|
-
|
116
|
+
context "when returning 404" do
|
117
|
+
let(:url) { 'https://www.youtube.com/watch?v=123123123' }
|
118
|
+
|
119
|
+
it "raises OEmbed::NotFound" do
|
120
|
+
expect{ OEmbed::ProviderDiscovery.discover_provider(url) }.to raise_error(OEmbed::NotFound)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when returning 301" do
|
125
|
+
let(:url) { 'http://www.youtube.com/watch?v=dFs9WO2B8uI' }
|
126
|
+
|
127
|
+
it "does redirect http to https" do
|
128
|
+
expect{ OEmbed::ProviderDiscovery.discover_provider(url) }.not_to raise_error
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "does passes the timeout option to Net::Http" do
|
133
|
+
expect_any_instance_of(Net::HTTP).to receive(:open_timeout=).with(5)
|
134
|
+
expect_any_instance_of(Net::HTTP).to receive(:read_timeout=).with(5)
|
135
|
+
OEmbed::ProviderDiscovery.discover_provider('https://www.youtube.com/watch?v=dFs9WO2B8uI', :timeout => 5)
|
136
|
+
end
|
137
|
+
end
|
data/spec/providers_spec.rb
CHANGED
@@ -18,82 +18,82 @@ describe OEmbed::Providers do
|
|
18
18
|
|
19
19
|
describe ".register" do
|
20
20
|
it "should register providers" do
|
21
|
-
OEmbed::Providers.urls.
|
22
|
-
|
21
|
+
expect(OEmbed::Providers.urls).to be_empty
|
22
|
+
|
23
23
|
OEmbed::Providers.register(@flickr, @qik)
|
24
|
-
|
25
|
-
OEmbed::Providers.urls.keys.
|
24
|
+
|
25
|
+
expect(OEmbed::Providers.urls.keys).to eq(@flickr.urls + @qik.urls)
|
26
26
|
|
27
27
|
@flickr.urls.each do |regexp|
|
28
|
-
OEmbed::Providers.urls.
|
29
|
-
OEmbed::Providers.urls[regexp].
|
28
|
+
expect(OEmbed::Providers.urls).to have_key(regexp)
|
29
|
+
expect(OEmbed::Providers.urls[regexp]).to include(@flickr)
|
30
30
|
end
|
31
31
|
|
32
32
|
@qik.urls.each do |regexp|
|
33
|
-
OEmbed::Providers.urls.
|
34
|
-
OEmbed::Providers.urls[regexp].
|
33
|
+
expect(OEmbed::Providers.urls).to have_key(regexp)
|
34
|
+
expect(OEmbed::Providers.urls[regexp]).to include(@qik)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should find by URLs" do
|
39
39
|
OEmbed::Providers.register(@flickr, @qik) # tested in "should register providers"
|
40
|
-
|
41
|
-
OEmbed::Providers.find(example_url(:flickr)).
|
42
|
-
OEmbed::Providers.find(example_url(:qik)).
|
40
|
+
|
41
|
+
expect(OEmbed::Providers.find(example_url(:flickr))).to eq(@flickr)
|
42
|
+
expect(OEmbed::Providers.find(example_url(:qik))).to eq(@qik)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe ".unregister" do
|
47
47
|
it "should unregister providers" do
|
48
48
|
OEmbed::Providers.register(@flickr, @qik) # tested in "should register providers"
|
49
|
-
|
49
|
+
|
50
50
|
OEmbed::Providers.unregister(@flickr)
|
51
|
-
|
51
|
+
|
52
52
|
@flickr.urls.each do |regexp|
|
53
|
-
OEmbed::Providers.urls.
|
53
|
+
expect(OEmbed::Providers.urls).to_not have_key(regexp)
|
54
54
|
end
|
55
|
-
|
56
|
-
OEmbed::Providers.urls.keys.
|
55
|
+
|
56
|
+
expect(OEmbed::Providers.urls.keys).to eq(@qik.urls)
|
57
57
|
|
58
58
|
@qik.urls.each do |regexp|
|
59
|
-
OEmbed::Providers.urls.
|
60
|
-
OEmbed::Providers.urls[regexp].
|
59
|
+
expect(OEmbed::Providers.urls).to have_key(regexp)
|
60
|
+
expect(OEmbed::Providers.urls[regexp]).to include(@qik)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should not unregister duplicate provider urls at first" do
|
65
65
|
@qik_mirror = OEmbed::Provider.new("http://mirror.qik.com/api/oembed.{format}")
|
66
66
|
@qik_mirror << "http://qik.com/*"
|
67
|
-
|
67
|
+
|
68
68
|
@qik_mirror.urls.each do |regexp|
|
69
|
-
@qik.urls.
|
69
|
+
expect(@qik.urls).to include(regexp)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
OEmbed::Providers.register(@qik, @qik_mirror)
|
73
|
-
|
74
|
-
OEmbed::Providers.urls.keys.
|
73
|
+
|
74
|
+
expect(OEmbed::Providers.urls.keys).to eq(@qik.urls)
|
75
75
|
|
76
76
|
@qik_mirror.urls.each do |regexp|
|
77
|
-
OEmbed::Providers.urls[regexp].
|
78
|
-
OEmbed::Providers.urls[regexp].
|
77
|
+
expect(OEmbed::Providers.urls[regexp]).to include(@qik_mirror)
|
78
|
+
expect(OEmbed::Providers.urls[regexp]).to include(@qik)
|
79
79
|
end
|
80
|
-
|
81
|
-
OEmbed::Providers.find(example_url(:qik)).
|
82
|
-
|
80
|
+
|
81
|
+
expect(OEmbed::Providers.find(example_url(:qik))).to eq(@qik)
|
82
|
+
|
83
83
|
OEmbed::Providers.unregister(@qik)
|
84
|
-
|
84
|
+
|
85
85
|
urls = OEmbed::Providers.urls.dup
|
86
86
|
|
87
87
|
@qik_mirror.urls.each do |regexp|
|
88
|
-
OEmbed::Providers.urls[regexp].
|
88
|
+
expect(OEmbed::Providers.urls[regexp]).to include(@qik_mirror)
|
89
89
|
end
|
90
|
-
|
91
|
-
OEmbed::Providers.find(example_url(:qik)).
|
92
|
-
|
90
|
+
|
91
|
+
expect(OEmbed::Providers.find(example_url(:qik))).to eq(@qik_mirror)
|
92
|
+
|
93
93
|
OEmbed::Providers.unregister(@qik_mirror)
|
94
|
-
|
94
|
+
|
95
95
|
@qik_mirror.urls.each do |regexp|
|
96
|
-
OEmbed::Providers.urls.
|
96
|
+
expect(OEmbed::Providers.urls).to_not have_key(regexp)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
@@ -114,10 +114,10 @@ describe OEmbed::Providers do
|
|
114
114
|
# OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery)
|
115
115
|
#
|
116
116
|
# provider = OEmbed::ProviderDiscovery
|
117
|
-
# provider.
|
117
|
+
# expect(provider).to receive(:raw).
|
118
118
|
# with(url, {}).
|
119
119
|
# and_return(valid_response(:raw))
|
120
|
-
# provider.
|
120
|
+
# expect(provider).to receive(:get).
|
121
121
|
# with(url, {}).
|
122
122
|
# and_return(valid_response(:object))
|
123
123
|
#end
|
@@ -127,9 +127,9 @@ describe OEmbed::Providers do
|
|
127
127
|
OEmbed::Providers.register_all
|
128
128
|
all_example_urls.each do |url|
|
129
129
|
provider = OEmbed::Providers.find(url)
|
130
|
-
expect(provider).
|
130
|
+
expect(provider).to receive(:raw).
|
131
131
|
with(url, {})
|
132
|
-
expect(provider).
|
132
|
+
expect(provider).to receive(:get).
|
133
133
|
with(url, {})
|
134
134
|
OEmbed::Providers.raw(url)
|
135
135
|
OEmbed::Providers.get(url)
|
@@ -139,8 +139,8 @@ describe OEmbed::Providers do
|
|
139
139
|
it "should raise an error if no embeddable content is found" do
|
140
140
|
OEmbed::Providers.register_all
|
141
141
|
["http://fake.com/", example_url(:google_video)].each do |url|
|
142
|
-
|
143
|
-
|
142
|
+
expect { OEmbed::Providers.get(url) }.to raise_error(OEmbed::NotFound)
|
143
|
+
expect { OEmbed::Providers.raw(url) }.to raise_error(OEmbed::NotFound)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
@@ -150,28 +150,28 @@ describe OEmbed::Providers do
|
|
150
150
|
OEmbed::Providers.register_fallback(OEmbed::Providers::Hulu)
|
151
151
|
OEmbed::Providers.register_fallback(OEmbed::Providers::OohEmbed)
|
152
152
|
|
153
|
-
OEmbed::Providers.fallback.
|
153
|
+
expect(OEmbed::Providers.fallback).to eq([ OEmbed::Providers::Hulu, OEmbed::Providers::OohEmbed])
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should fallback to the appropriate provider when URL isn't found" do
|
157
157
|
OEmbed::Providers.register_all
|
158
158
|
OEmbed::Providers.register_fallback(OEmbed::Providers::Hulu)
|
159
159
|
OEmbed::Providers.register_fallback(OEmbed::Providers::OohEmbed)
|
160
|
-
|
160
|
+
|
161
161
|
url = example_url(:google_video)
|
162
162
|
|
163
163
|
provider = OEmbed::Providers.fallback.last
|
164
|
-
provider.
|
164
|
+
expect(provider).to receive(:raw).
|
165
165
|
with(url, {}).
|
166
166
|
and_return(valid_response(:raw))
|
167
|
-
provider.
|
167
|
+
expect(provider).to receive(:get).
|
168
168
|
with(url, {}).
|
169
169
|
and_return(valid_response(:object))
|
170
170
|
|
171
171
|
OEmbed::Providers.fallback.each do |p|
|
172
172
|
next if p == provider
|
173
|
-
p.
|
174
|
-
p.
|
173
|
+
expect(p).to receive(:raw).and_raise(OEmbed::NotFound)
|
174
|
+
expect(p).to receive(:get).and_raise(OEmbed::NotFound)
|
175
175
|
end
|
176
176
|
|
177
177
|
OEmbed::Providers.raw(url)
|
@@ -182,10 +182,10 @@ describe OEmbed::Providers do
|
|
182
182
|
OEmbed::Providers.register_all
|
183
183
|
OEmbed::Providers.register_fallback(OEmbed::Providers::Hulu)
|
184
184
|
OEmbed::Providers.register_fallback(OEmbed::Providers::OohEmbed)
|
185
|
-
|
185
|
+
|
186
186
|
["http://fa.ke/"].each do |url|
|
187
|
-
|
188
|
-
|
187
|
+
expect { OEmbed::Providers.get(url) }.to raise_error(OEmbed::NotFound)
|
188
|
+
expect { OEmbed::Providers.raw(url) }.to raise_error(OEmbed::NotFound)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
@@ -194,26 +194,26 @@ describe OEmbed::Providers do
|
|
194
194
|
after(:each) do
|
195
195
|
OEmbed::Providers.send(:remove_const, :Fake) if defined?(OEmbed::Providers::Fake)
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
it "should not register a provider that is not marked as official" do
|
199
|
-
defined?(OEmbed::Providers::Fake).
|
200
|
-
|
199
|
+
expect(defined?(OEmbed::Providers::Fake)).to_not be
|
200
|
+
|
201
201
|
class OEmbed::Providers
|
202
202
|
Fake = OEmbed::Provider.new("http://new.fa.ke/oembed/")
|
203
203
|
Fake << "http://new.fa.ke/*"
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
OEmbed::Providers.register_all
|
207
207
|
["http://new.fa.ke/20C285E0"].each do |url|
|
208
208
|
provider = OEmbed::Providers.find(url)
|
209
|
-
provider.
|
209
|
+
expect(provider).to be_nil
|
210
210
|
end
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
describe 'add_official_provider' do
|
214
214
|
it "should register a new official provider" do
|
215
|
-
defined?(OEmbed::Providers::Fake).
|
216
|
-
|
215
|
+
expect(defined?(OEmbed::Providers::Fake)).to_not be
|
216
|
+
|
217
217
|
class OEmbed::Providers
|
218
218
|
Fake = OEmbed::Provider.new("http://official.fa.ke/oembed/")
|
219
219
|
Fake << "http://official.fa.ke/*"
|
@@ -222,19 +222,19 @@ describe OEmbed::Providers do
|
|
222
222
|
|
223
223
|
["http://official.fa.ke/20C285E0"].each do |url|
|
224
224
|
provider = OEmbed::Providers.find(url)
|
225
|
-
provider.
|
225
|
+
expect(provider).to_not be_a(OEmbed::Provider)
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
OEmbed::Providers.register_all
|
229
229
|
["http://official.fa.ke/20C285E0"].each do |url|
|
230
230
|
provider = OEmbed::Providers.find(url)
|
231
|
-
provider.
|
231
|
+
expect(provider).to be_a(OEmbed::Provider)
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
235
|
it "should register an official sub_type provider separately" do
|
236
|
-
defined?(OEmbed::Providers::Fake).
|
237
|
-
|
236
|
+
expect(defined?(OEmbed::Providers::Fake)).to_not be
|
237
|
+
|
238
238
|
class OEmbed::Providers
|
239
239
|
Fake = OEmbed::Provider.new("http://sub.fa.ke/oembed/")
|
240
240
|
Fake << "http://sub.fa.ke/*"
|
@@ -244,13 +244,13 @@ describe OEmbed::Providers do
|
|
244
244
|
OEmbed::Providers.register_all
|
245
245
|
["http://sub.fa.ke/20C285E0"].each do |url|
|
246
246
|
provider = OEmbed::Providers.find(url)
|
247
|
-
provider.
|
247
|
+
expect(provider).to_not be_a(OEmbed::Provider)
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
OEmbed::Providers.register_all(:fakes)
|
251
251
|
["http://sub.fa.ke/20C285E0"].each do |url|
|
252
252
|
provider = OEmbed::Providers.find(url)
|
253
|
-
provider.
|
253
|
+
expect(provider).to be_a(OEmbed::Provider)
|
254
254
|
end
|
255
255
|
end
|
256
256
|
end
|
data/spec/response_spec.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
+
def expected_helpers
|
4
|
+
{
|
5
|
+
"type" => "random",
|
6
|
+
"version" => "1.0",
|
7
|
+
"html" => "<em>Hello world!</em>",
|
8
|
+
"url" => "http://foo.com/bar",
|
9
|
+
}.freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
def expected_skipped
|
13
|
+
{
|
14
|
+
"fields" => "hello",
|
15
|
+
"__id__" => 1234,
|
16
|
+
"provider" => "oohEmbed",
|
17
|
+
"to_s" => "random string",
|
18
|
+
}.freeze
|
19
|
+
end
|
20
|
+
|
21
|
+
def all_expected
|
22
|
+
expected_helpers.merge(expected_skipped).freeze
|
23
|
+
end
|
24
|
+
|
3
25
|
describe OEmbed::Response do
|
4
26
|
include OEmbedSpecHelper
|
5
27
|
|
@@ -42,65 +64,43 @@ describe OEmbed::Response do
|
|
42
64
|
OEmbed::Response.create_for(valid_response(:json), @viddler, example_url(:viddler), :json)
|
43
65
|
}
|
44
66
|
|
45
|
-
let(:expected_helpers) {
|
46
|
-
{
|
47
|
-
"type" => "random",
|
48
|
-
"version" => "1.0",
|
49
|
-
"html" => "<em>Hello world!</em>",
|
50
|
-
"url" => "http://foo.com/bar",
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
let(:expected_skipped) {
|
55
|
-
{
|
56
|
-
"fields" => "hello",
|
57
|
-
"__id__" => 1234,
|
58
|
-
"provider" => "oohEmbed",
|
59
|
-
"to_s" => "random string",
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
let(:all_expected) {
|
64
|
-
expected_helpers.merge(expected_skipped)
|
65
|
-
}
|
66
|
-
|
67
67
|
describe "#initialize" do
|
68
68
|
it "should parse the data into fields" do
|
69
69
|
# We need to compare keys & values separately because we don't expect all
|
70
70
|
# non-string values to be recognized correctly.
|
71
71
|
|
72
|
-
new_res.fields.keys.
|
73
|
-
new_res.fields.values.map{|v|v.to_s}.
|
72
|
+
expect(new_res.fields.keys).to eq(valid_response(:object).keys)
|
73
|
+
expect(new_res.fields.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
74
74
|
|
75
|
-
default_res.fields.keys.
|
76
|
-
default_res.fields.values.map{|v|v.to_s}.
|
75
|
+
expect(default_res.fields.keys).to eq(valid_response(:object).keys)
|
76
|
+
expect(default_res.fields.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
77
77
|
|
78
|
-
xml_res.fields.keys.
|
79
|
-
xml_res.fields.values.map{|v|v.to_s}.
|
78
|
+
expect(xml_res.fields.keys).to eq(valid_response(:object).keys)
|
79
|
+
expect(xml_res.fields.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
80
80
|
|
81
|
-
json_res.fields.keys.
|
82
|
-
json_res.fields.values.map{|v|v.to_s}.
|
81
|
+
expect(json_res.fields.keys).to eq(valid_response(:object).keys)
|
82
|
+
expect(json_res.fields.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should set the provider" do
|
86
|
-
new_res.provider.
|
87
|
-
default_res.provider.
|
88
|
-
xml_res.provider.
|
89
|
-
json_res.provider.
|
86
|
+
expect(new_res.provider).to eq(OEmbed::Providers::OohEmbed)
|
87
|
+
expect(default_res.provider).to eq(@flickr)
|
88
|
+
expect(xml_res.provider).to eq(@qik)
|
89
|
+
expect(json_res.provider).to eq(@viddler)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should set the format" do
|
93
|
-
new_res.format.
|
94
|
-
default_res.format.to_s.
|
95
|
-
xml_res.format.to_s.
|
96
|
-
json_res.format.to_s.
|
93
|
+
expect(new_res.format).to be_nil
|
94
|
+
expect(default_res.format.to_s).to eq('json')
|
95
|
+
expect(xml_res.format.to_s).to eq('xml')
|
96
|
+
expect(json_res.format.to_s).to eq('json')
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should set the request_url" do
|
100
|
-
new_res.request_url.
|
101
|
-
default_res.request_url.to_s.
|
102
|
-
xml_res.request_url.to_s.
|
103
|
-
json_res.request_url.to_s.
|
100
|
+
expect(new_res.request_url).to be_nil
|
101
|
+
expect(default_res.request_url.to_s).to eq(example_url(:flickr))
|
102
|
+
expect(xml_res.request_url.to_s).to eq(example_url(:qik))
|
103
|
+
expect(json_res.request_url.to_s).to eq(example_url(:viddler))
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -135,45 +135,55 @@ describe OEmbed::Response do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should access the XML data through #field" do
|
138
|
-
xml_res.field(:type).
|
139
|
-
xml_res.field(:version).
|
140
|
-
xml_res.field(:fields).
|
141
|
-
xml_res.field(:__id__).
|
138
|
+
expect(xml_res.field(:type)).to eq("photo")
|
139
|
+
expect(xml_res.field(:version)).to eq("1.0")
|
140
|
+
expect(xml_res.field(:fields)).to eq("hello")
|
141
|
+
expect(xml_res.field(:__id__)).to eq("1234")
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should access the JSON data through #field" do
|
145
|
-
json_res.field(:type).
|
146
|
-
json_res.field(:version).
|
147
|
-
json_res.field(:fields).
|
148
|
-
json_res.field(:__id__).
|
145
|
+
expect(json_res.field(:type)).to eq("photo")
|
146
|
+
expect(json_res.field(:version)).to eq("1.0")
|
147
|
+
expect(json_res.field(:fields)).to eq("hello")
|
148
|
+
expect(json_res.field(:__id__)).to eq("1234")
|
149
149
|
end
|
150
150
|
|
151
151
|
describe "#define_methods!" do
|
152
|
-
|
153
|
-
local_res = OEmbed::Response.new(all_expected, OEmbed::Providers::OohEmbed)
|
154
|
-
|
152
|
+
context "with automagic" do
|
155
153
|
all_expected.each do |method, value|
|
156
|
-
|
154
|
+
before do
|
155
|
+
@local_res = OEmbed::Response.new(all_expected, OEmbed::Providers::OohEmbed)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should define the #{method} method" do
|
159
|
+
expect(@local_res).to respond_to(method)
|
160
|
+
end
|
157
161
|
end
|
162
|
+
|
158
163
|
expected_helpers.each do |method, value|
|
159
|
-
|
164
|
+
it "should define #{method} to return #{value.inspect}" do
|
165
|
+
expect(@local_res.send(method)).to eq(value)
|
166
|
+
end
|
160
167
|
end
|
168
|
+
|
161
169
|
expected_skipped.each do |method, value|
|
162
|
-
|
170
|
+
it "should NOT override #{method} to not return #{value.inspect}" do
|
171
|
+
expect(@local_res.send(method)).to_not eq(value)
|
172
|
+
end
|
163
173
|
end
|
164
174
|
end
|
165
175
|
|
166
176
|
it "should protect most already defined methods" do
|
167
|
-
Object.new.
|
168
|
-
Object.new.
|
177
|
+
expect(Object.new).to respond_to('__id__')
|
178
|
+
expect(Object.new).to respond_to('to_s')
|
169
179
|
|
170
|
-
all_expected.keys.
|
171
|
-
all_expected.keys.
|
180
|
+
expect(all_expected.keys).to include('__id__')
|
181
|
+
expect(all_expected.keys).to include('to_s')
|
172
182
|
|
173
183
|
local_res = OEmbed::Response.new(all_expected, OEmbed::Providers::OohEmbed)
|
174
184
|
|
175
|
-
local_res.__id__.
|
176
|
-
local_res.to_s.
|
185
|
+
expect(local_res.__id__).to_not eq(local_res.field('__id__'))
|
186
|
+
expect(local_res.to_s).to_not eq(local_res.field('to_s'))
|
177
187
|
end
|
178
188
|
|
179
189
|
it "should not protect already defined methods that are specifically overridable" do
|
@@ -183,16 +193,16 @@ describe OEmbed::Response do
|
|
183
193
|
end
|
184
194
|
end
|
185
195
|
|
186
|
-
Object.new.
|
187
|
-
String.new.
|
196
|
+
expect(Object.new).to respond_to('version')
|
197
|
+
expect(String.new).to respond_to('version')
|
188
198
|
|
189
|
-
all_expected.keys.
|
190
|
-
all_expected['version'].
|
199
|
+
expect(all_expected.keys).to include('version')
|
200
|
+
expect(all_expected['version']).to_not eq(String.new.version)
|
191
201
|
|
192
202
|
local_res = OEmbed::Response.new(all_expected, OEmbed::Providers::OohEmbed)
|
193
203
|
|
194
|
-
local_res.version.
|
195
|
-
local_res.version.
|
204
|
+
expect(local_res.version).to eq(local_res.field('version'))
|
205
|
+
expect(local_res.version).to_not eq(String.new.version)
|
196
206
|
end
|
197
207
|
end
|
198
208
|
|
@@ -200,19 +210,19 @@ describe OEmbed::Response do
|
|
200
210
|
describe "#html" do
|
201
211
|
it "should include the title, if given" do
|
202
212
|
response = OEmbed::Response.create_for(example_body(:flickr), example_url(:flickr), flickr, :json)
|
203
|
-
response.
|
204
|
-
response.title.
|
213
|
+
expect(response).to respond_to(:title)
|
214
|
+
expect(response.title).to_not be_empty
|
205
215
|
|
206
|
-
response.html.
|
207
|
-
response.html.
|
216
|
+
expect(response.html).to_not be_nil
|
217
|
+
expect(response.html).to match(/alt='#{response.title}'/)
|
208
218
|
end
|
209
219
|
|
210
220
|
it "should work just fine, without a title" do
|
211
221
|
response = OEmbed::Response.create_for(example_body(:skitch), example_url(:skitch), skitch, :json)
|
212
|
-
response.
|
222
|
+
expect(response).to_not respond_to(:title)
|
213
223
|
|
214
|
-
response.html.
|
215
|
-
response.html.
|
224
|
+
expect(response.html).to_not be_nil
|
225
|
+
expect(response.html).to match(/alt=''/)
|
216
226
|
end
|
217
227
|
end
|
218
228
|
end
|