summaryrefslogtreecommitdiff
path: root/test/plugins
diff options
context:
space:
mode:
authorMatthias Hecker <mail@apoc.cc>2020-04-06 20:20:32 +0200
committerMatthias Hecker <mail@apoc.cc>2020-04-06 20:20:32 +0200
commit618df277b7cb7d160ba5c86d1a22298a4741ed5f (patch)
tree8e709db0e57559a0e1aa06eae886a770c80c17a2 /test/plugins
parent628bf10d8ad8536b98b85c529fe92e8ac56a9c4d (diff)
tests: mocked bot and messages added, added points tests
Diffstat (limited to 'test/plugins')
-rw-r--r--test/plugins/test_points.rb44
-rw-r--r--test/plugins/test_rot13.rb53
2 files changed, 49 insertions, 48 deletions
diff --git a/test/plugins/test_points.rb b/test/plugins/test_points.rb
new file mode 100644
index 00000000..f1a7479d
--- /dev/null
+++ b/test/plugins/test_points.rb
@@ -0,0 +1,44 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
+$:.unshift File.join(File.dirname(__FILE__), '..', '..')
+
+require 'test/unit'
+require 'test/mock'
+
+require 'rbot/ircbot'
+require 'rbot/registry'
+require 'rbot/plugins'
+require 'rbot/language'
+
+class PointsPluginTest < Test::Unit::TestCase
+ def setup
+ manager = Irc::Bot::Plugins.manager
+ manager.bot_associate(MockBot.new)
+ manager.load_botmodule_file('./data/rbot/plugins/points.rb')
+ @plugin = manager.get_plugin('points')
+ end
+
+ def test_points
+ assert_not_nil(@plugin)
+ assert_not_empty(@plugin.help(nil))
+
+ m = MockMessage.new('linux++', 'user')
+ @plugin.message(m)
+ assert_equal('linux now has 1 points!', m.replies.first)
+
+ m = MockMessage.new('linux++', 'user')
+ @plugin.message(m)
+ assert_equal('linux now has 2 points!', m.replies.first)
+
+ m = MockMessage.new('linux++', 'linux')
+ @plugin.message(m)
+ assert_empty(m.replies)
+
+ m = MockMessage.new('', 'user')
+ @plugin.points(m, key: 'linux')
+ assert_equal('points for linux: 2', m.replies.first)
+
+ m = MockMessage.new('', 'linux')
+ @plugin.points(m, {})
+ assert_equal('points for linux: 2', m.replies.first)
+ end
+end
diff --git a/test/plugins/test_rot13.rb b/test/plugins/test_rot13.rb
index aa4bb185..fafb58ba 100644
--- a/test/plugins/test_rot13.rb
+++ b/test/plugins/test_rot13.rb
@@ -1,57 +1,14 @@
-$:.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
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
+$:.unshift File.join(File.dirname(__FILE__), '..', '..')
require 'test/unit'
+require 'test/mock'
+
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 filter(name, value)
- @filters[name].call({text: value})[:text]
- end
-
- def path
- ''
- end
-
- def registry_factory
- Irc::Bot::Registry.new('tc')
- end
-end
-
-
-class MockMessage
- attr_reader :messages
-
- def initialize
- @messages = []
- end
-
- def reply(message)
- @messages << message
- end
-end
-
-
class PluginTest < Test::Unit::TestCase
def setup
manager = Irc::Bot::Plugins.manager
@@ -65,6 +22,6 @@ class PluginTest < Test::Unit::TestCase
assert_equal(@plugin.help(nil), "rot13 <string> => encode <string> to rot13 or back")
m = MockMessage.new
@plugin.rot13(m, {string: 'Hello World'})
- assert_equal(m.messages.first, 'Uryyb Jbeyq')
+ assert_equal(m.replies.first, 'Uryyb Jbeyq')
end
end