diff --git a/lib/ika.rb b/lib/ika.rb index 788b0d3..438615d 100644 --- a/lib/ika.rb +++ b/lib/ika.rb @@ -47,11 +47,5 @@ class Ika end return current_session&.respond_to message - - if message.message.content == "!init" - return message.respond("There's already a session running") unless current_session.nil? - - return current_session = Session.new(message, event.message.author) - end end end diff --git a/test/test_ika.rb b/test/test_ika.rb new file mode 100644 index 0000000..587b93e --- /dev/null +++ b/test/test_ika.rb @@ -0,0 +1,34 @@ +require_relative "../lib/ika" +require "minitest/autorun" + +class TestIka < Minitest::Test + def setup + @bot = Minitest::Mock.new + @ika = Ika.new @bot + end + + def test_start + @bot.expect(:message, nil) + @bot.expect(:run, nil) + @ika.start! + end + + def test_handle_command_message + @command = Minitest::Mock.new + @command.expect(:execute, nil) + Commands::Command.stub(:for, @command) do |x| + @ika.handle_message("msg") + end + end + + def test_handle_normal_message + @ika.current_session = Minitest::Mock.new + @command = Commands::Command.new(nil, nil) + Commands::Command.stub(:for, nil) do |x| + @command.stub(:execute, -> { raise "#execute was called" }) do |x| + @ika.current_session.expect(:respond_to, nil) { |x| x == "msg" } + @ika.handle_message("msg") + end + end + end +end