require 'test/unit' require 'MyAgent' require 'fileutils' class TestMyAgent < Test::Unit::TestCase def setup if File.exist?('MyAgent.rb') FileUtils.copy('MyAgent.rb', 'MyAgent.rb.save') begin FileUtils.copy('MyAgent-api.yaml', 'MyAgent-api.yaml.save') rescue; end end @agent = MyAgent.new end def test_defining_hello actual, s = @agent.send("add pattern /^hello/, hello") actual, s = @agent.send("hello") actual, s = @agent.send("> def hello(pattern=nil, input=nil)") actual, s = @agent.send("> if @count == nil; @count = 1; return 'I am ready for my first lesson.'; end") actual, s = @agent.send("> return 'Hello again.'") actual, s = @agent.send("> end # method_def") actual, s = @agent.send("hello") assert_match(/lesson/, actual) actual, s = @agent.send("hi is a synonym for hello") assert_match(/Okay/, actual) actual, s = @agent.send("hi") assert_match(/again/, actual) end def test_show_api actual, s = @agent.send("show api") assert_match(/ is a synonym for /, actual) end def test_show_one_method_api actual, s = @agent.send("show show_api's api") assert_match(/show api/, actual) end def teardown File.delete('MyAgent.rb') unless !File.exist?('MyAgent.rb.save') begin; File.delete('MyAgent-api.yaml'); rescue; end if File.exist?('MyAgent.rb.save') FileUtils.copy('MyAgent.rb.save', 'MyAgent.rb') begin; FileUtils.copy('MyAgent-api.yaml.save', 'MyAgent-api.yaml'); rescue; end end if File.exist?('MyAgent.rb') then File.delete('MyAgent.rb.save') end if File.exist?('MyAgent-api.yaml.save') then File.delete('MyAgent-api.yaml.save') end end end