Class: PluginTests
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- PluginTests
- Defined in:
- lib/wiki_lyrics/tests/plugin_tests.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cases ⇒ Object
- #check_response(response, request, site_name) ⇒ Object
- #check_suggestions(suggestions, request, site_name) ⇒ Object
- #lyrics_test_data ⇒ Object
- #plugin ⇒ Object
- #suggestions_test_data ⇒ Object
- #test_lyrics_direct_search ⇒ Object
- #test_lyrics_from_suggestions ⇒ Object
- #test_lyrics_full_search ⇒ Object
- #test_no_lyrics_found ⇒ Object
Class Method Details
.build_suite(plugin, cases) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 30 def self.build_suite( plugin, cases ) @@tmp_plugin = plugin @@tmp_cases = cases eval( "class #{plugin.class.name}Tests < PluginTests\n" + \ "@@plugin = @@tmp_plugin\n" + \ "@@cases = @@tmp_cases\n" + \ "def self.plugin()\n" + \ "return @@plugin\n" + \ "end\n" + \ "def self.cases()\n" + \ "return @@cases\n" + \ "end\n" + \ "end" ) return eval( "#{plugin.class.name}Tests.suite()" ) end |
Instance Method Details
#cases ⇒ Object
52 53 54 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 52 def cases() return self.class.cases() end |
#check_response(response, request, site_name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 90 def check_response( response, request, site_name ) [response.artist.to_s(), response.title.to_s(), response.album.to_s()].each() do || assert_nil( .downcase().index( "lyrics" ), "Lyrics metadata for #{request.title} by #{request.artist} returned by #{site_name} contains the 'lyrics' word" ) end assert_not_nil( response.lyrics, "No lyrics for #{request.title} by #{request.artist} returned by #{site_name}" ) assert( ! response.lyrics.strip().empty?, "Empty lyrics for #{request.title} by #{request.artist} returned by #{site_name}" ) # assert( # response.lyrics.include?( "\n" ), # "Lyrics for #{request.title} by #{request.artist} returned by #{site_name} don't have any line breaks" # ) md = /<\/?(a|h[1-6]|hr|p|br|body|html|span|div|br|script|!?--) *\/?>*/i.match( response.lyrics ) assert_nil( md, "Lyrics for #{request.title} by #{request.artist} returned" + \ " by #{site_name} contains unexpected HTML tags: #{md ? md[1] : ""}" ) end |
#check_suggestions(suggestions, request, site_name) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 72 def check_suggestions( suggestions, request, site_name ) assert_not_nil( suggestions, "No suggestions for #{request.title} by #{request.artist} returned by #{site_name}" ) assert( ! suggestions.empty?, "Empty suggestions list for #{request.title} by #{request.artist} returned by #{site_name}" ) suggestions.each() do |suggestion| sugg = { "artist" => suggestion.artist, "title" => suggestion.title } sugg.each() do |key, value| assert_nil( value.downcase().index( "lyrics" ), "Suggestions for #{request.title} by #{request.artist} returned by #{site_name} contains the 'lyrics' word (#{value})" ) assert( value == HTMLEntities.decode( value ), "Suggestions for #{request.title} by #{request.artist} returned by #{site_name} contains unexpected HTML entities (#{value})" ) end end end |
#lyrics_test_data ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 56 def lyrics_test_data() test_data = plugin().lyrics_test_data() return test_data if ! cases() || cases().empty? test_data2 = [] cases().each() { |index| test_data2 << test_data[index] if test_data[index] } return test_data2 end |
#plugin ⇒ Object
48 49 50 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 48 def plugin() return self.class.plugin() end |
#suggestions_test_data ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 64 def suggestions_test_data() test_data = plugin().suggestions_test_data() return test_data if ! cases() || cases().empty? test_data2 = [] cases().each() { |index| test_data2 << test_data[index] if test_data[index] } return test_data2 end |
#test_lyrics_direct_search ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 117 def test_lyrics_direct_search() puts "\nTesting #{plugin().site_name()} lyrics direct search..." lyrics_test_data().each() do |request| fetch_data = plugin().build_lyrics_fetch_data( request ) if fetch_data.url puts " - searching lyrics for #{request.title} by #{request.artist}" response = plugin().lyrics_direct_search( request ) check_response( response, request, plugin.site_name() ) else puts " - skipping lyrics search for #{request.title} by #{request.artist} (no direct fetch data received)" break end end end |
#test_lyrics_from_suggestions ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 132 def test_lyrics_from_suggestions() puts "\nTesting #{plugin().site_name()} lyrics from suggestions..." suggestions_test_data().each() do |request| puts " - searching suggestions for #{request.title} by #{request.artist}" suggestions = plugin().suggestions( request ) check_suggestions( suggestions, request, plugin.site_name() ) puts " - searching lyrics to #{request.title} by #{request.artist} in suggestions" response, suggestions = plugin().lyrics_from_suggestions( request, suggestions ) check_response( response, request, plugin.site_name() ) end end |
#test_lyrics_full_search ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 144 def test_lyrics_full_search() puts "\nTesting #{plugin().site_name()} lyrics full search..." lyrics_test_data().each() do |request| puts " - searching lyrics for #{request.title} by #{request.artist}" response = plugin().lyrics_full_search( request ) check_response( response, request, plugin.site_name() ) end end |
#test_no_lyrics_found ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/wiki_lyrics/tests/plugin_tests.rb', line 153 def test_no_lyrics_found() puts "\nTesting #{plugin().site_name()} forced retrieval fail..." request = Lyrics::Request.new( "Fake Artist", "Fake Title", "Fake Album" ) puts " - searching lyrics for #{request.title} by #{request.artist}" response = plugin().lyrics_full_search( request ) assert_nil( response.lyrics, "Unexpected lyrics returned for #{request.title} by #{request.artist} by #{plugin.site_name()}" ) end |