X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=test%2Fplugins%2Ftest_rot13.rb;h=aa4bb18576c11a4f335e679fbeb1e7e468d7b8fa;hb=b22038a43a626915c6f70debf63f732053309a75;hp=0727c77f4f67188f9c20f489a408eb603757dc70;hpb=ce800e5957045e05a8f270bd5caabf9cb83a8ba0;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/test/plugins/test_rot13.rb b/test/plugins/test_rot13.rb index 0727c77f..aa4bb185 100644 --- a/test/plugins/test_rot13.rb +++ b/test/plugins/test_rot13.rb @@ -25,6 +25,10 @@ class MockBot @filters[name] = block end + def filter(name, value) + @filters[name].call({text: value})[:text] + end + def path '' end @@ -35,24 +39,32 @@ class MockBot end +class MockMessage + attr_reader :messages + + def initialize + @messages = [] + end + + def reply(message) + @messages << message + end +end + + class PluginTest < Test::Unit::TestCase def setup - Irc::Bot::Plugins.manager.bot_associate(MockBot.new) - - # @plugin = RotPlugin.new(MockBot.new) - # require '' - plugin_module = Module.new - fname = './data/rbot/plugins/rot13.rb' - bindtextdomain_to(plugin_module, "rbot-#{File.basename(fname, '.rb')}") - plugin_string = IO.read(fname) - plugin_module.module_eval(plugin_string, fname) + manager = Irc::Bot::Plugins.manager + manager.bot_associate(MockBot.new) + manager.load_botmodule_file('./data/rbot/plugins/rot13.rb') + @plugin = manager.get_plugin('rot') end def test_rot13 - plugins = Irc::Bot::Plugins.manager.botmodules[:Plugin] - assert_equal(plugins.size, 1) - rot13 = plugins.first - - assert_equal(rot13.help(nil), "rot13 => encode to rot13 or back") + assert_not_nil(@plugin) + assert_equal(@plugin.help(nil), "rot13 => encode to rot13 or back") + m = MockMessage.new + @plugin.rot13(m, {string: 'Hello World'}) + assert_equal(m.messages.first, 'Uryyb Jbeyq') end end