Compare commits
4 Commits
24b5386b51
...
6612483ac4
Author | SHA1 | Date | |
---|---|---|---|
6612483ac4 | |||
9df060a124 | |||
6a2a00541c | |||
3d9e1e51c4 |
3
Rakefile
Normal file
3
Rakefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
require "minitest/test_task"
|
||||||
|
|
||||||
|
Minitest::TestTask.create # named test, sensible defaults
|
@ -11,7 +11,6 @@ module Commands
|
|||||||
|
|
||||||
class Command
|
class Command
|
||||||
def self.inherited(klass)
|
def self.inherited(klass)
|
||||||
p klass
|
|
||||||
Commands.register_command klass
|
Commands.register_command klass
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,11 +47,5 @@ class Ika
|
|||||||
end
|
end
|
||||||
|
|
||||||
return current_session&.respond_to message
|
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
|
||||||
end
|
end
|
||||||
|
@ -21,11 +21,11 @@ class KanaKanji
|
|||||||
@kanji = kanji || kana
|
@kanji = kanji || kana
|
||||||
end
|
end
|
||||||
|
|
||||||
def [] (index)
|
def [](index)
|
||||||
self.class.new kana[index], kanji[index]
|
self.class.new kana[index], kanji[index]
|
||||||
end
|
end
|
||||||
|
|
||||||
def + (other)
|
def +(other)
|
||||||
case other
|
case other
|
||||||
when String
|
when String
|
||||||
self.class.new kana + other, kanji + other
|
self.class.new kana + other, kanji + other
|
||||||
|
34
test/test_ika.rb
Normal file
34
test/test_ika.rb
Normal 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
22
test/test_lesson.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user