require 'test/unit' require './BsBot' require 'fileutils' class TestMyBot < Test::Unit::TestCase def setup if File.exist?('bsagent.rb') FileUtils.copy('bsagent.rb', 'bsagent.rb.save') begin FileUtils.copy('bsagent-api.yaml', 'bsagent-api.yaml.save') rescue; end end @agent = MyBot.new end def test_name actual, s = @agent.send("what is your name?") assert_match(/bsbot/, actual) end def test_volume actual, s = @agent.send("BsBot: what is your volume?") assert_match(/1/, actual) end def test_rules actual, s = @agent.send("BsBot: loud") assert_match(/0/, actual) actual, s = @agent.send("BsBot: if response =~ /default response/i then response = 'foo!' end") assert_match(/Okay/, actual) actual, s = @agent.send("testing") assert_match(/foo!/, actual) actual, s = @agent.send("BsBot: if response =~ /foo!/ then response = 'bar' end") assert_match(/Okay/, actual) actual, s = @agent.send("testing") assert_match(/bar/, actual) actual, s = @agent.send("BsBot: delete rule 1") assert_match(/Okay/, actual) actual, s = @agent.send("testing") assert_match(/default response/i, actual) actual, s = @agent.send("BsBot: if response =~ /default response/i then response = 'fubar' end") assert_match(/Okay/, actual) actual, s = @agent.send("testing") assert_match(/fubar/, actual) actual, s = @agent.send("BsBot: delete all rules") assert_match(/Okay/, actual) actual, s = @agent.send("BsBot: show rules") assert_match(//, actual) actual, s = @agent.send("testing") assert_match(/Default response/, actual) actual, s = @agent.send("what is the debug mode?") assert_match(/off/i, actual) actual, s = @agent.send("bsbot: turn debug mode on") assert_match(/on/i, actual) actual, s = @agent.send("bsbot: what is the debug mode?") assert_match(/on/i, actual) actual, s = @agent.send("bsbot: please turn off the debug mode.") assert_match(/off/i, actual) actual, s = @agent.send("bsbot: what is the debug mode?") assert_match(/off/i, actual) end def test_draw_side_by_side actual, s = @agent.send("Bank: your assets are Loan and your liabilities are Deposit") actual, s = @agent.send("Person: your assets are Deposit and your liabilities are Loan") actual, s = @agent.send("Draw Bank and Person balance sheets side-by-side") puts actual assert_match(/.*Bank *Person/, actual) end def teardown File.delete('bsagent.rb') unless !File.exist?('bsagent.rb.save') begin; File.delete('bsagent-api.yaml'); rescue; end if File.exist?('bsagent.rb.save') FileUtils.copy('bsagent.rb.save', 'bsagent.rb') begin; FileUtils.copy('bsagent-api.yaml.save', 'bsagent-api.yaml'); rescue; end end if File.exist?('bsagent.rb') then File.delete('bsagent.rb.save') end if File.exist?('bsagent-api.yaml.save') then File.delete('bsagent-api.yaml.save') end end end