require_relative "../lib/ika" require "minitest/autorun" class TestHandler < Ika attr_reader :responses def initialize @responses = [] end def responder lambda { |response| @responses << response } end end class TestIka < Minitest::Test def setup @ika = TestHandler.new end def test_handle_command_message skip @command = Minitest::Mock.new @command.expect(:execute, nil) Commands::Command.stub(:for, @command) do |x| @ika.handle_message("msg") end assert_equal [], @ika.responses end def test_handle_normal_message skip @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 assert_equal [], @ika.responses end end