]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
test: first plugin test added for rot13
authorMatthias Hecker <mail@apoc.cc>
Mon, 30 Mar 2020 21:46:19 +0000 (23:46 +0200)
committerMatthias Hecker <mail@apoc.cc>
Mon, 30 Mar 2020 21:54:04 +0000 (23:54 +0200)
tasks/test.rake
test/plugins/test_rot13.rb [new file with mode: 0644]

index b7939f71d2bbffa93b3aeffe5c5fbbc003a977aa..b923118b3c646f376fd7e155c5ed73d410fcaddd 100644 (file)
@@ -3,6 +3,6 @@ require 'rake'
 
 Rake::TestTask.new do |t|
   t.libs << "test"
-  t.test_files = FileList['test/test_*.rb']
+  t.test_files = FileList['test/test_*.rb'] + FileList['test/plugins/test_*.rb']
   t.verbose = true
 end
diff --git a/test/plugins/test_rot13.rb b/test/plugins/test_rot13.rb
new file mode 100644 (file)
index 0000000..0727c77
--- /dev/null
@@ -0,0 +1,58 @@
+$:.unshift File.join(File.dirname(__FILE__), '../lib')
+
+module Irc
+class Bot
+  module Config
+    @@datadir = File.expand_path(File.dirname($0) + '/../data/rbot')
+    @@coredir = File.expand_path(File.dirname($0) + '/../lib/rbot/core')
+  end
+end
+end
+
+require 'test/unit'
+require 'rbot/ircbot'
+require 'rbot/registry'
+require 'rbot/plugins'
+
+
+class MockBot
+  attr_reader :filters
+  def initialize
+    @filters = {}
+  end
+
+  def register_filter(name, &block)
+    @filters[name] = block
+  end
+
+  def path
+    ''
+  end
+
+  def registry_factory
+    Irc::Bot::Registry.new('tc')
+  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)
+  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 <string> => encode <string> to rot13 or back")
+  end
+end