summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mock.rb23
-rw-r--r--test/plugins/test_note.rb40
2 files changed, 60 insertions, 3 deletions
diff --git a/test/mock.rb b/test/mock.rb
index 511daaba..ba6326db 100644
--- a/test/mock.rb
+++ b/test/mock.rb
@@ -1,7 +1,7 @@
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
$:.unshift File.join(File.dirname(__FILE__), '..')
-#require 'rbot/logger'
-#Irc::Bot::LoggerManager.instance.set_level(5)
+require 'rbot/logger'
+Irc::Bot::LoggerManager.instance.set_level(5)
module Irc
class Bot
@@ -14,11 +14,18 @@ end
class MockBot
- attr_reader :filters, :lang
+ attr_reader :filters, :lang, :messages
+ attr_accessor :config
def initialize
@filters = {}
+ @config = {}
@lang = Irc::Bot::Language.new(self, 'english')
+ @messages = []
+ end
+
+ def say(target, message)
+ @messages << [target, message]
end
def register_filter(name, &block)
@@ -51,11 +58,13 @@ class MockMessage
attr_reader :message
attr_reader :replies
attr_reader :channel
+ attr_reader :replyto
attr_reader :sourcenick
def initialize(message='', source='user')
@message = message
@sourcenick = source
+ @replyto = source
@channel = Irc::Channel.new('#test', '', ['bob'], server: nil)
@replies = []
end
@@ -64,9 +73,17 @@ class MockMessage
@replies << message
end
+ def okay
+ reply 'okay'
+ end
+
def public?
true
end
+
+ def private?
+ false
+ end
end
diff --git a/test/plugins/test_note.rb b/test/plugins/test_note.rb
new file mode 100644
index 00000000..b8320965
--- /dev/null
+++ b/test/plugins/test_note.rb
@@ -0,0 +1,40 @@
+$:.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 NotePluginTest < Test::Unit::TestCase
+ def setup
+ @bot = MockBot.new
+ @bot.config['note.private_message'] = false
+ manager = Irc::Bot::Plugins.manager
+ manager.bot_associate(@bot)
+ manager.load_botmodule_file('./data/rbot/plugins/note.rb')
+ @plugin = manager.get_plugin('note')
+ end
+
+ def test_note
+ assert_not_nil(@plugin)
+ assert_equal(@plugin.help(nil), 'note <nick> <string> => stores a note (<string>) for <nick>')
+
+
+ m = MockMessage.new
+ @plugin.note(m, {nick: 'AlIcE', string: 'Hello Alice!'})
+ assert_equal(1, m.replies.size)
+ assert_equal('okay', m.replies.first)
+
+ m = MockMessage.new('', 'Alice')
+ @plugin.message(m)
+ assert_equal(1, @bot.messages.size)
+ to, message = @bot.messages.first
+ assert_equal('Alice', to)
+ assert_match(/you have notes!/, message)
+ assert_match(/<user> Hello Alice!/, message)
+ end
+end