Compare commits

...

4 Commits

Author SHA1 Message Date
6612483ac4 Cleanup 2025-08-16 15:59:40 -04:00
9df060a124 Lesson test 2025-08-16 15:57:52 -04:00
6a2a00541c Add Rake test 2025-08-16 15:47:13 -04:00
3d9e1e51c4 Tests for ika 2025-08-16 15:47:08 -04:00
6 changed files with 61 additions and 9 deletions

3
Rakefile Normal file
View File

@ -0,0 +1,3 @@
require "minitest/test_task"
Minitest::TestTask.create # named test, sensible defaults

View File

@ -11,7 +11,6 @@ module Commands
class Command
def self.inherited(klass)
p klass
Commands.register_command klass
end

View File

@ -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

34
test/test_ika.rb Normal file
View File

@ -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

22
test/test_lesson.rb Normal file
View File

@ -0,0 +1,22 @@
require_relative "../lib/lesson"
require "minitest/autorun"
class TestLesson < Minitest::Test
def setup
@lesson = Lesson.new [[0.1 / 60, "test the thing"], [0.1 / 60, "finish testing"]]
end
def test_start
@channel = Minitest::Mock.new
@channel.expect(:send_message, nil) { |msg| msg.include? "to test the thing" }
@channel.expect(:send_message, nil) { |msg| msg.include? "to finish testing" }
@channel.expect(:send_message, nil) { |msg| msg == "Lesson over!" }
assert_equal false, @lesson.running
@lesson.start!(@channel)
sleep(0.5)
# gonna be impossible to thread this needle
# assert_equal true, @lesson.running
sleep(0.5)
assert_equal false, @lesson.running
end
end