Skip to content

Commit a585f55

Browse files
committed
Merge pull request #61 from ruby-oembed/feature/per-provider-specs
per-Provider specs
2 parents 9b432b0 + 3fb7f8a commit a585f55

File tree

8 files changed

+1733
-14
lines changed

8 files changed

+1733
-14
lines changed

spec/cassettes/OEmbed_Providers_Slideshare.yml

Lines changed: 1199 additions & 0 deletions
Large diffs are not rendered by default.

spec/cassettes/OEmbed_Providers_Twitter.yml

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.

spec/provider_discovery_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
require File.dirname(__FILE__) + '/spec_helper'
22
require 'json'
3-
require 'vcr'
4-
5-
VCR.config do |c|
6-
c.default_cassette_options = { :record => :new_episodes }
7-
c.cassette_library_dir = 'spec/cassettes'
8-
c.stub_with :fakeweb
9-
end
103

114
describe OEmbed::ProviderDiscovery do
125
before(:all) do

spec/provider_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
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
92

103
describe OEmbed::Provider do
114
before(:all) do

spec/providers/slideshare_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require File.join(File.dirname(__FILE__), '../spec_helper')
2+
require 'support/shared_examples_for_providers'
3+
4+
describe 'OEmbed::Providers::Slideshare' do
5+
before(:all) do
6+
VCR.insert_cassette('OEmbed_Providers_Slideshare')
7+
end
8+
after(:all) do
9+
VCR.eject_cassette
10+
end
11+
12+
include OEmbedSpecHelper
13+
14+
let(:provider_class) { OEmbed::Providers::Slideshare }
15+
16+
expected_valid_urls = (
17+
%w(https:// http://).map do |protocol|
18+
%w(slideshare.net www.slideshare.net de.slideshare.net).map do |host|
19+
[
20+
'/gabriele.lana/the-magic-of-elixir',
21+
# Even though Slideshare's oEmbed endpoint
22+
# is supposed to /mobile/ URLs,
23+
# as of 2016-05-21 it's returning 404 results for these URLs.
24+
#'/mobile/gabriele.lana/the-magic-of-elixir',
25+
].map do |path|
26+
File.join(protocol, host, path)
27+
end
28+
end
29+
end
30+
).flatten
31+
32+
expected_invalid_urls = %w(
33+
http://www.slideshare.net
34+
http://www.slideshare.net/gabriele.lana
35+
)
36+
37+
it_should_behave_like(
38+
"an OEmbed::Proviers instance",
39+
expected_valid_urls,
40+
expected_invalid_urls
41+
)
42+
end

spec/providers/twitter_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require File.join(File.dirname(__FILE__), '../spec_helper')
2+
require 'support/shared_examples_for_providers'
3+
4+
describe 'OEmbed::Providers::Twitter' do
5+
before(:all) do
6+
VCR.insert_cassette('OEmbed_Providers_Twitter')
7+
end
8+
after(:all) do
9+
VCR.eject_cassette
10+
end
11+
12+
include OEmbedSpecHelper
13+
14+
let(:provider_class) { OEmbed::Providers::Twitter }
15+
16+
expected_valid_urls = %w(
17+
https://twitter.com/RailsGirlsSoC/status/702136612822634496
18+
https://www.twitter.com/bpoweski/status/71633762
19+
)
20+
expected_invalid_urls = %w(
21+
http://twitter.com/RailsGirlsSoC/status/702136612822634496
22+
https://twitter.es/FCBarcelona_es/status/734194638697959424
23+
)
24+
25+
it_should_behave_like(
26+
"an OEmbed::Proviers instance",
27+
expected_valid_urls,
28+
expected_invalid_urls
29+
)
30+
31+
context "using XML" do
32+
expected_valid_urls.each do |valid_url|
33+
context "given the valid URL #{valid_url}" do
34+
describe ".get" do
35+
it "should encounter a 400 error" do
36+
expect {
37+
provider_class.get(valid_url, :format=>:xml)
38+
}.to raise_error(OEmbed::UnknownResponse, /\b400\b/)
39+
end
40+
end
41+
end
42+
end
43+
end
44+
end

spec/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
require 'rubygems'
2+
23
require 'vcr'
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
39

410
require 'coveralls'
511
Coveralls.wear!
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
RSpec.shared_examples "an OEmbed::Proviers instance" do |expected_valid_urls, expected_invalid_urls|
2+
expected_valid_urls.each do |valid_url|
3+
context "given the valid URL #{valid_url}" do
4+
describe ".include?" do
5+
it "should be true" do
6+
expect(provider_class.include?(valid_url)).to be_truthy
7+
end
8+
end
9+
10+
describe ".get" do
11+
it "should return a response" do
12+
response = nil
13+
expect {
14+
response = provider_class.get(valid_url)
15+
}.to_not raise_error
16+
expect(response).to be_a(OEmbed::Response)
17+
end
18+
end
19+
end
20+
end
21+
22+
expected_invalid_urls.each do |invalid_url|
23+
context "given the invalid URL #{invalid_url}" do
24+
describe ".include?" do
25+
it "should be false" do
26+
expect(provider_class.include?(invalid_url)).to be_falsey
27+
end
28+
end
29+
30+
describe ".get" do
31+
it "should not find a response" do
32+
expect {
33+
provider_class.get(invalid_url)
34+
}.to raise_error(OEmbed::NotFound)
35+
end
36+
end
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)