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