Skip to content
Extraits de code Groupes Projets
Valider 01bb05c5 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Plugin Youtube, test supplémentaire pour SitePlugin

parent 0ed7f553
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -14,7 +14,7 @@ class SitePlugin ...@@ -14,7 +14,7 @@ class SitePlugin
# Return the plugin that can handle a given site. # Return the plugin that can handle a given site.
def self.for_site(site) def self.for_site(site)
@@repository.find {|handler| handler.can_handle? site } @@repository.find { |handler| handler.can_handle? site }
end end
# A place holder method. This method *must* be implemented in the subclasses. # A place holder method. This method *must* be implemented in the subclasses.
......
require_relative '../lib/site_plugin.rb'
class YoutubePlugin < SitePlugin
def self.can_handle?(site)
site =~ /^http:\/\/((www.)?youtube.(fr|com)\/watch\?v=|youtu\.be\/)[a-zA-Z0-9]+$/
end
public
def get(url)
puts "Oh oh oh ! #{url}"
end
end
$LOAD_PATH << '../lib' require_relative '../lib/site_plugin.rb'
require 'site_plugin'
describe SitePlugin do describe SitePlugin do
describe 'inherance' do describe 'inherance' do
...@@ -25,4 +24,11 @@ describe SitePlugin do ...@@ -25,4 +24,11 @@ describe SitePlugin do
SitePlugin.for_site('OfCourseICanHandle_test_').nil?.should be_false SitePlugin.for_site('OfCourseICanHandle_test_').nil?.should be_false
end end
end end
describe '#can_handle?' do
it 'raise an exception' do
@siteplugin = SitePlugin.new
lambda { @siteplugin.can_handle?('test') }.should raise_error
end
end
end end
require_relative '../plugins/youtube_plugin.rb'
describe YoutubePlugin do
describe '.can_handle?' do
it 'true with "youtube.com"' do
YoutubePlugin.can_handle?('http://youtube.com/watch?v=Pb8VPYMgHlg').should be_true
end
it 'true with "www.youtube.com"' do
YoutubePlugin.can_handle?('http://www.youtube.com/watch?v=Pb8VPYMgHlg').should be_true
end
it 'true with "youtu.be"' do
YoutubePlugin.can_handle?('http://youtu.be/Pb8VPYMgHlg').should be_true
end
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter