require 'test/unit' require 'todobot' require 'fileutils' class TestMyBot < Test::Unit::TestCase def setup if File.exist?('todoagent.rb') FileUtils.copy('todoagent.rb', 'todoagent.rb.save') begin FileUtils.copy('todoagent-api.yaml', 'todoagent-api.yaml.save') rescue; end end @agent = MyBot.new end def test_name actual, s = @agent.send("what is your name?") assert_match(/todobot/i, actual) end def test_volume actual, s = @agent.send("ToDoBot: what is your volume?") assert_match(/1/, actual) end def test_rules actual, s = @agent.send("TODOBot: loud") assert_match(/0/, actual) actual, s = @agent.send("todobot: 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("TODOAGEnT: if response =~ /foo!/ then response = 'bar' end") assert_match(/Okay/, actual) actual, s = @agent.send("testing") assert_match(/bar/, actual) actual, s = @agent.send("todoagent: delete rule 1") assert_match(/Okay/, actual) actual, s = @agent.send("testing") assert_match(/default response/i, actual) actual, s = @agent.send("ToDoAgent: 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("ToDoAgent: delete all rules") assert_match(/Okay/, actual) actual, s = @agent.send("TodoAgent: show rules") assert_match(//, actual) actual, s = @agent.send("testing") assert_match(/Default response/, actual) end def teardown File.delete('todoagent.rb') unless !File.exist?('todoagent.rb.save') begin; File.delete('todoagent-api.yaml'); rescue; end if File.exist?('todoagent.rb.save') FileUtils.copy('todoagent.rb.save', 'todoagent.rb') begin; FileUtils.copy('todoagent-api.yaml.save', 'todoagent-api.yaml'); rescue; end end if File.exist?('todoagent.rb') then File.delete('todoagent.rb.save') end if File.exist?('todoagent-api.yaml.save') then File.delete('todoagent-api.yaml.save') end end end