ruby-oembed 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,31 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'json'
2
3
 
3
- describe "OEmbed::Formatter::JSON::Backends::JSONGem" do
4
- include OEmbedSpecHelper
4
+ describe "Setting JSON.backend = 'JSONGem'" do
5
+ context "without the JSON object defined" do
6
+ it "should fail" do
7
+ expect(OEmbed::Formatter::JSON).to receive(:already_loaded?).with('JSONGem').and_return(false)
8
+ expect(Object).to receive(:const_defined?).with('JSON').and_return(false)
5
9
 
6
- before(:all) do
7
- expect {
8
- OEmbed::Formatter::JSON.backend = 'JSONGem'
9
- }.to raise_error(LoadError)
10
+ expect {
11
+ OEmbed::Formatter::JSON.backend = 'JSONGem'
12
+ }.to raise_error(LoadError)
13
+ end
14
+ end
10
15
 
11
- require 'json'
16
+ context "with the JSON object loaded" do
17
+ it "should work" do
18
+ expect(OEmbed::Formatter::JSON).to receive(:already_loaded?).with('JSONGem').and_return(false)
12
19
 
13
- expect {
14
- OEmbed::Formatter::JSON.backend = 'JSONGem'
15
- }.to_not raise_error
20
+ expect {
21
+ OEmbed::Formatter::JSON.backend = 'JSONGem'
22
+ }.to_not raise_error
23
+ end
16
24
  end
25
+ end
26
+
27
+ describe "OEmbed::Formatter::JSON::Backends::JSONGem" do
28
+ include OEmbedSpecHelper
17
29
 
18
30
  it "should support JSON" do
19
31
  expect {
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'json'
2
3
  require 'vcr'
3
4
 
4
5
  VCR.config do |c|
@@ -9,6 +10,7 @@ end
9
10
 
10
11
  describe OEmbed::ProviderDiscovery do
11
12
  before(:all) do
13
+ OEmbed::Formatter::JSON.backend = 'JSONGem'
12
14
  VCR.insert_cassette('OEmbed_ProviderDiscovery')
13
15
  end
14
16
  after(:all) do
@@ -18,97 +20,111 @@ describe OEmbed::ProviderDiscovery do
18
20
  include OEmbedSpecHelper
19
21
 
20
22
  {
23
+ # 'name' => [
24
+ # 'given_page_url',
25
+ # 'expected_endpoint' || {:json=>'expected_json_endpoint', :xml=>'expected_xml_endpoint},
26
+ # :expected_format,
27
+ # ]
21
28
  'youtube' => [
22
29
  'http://www.youtube.com/watch?v=u6XAPnuFjJc',
23
- 'http://www.youtube.com/oembed',
30
+ {:json=>'http://www.youtube.com/oembed', :xml=>'http://www.youtube.com/oembed'},
24
31
  :json,
25
32
  ],
26
33
  'vimeo' => [
27
34
  'http://vimeo.com/27953845',
28
- {:json=>'http://vimeo.com/api/oembed.json',:xml=>'http://vimeo.com/api/oembed.xml'},
35
+ {:json=>'http://vimeo.com/api/oembed.json', :xml=>'http://vimeo.com/api/oembed.xml'},
29
36
  :json,
30
37
  ],
31
- #'noteflight' => [
32
- # 'http://www.noteflight.com/scores/view/09665392c94475f65dfaf5f30aadb6ed0921939d',
33
- # 'http://www.noteflight.com/services/oembed',
34
- # :json,
35
- #],
38
+ 'facebook-photo' => [
39
+ 'https://www.facebook.com/Federer/photos/pb.64760994940.-2207520000.1456668968./10153235368269941/?type=3&theater',
40
+ 'https://www.facebook.com/plugins/post/oembed.json/',
41
+ :json,
42
+ ],
43
+ 'tumblr' => [
44
+ 'http://kittehkats.tumblr.com/post/140525169406/katydid-and-the-egg-happy-forest-family',
45
+ 'https://www.tumblr.com/oembed/1.0',
46
+ :json
47
+ ],
48
+ 'noteflight' => [
49
+ 'http://www.noteflight.com/scores/view/09665392c94475f65dfaf5f30aadb6ed0921939d',
50
+ {:json=>'http://www.noteflight.com/services/oembed', :xml=>'http://www.noteflight.com/services/oembed'},
51
+ :json,
52
+ ],
53
+ # TODO: Enhance ProviderDiscovery to support arbitrary query parameters. See https://github.com/judofyr/ruby-oembed/issues/15
36
54
  #'wordpress' => [
37
55
  # 'http://sweetandweak.wordpress.com/2011/09/23/nothing-starts-the-morning-like-a-good-dose-of-panic/',
38
- # 'http://public-api.wordpress.com/oembed/1.0/',
56
+ # {:json=>'https://public-api.wordpress.com/oembed/1.0/', :xml=>'https://public-api.wordpress.com/oembed/1.0/'},
39
57
  # :json,
40
58
  #],
41
59
  }.each do |context, urls|
42
60
 
43
- given_url, expected_endpoint, expected_format = urls
44
-
45
- context "with #{context} url" do
61
+ given_url, expected_endpoints, expected_format = urls
62
+ expected_endpoints = {expected_format=>expected_endpoints} unless expected_endpoints.is_a?(Hash)
46
63
 
47
- describe "discover_provider" do
64
+ context "given a #{context} url" do
48
65
 
49
- before(:all) do
50
- @provider_default = OEmbed::ProviderDiscovery.discover_provider(given_url)
51
- @provider_json = OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:json)
52
- @provider_xml = OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:xml)
53
- end
54
-
55
- it "should return the correct Class" do
56
- expect(@provider_default).to be_instance_of(OEmbed::Provider)
57
- expect(@provider_json).to be_instance_of(OEmbed::Provider)
58
- expect(@provider_xml).to be_instance_of(OEmbed::Provider)
59
- end
66
+ shared_examples "a discover_provider call" do |endpoint, format|
67
+ describe ".discover_provider" do
68
+ it "should return the correct Class" do
69
+ expect(provider).to be_instance_of(OEmbed::Provider)
70
+ end
60
71
 
61
- it "should detect the correct URL" do
62
- if expected_endpoint.is_a?(Hash)
63
- expect(@provider_json.endpoint).to eq(expected_endpoint[expected_format])
64
- expect(@provider_json.endpoint).to eq(expected_endpoint[:json])
65
- expect(@provider_xml.endpoint).to eq(expected_endpoint[:xml])
66
- else
67
- expect(@provider_default.endpoint).to eq(expected_endpoint)
68
- expect(@provider_json.endpoint).to eq(expected_endpoint)
69
- expect(@provider_xml.endpoint).to eq(expected_endpoint)
72
+ it "should detect the correct URL" do
73
+ expect(provider.endpoint).to eq(endpoint)
70
74
  end
71
- end
72
75
 
73
- it "should return the correct format" do
74
- expect(@provider_default.format).to eq(expected_format)
75
- expect(@provider_json.format).to eq(:json)
76
- expect(@provider_xml.format).to eq(:xml)
76
+ it "should return the correct format" do
77
+ expect(provider.format).to eq(format)
78
+ end
77
79
  end
78
- end # discover_provider
79
80
 
80
- describe "get" do
81
-
82
- before(:all) do
83
- @response_default = OEmbed::ProviderDiscovery.get(given_url)
84
- @response_json = OEmbed::ProviderDiscovery.get(given_url, :format=>:json)
85
- @response_xml = OEmbed::ProviderDiscovery.get(given_url, :format=>:xml)
86
- end
81
+ describe ".get" do
82
+ it "should return the correct Class" do
83
+ expect(response).to be_kind_of(OEmbed::Response)
84
+ end
87
85
 
88
- it "should return the correct Class" do
89
- expect(@response_default).to be_kind_of(OEmbed::Response)
90
- expect(@response_json).to be_kind_of(OEmbed::Response)
91
- expect(@response_xml).to be_kind_of(OEmbed::Response)
92
- end
86
+ it "should return the correct format" do
87
+ expect(response.format).to eq(format.to_s)
88
+ end
93
89
 
94
- it "should return the correct format" do
95
- expect(@response_default.format).to eq(expected_format.to_s)
96
- expect(@response_json.format).to eq('json')
97
- expect(@response_xml.format).to eq('xml')
90
+ it "should return the correct data" do
91
+ expect(response.type).to_not be_empty
92
+
93
+ case response.type
94
+ when 'video', 'rich'
95
+ expect(response.html).to_not be_empty
96
+ expect(response.width).to_not be_nil
97
+ expect(response.height).to_not be_nil
98
+ when 'photo'
99
+ expect(response.url).to_not be_empty
100
+ expect(response.width).to_not be_nil
101
+ expect(response.height).to_not be_nil
102
+ end
103
+ end
104
+ end # get
105
+ end
106
+
107
+ context "with no format specified" do
108
+ let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url) }
109
+ let(:response) { OEmbed::ProviderDiscovery.get(given_url) }
110
+ include_examples "a discover_provider call", expected_endpoints[expected_format], expected_format
111
+ end
112
+
113
+ if expected_endpoints.include?(:json)
114
+ context "with json format specified" do
115
+ let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:json) }
116
+ let(:response) { OEmbed::ProviderDiscovery.get(given_url, :format=>:json) }
117
+ include_examples "a discover_provider call", expected_endpoints[:json], :json
98
118
  end
119
+ end
99
120
 
100
- it "should return the correct data" do
101
- expect(@response_default.type).to_not be_nil
102
- expect(@response_json.type).to_not be_nil
103
- expect(@response_xml.type).to_not be_nil
104
-
105
- # Technically, the following values _could_ be blank, but for the
106
- # examples urls we're using we expect them not to be.
107
- expect(@response_default.title).to_not be_nil
108
- expect(@response_json.title).to_not be_nil
109
- expect(@response_xml.title).to_not be_nil
121
+ if expected_endpoints.include?(:xml)
122
+ context "with json format specified" do
123
+ let(:provider) { OEmbed::ProviderDiscovery.discover_provider(given_url, :format=>:xml) }
124
+ let(:response) { OEmbed::ProviderDiscovery.get(given_url, :format=>:xml) }
125
+ include_examples "a discover_provider call", expected_endpoints[:xml], :xml
110
126
  end
111
- end # get
127
+ end
112
128
  end
113
129
 
114
130
  end # each service
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-oembed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Holm
@@ -127,6 +127,7 @@ files:
127
127
  - ".yardopts"
128
128
  - CHANGELOG.rdoc
129
129
  - Gemfile
130
+ - Guardfile
130
131
  - LICENSE
131
132
  - README.rdoc
132
133
  - Rakefile
@@ -184,7 +185,7 @@ rdoc_options:
184
185
  - "--main"
185
186
  - README.rdoc
186
187
  - "--title"
187
- - ruby-oembed-0.9.0
188
+ - ruby-oembed-0.10.0
188
189
  - "--inline-source"
189
190
  - "--exclude"
190
191
  - tasks