forked from rb2k/viddl-rb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_spec.rb
53 lines (41 loc) · 1.96 KB
/
lib_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'
require 'minitest/autorun'
require 'rest_client'
require 'viddl-rb.rb'
class TestURLExtraction < MiniTest::Unit::TestCase
def test_can_get_single_youtube_url_and_filename
download_urls = ViddlRb.get_urls_names("http://www.youtube.com/watch?v=gZ8w4vVaOL8")
url = download_urls.first[:url]
name = download_urls.first[:name]
assert_equal("Nyan_Nyan_10_hours.mp4", name) # check that the name is correct
assert_match(/^http/, url) # check that the string starts with http
assert_match(/c.youtube.com\/videoplayback/, url) # check that we have the video playback string
Net::HTTP.get_response(URI(url)) do |res| # check that the location header is empty
assert_nil(res["location"])
break # break here because otherwise it will read the body for some reason (I think this is bug in Ruby)
end
end
def test_can_get_youtube_playlist
download_urls = ViddlRb.get_urls_names("http://www.youtube.com/playlist?list=PL41AAC84379472529")
assert(download_urls.size == 3)
end
def test_can_extract_extensions_from_url_names
download_urls = ViddlRb.get_urls_exts("http://www.dailymotion.com/video/x5ppy6_foot-2008-remi-gaillard_fun")
assert_equal(".mp4", download_urls.first[:ext])
end
def test_raises_download_error_when_video_cannot_be_downloaded
assert_raises(ViddlRb::DownloadError) do
ViddlRb.get_urls("http://www.youtube.com/watch?v=6TT19cB0NTM") # embedding is disabled for this video
end
end
def test_raises_plugin_error_when_plugin_fails
assert_raises(ViddlRb::PluginError) do
ViddlRb.get_urls("http://www.dailymotion.com/***/") # bogus url
end
end
def test_returns_nil_when_url_is_not_recognized
assert_nil(ViddlRb.get_urls("12345"))
assert_nil(ViddlRb.get_urls("http://www.google.com"))
end
end