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