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