ruby-oembed 0.8.3 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "OEmbed::Formatter::XML::Backends::Nokogiri" do
4
+ include OEmbedSpecHelper
5
+
6
+ before(:all) do
7
+ lambda {
8
+ OEmbed::Formatter::XML.backend = 'Nokogiri'
9
+ }.should raise_error(LoadError)
10
+
11
+ require 'nokogiri'
12
+
13
+ lambda {
14
+ OEmbed::Formatter::XML.backend = 'Nokogiri'
15
+ }.should_not raise_error
16
+ end
17
+
18
+ it "should support XML" do
19
+ proc { OEmbed::Formatter.supported?(:xml) }.
20
+ should_not raise_error(OEmbed::FormatNotSupported)
21
+ end
22
+
23
+ it "should be using the Nokogiri backend" do
24
+ OEmbed::Formatter::XML.backend.should == OEmbed::Formatter::XML::Backends::Nokogiri
25
+ end
26
+
27
+ it "should decode an XML String" do
28
+ decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
29
+ # We need to compare keys & values separately because we don't expect all
30
+ # non-string values to be recognized correctly.
31
+ decoded.keys.should == valid_response(:object).keys
32
+ decoded.values.map{|v|v.to_s}.should == valid_response(:object).values.map{|v|v.to_s}
33
+ end
34
+
35
+ it "should raise an OEmbed::ParseError when decoding an invalid XML String" do
36
+ lambda {
37
+ decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_container', :xml))
38
+ }.should raise_error(OEmbed::ParseError)
39
+ lambda {
40
+ decode = OEmbed::Formatter.decode(:xml, invalid_response('unclosed_tag', :xml))
41
+ }.should raise_error(OEmbed::ParseError)
42
+ lambda {
43
+ decode = OEmbed::Formatter.decode(:xml, invalid_response('invalid_syntax', :xml))
44
+ }.should raise_error(OEmbed::ParseError)
45
+ end
46
+
47
+ it "should raise an OEmbed::ParseError when decoding fails with an unexpected error" do
48
+ error_to_raise = ArgumentError
49
+ OEmbed::Formatter::XML.backend.parse_error.should_not be_kind_of(error_to_raise)
50
+
51
+ ::Nokogiri::XML::Document.should_receive(:parse).
52
+ and_raise(error_to_raise.new("unknown error"))
53
+
54
+ lambda {
55
+ decode = OEmbed::Formatter.decode(:xml, valid_response(:xml))
56
+ }.should raise_error(OEmbed::ParseError)
57
+ end
58
+ end
@@ -0,0 +1,116 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'vcr'
3
+
4
+ VCR.config do |c|
5
+ c.default_cassette_options = { :record => :new_episodes }
6
+ c.cassette_library_dir = 'spec/cassettes'
7
+ c.stub_with :fakeweb
8
+ end
9
+
10
+ describe OEmbed::ProviderDiscovery do
11
+ before(:all) do
12
+ VCR.insert_cassette('OEmbed_ProviderDiscovery')
13
+ end
14
+ after(:all) do
15
+ VCR.eject_cassette
16
+ end
17
+
18
+ include OEmbedSpecHelper
19
+
20
+ {
21
+ 'youtube' => [
22
+ 'http://www.youtube.com/watch?v=u6XAPnuFjJc',
23
+ 'http://www.youtube.com/oembed',
24
+ :json,
25
+ ],
26
+ 'vimeo' => [
27
+ 'http://vimeo.com/27953845',
28
+ {:json=>'http://vimeo.com/api/oembed.json',:xml=>'http://vimeo.com/api/oembed.xml'},
29
+ :json,
30
+ ],
31
+ #'noteflight' => [
32
+ # 'http://www.noteflight.com/scores/view/09665392c94475f65dfaf5f30aadb6ed0921939d',
33
+ # 'http://www.noteflight.com/services/oembed',
34
+ # :json,
35
+ #],
36
+ #'wordpress' => [
37
+ # '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/',
39
+ # :json,
40
+ #],
41
+ }.each do |context, urls|
42
+
43
+ given_url, expected_endpoint, expected_format = urls
44
+
45
+ context "with #{context} url" do
46
+
47
+ describe "discover_provider" do
48
+
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
+ @provider_default.should be_instance_of(OEmbed::Provider)
57
+ @provider_json.should be_instance_of(OEmbed::Provider)
58
+ @provider_xml.should be_instance_of(OEmbed::Provider)
59
+ end
60
+
61
+ it "should detect the correct URL" do
62
+ if expected_endpoint.is_a?(Hash)
63
+ @provider_json.endpoint.should eq(expected_endpoint[expected_format])
64
+ @provider_json.endpoint.should eq(expected_endpoint[:json])
65
+ @provider_xml.endpoint.should eq(expected_endpoint[:xml])
66
+ else
67
+ @provider_default.endpoint.should eq(expected_endpoint)
68
+ @provider_json.endpoint.should eq(expected_endpoint)
69
+ @provider_xml.endpoint.should eq(expected_endpoint)
70
+ end
71
+ end
72
+
73
+ it "should return the correct format" do
74
+ @provider_default.format.should eq(expected_format)
75
+ @provider_json.format.should eq(:json)
76
+ @provider_xml.format.should eq(:xml)
77
+ end
78
+ end # discover_provider
79
+
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
87
+
88
+ it "should return the correct Class" do
89
+ @response_default.should be_kind_of(OEmbed::Response)
90
+ @response_json.should be_kind_of(OEmbed::Response)
91
+ @response_xml.should be_kind_of(OEmbed::Response)
92
+ end
93
+
94
+ it "should return the correct format" do
95
+ @response_default.format.should eq(expected_format.to_s)
96
+ @response_json.format.should eq('json')
97
+ @response_xml.format.should eq('xml')
98
+ end
99
+
100
+ it "should return the correct data" do
101
+ @response_default.type.should_not be_nil
102
+ @response_json.type.should_not be_nil
103
+ @response_xml.type.should_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
+ @response_default.title.should_not be_nil
108
+ @response_json.title.should_not be_nil
109
+ @response_xml.title.should_not be_nil
110
+ end
111
+ end # get
112
+ end
113
+
114
+ end # each service
115
+
116
+ end
@@ -266,7 +266,8 @@ describe OEmbed::Provider do
266
266
 
267
267
  it "should raise error on all other responses" do
268
268
  Net::HTTPResponse::CODE_TO_OBJ.delete_if do |code, res|
269
- ["200", "404", "501"].include?(code)
269
+ ("200".."299").include?(code) ||
270
+ ["404", "501"].include?(code)
270
271
  end.each do |code, res|
271
272
  r = res.new("1.1", code, "Message")
272
273
  Net::HTTP.stub!(:start).and_return(r)
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'vcr'
2
3
  require File.dirname(__FILE__) + '/../lib/oembed'
3
4
 
4
5
  module OEmbedSpecHelper
@@ -45,7 +46,7 @@ module OEmbedSpecHelper
45
46
  "__id__" => 1234
46
47
  }
47
48
  when 'json'
48
- <<-JSON
49
+ <<-JSON.strip
49
50
  {
50
51
  "type": "photo",
51
52
  "version": "1.0",
@@ -54,7 +55,7 @@ module OEmbedSpecHelper
54
55
  }
55
56
  JSON
56
57
  when 'xml'
57
- <<-XML
58
+ <<-XML.strip
58
59
  <?xml version="1.0" encoding="utf-8" standalone="yes"?>
59
60
  <oembed>
60
61
  <type>photo</type>
metadata CHANGED
@@ -1,15 +1,10 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-oembed
3
- version: !ruby/object:Gem::Version
4
- hash: 57
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 8
9
- - 3
10
- version: 0.8.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Magnus Holm
14
9
  - Alex Kessinger
15
10
  - Aris Bartee
@@ -17,92 +12,108 @@ authors:
17
12
  autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
-
21
- date: 2011-06-26 00:00:00 -07:00
22
- default_executable:
23
- dependencies:
24
- - !ruby/object:Gem::Dependency
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
- version: "0"
15
+ date: 2011-11-15 00:00:00.000000000Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
34
18
  name: jeweler
35
- prerelease: false
36
- type: :development
37
- requirement: *id001
38
- - !ruby/object:Gem::Dependency
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
19
+ requirement: &2170353860 !ruby/object:Gem::Requirement
40
20
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
48
- name: rake
49
- prerelease: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
50
25
  type: :development
51
- requirement: *id002
52
- - !ruby/object:Gem::Dependency
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
26
+ prerelease: false
27
+ version_requirements: *2170353860
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: &2170353280 !ruby/object:Gem::Requirement
54
31
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: *2170353280
39
+ - !ruby/object:Gem::Dependency
62
40
  name: json
41
+ requirement: &2170352700 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
63
48
  prerelease: false
49
+ version_requirements: *2170352700
50
+ - !ruby/object:Gem::Dependency
51
+ name: xml-simple
52
+ requirement: &2170352120 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
64
58
  type: :development
65
- requirement: *id003
66
- - !ruby/object:Gem::Dependency
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
59
+ prerelease: false
60
+ version_requirements: *2170352120
61
+ - !ruby/object:Gem::Dependency
62
+ name: nokogiri
63
+ requirement: &2170351480 !ruby/object:Gem::Requirement
68
64
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- name: xml-simple
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
77
70
  prerelease: false
71
+ version_requirements: *2170351480
72
+ - !ruby/object:Gem::Dependency
73
+ name: rspec
74
+ requirement: &2170350980 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '2.0'
78
80
  type: :development
79
- requirement: *id004
80
- - !ruby/object:Gem::Dependency
81
- version_requirements: &id005 !ruby/object:Gem::Requirement
81
+ prerelease: false
82
+ version_requirements: *2170350980
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: &2170350500 !ruby/object:Gem::Requirement
82
86
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 2
89
- - 0
90
- version: "2.0"
91
- name: rspec
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
91
+ type: :development
92
92
  prerelease: false
93
+ version_requirements: *2170350500
94
+ - !ruby/object:Gem::Dependency
95
+ name: fakeweb
96
+ requirement: &2170350020 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
93
102
  type: :development
94
- requirement: *id005
95
- description: An oEmbed consumer library written in Ruby, letting you easily get embeddable HTML representations of supported web pages, based on their URLs. See http://oembed.com for more information about the protocol.
103
+ prerelease: false
104
+ version_requirements: *2170350020
105
+ description: An oEmbed consumer library written in Ruby, letting you easily get embeddable
106
+ HTML representations of supported web pages, based on their URLs. See http://oembed.com
107
+ for more information about the protocol.
96
108
  email: arisbartee@gmail.com
97
109
  executables: []
98
-
99
110
  extensions: []
100
-
101
- extra_rdoc_files:
111
+ extra_rdoc_files:
102
112
  - LICENSE
103
113
  - README.rdoc
104
- files:
114
+ files:
105
115
  - .rvmrc
116
+ - .travis.yml
106
117
  - .yardopts
107
118
  - CHANGELOG.rdoc
108
119
  - Gemfile
@@ -121,6 +132,7 @@ files:
121
132
  - lib/oembed/formatter/json/backends/jsongem.rb
122
133
  - lib/oembed/formatter/json/backends/yaml.rb
123
134
  - lib/oembed/formatter/xml.rb
135
+ - lib/oembed/formatter/xml/backends/nokogiri.rb
124
136
  - lib/oembed/formatter/xml/backends/rexml.rb
125
137
  - lib/oembed/formatter/xml/backends/xmlsimple.rb
126
138
  - lib/oembed/provider.rb
@@ -137,57 +149,51 @@ files:
137
149
  - lib/tasks/oembed.rake
138
150
  - lib/tasks/rspec.rake
139
151
  - ruby-oembed.gemspec
152
+ - spec/cassettes/OEmbed_ProviderDiscovery.yml
140
153
  - spec/formatter/ducktype_backend_spec.rb
141
154
  - spec/formatter/json/.DS_Store
142
155
  - spec/formatter/json/jsongem_backend_spec.rb
143
156
  - spec/formatter/json/yaml_backend_spec.rb
157
+ - spec/formatter/xml/nokogiri_backend_spec.rb
144
158
  - spec/formatter/xml/rexml_backend_spec.rb
145
159
  - spec/formatter/xml/xmlsimple_backend_spec.rb
146
160
  - spec/formatter_spec.rb
161
+ - spec/provider_discovery_spec.rb
147
162
  - spec/provider_spec.rb
148
163
  - spec/providers_spec.rb
149
164
  - spec/response_spec.rb
150
165
  - spec/spec_helper.rb
151
- has_rdoc: true
152
166
  homepage: http://github.com/judofyr/ruby-oembed
153
- licenses:
167
+ licenses:
154
168
  - MIT
155
169
  post_install_message:
156
- rdoc_options:
170
+ rdoc_options:
157
171
  - --main
158
172
  - README.rdoc
159
173
  - --title
160
- - ruby-oembed-0.8.3
174
+ - ruby-oembed-0.8.5
161
175
  - --inline-source
162
176
  - --exclude
163
177
  - tasks
164
178
  - CHANGELOG.rdoc
165
- require_paths:
179
+ require_paths:
166
180
  - lib
167
- required_ruby_version: !ruby/object:Gem::Requirement
181
+ required_ruby_version: !ruby/object:Gem::Requirement
168
182
  none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- hash: 3
173
- segments:
174
- - 0
175
- version: "0"
176
- required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
188
  none: false
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- hash: 3
182
- segments:
183
- - 0
184
- version: "0"
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
185
193
  requirements: []
186
-
187
194
  rubyforge_project:
188
- rubygems_version: 1.4.2
195
+ rubygems_version: 1.8.10
189
196
  signing_key:
190
197
  specification_version: 3
191
198
  summary: oEmbed for Ruby
192
199
  test_files: []
193
-