From: Nat P. <np...@us...> - 2002-08-27 19:21:45
|
Update of /cvsroot/mockobjects/no-stone-unturned/rubysrc In directory usw-pr-cvs1:/tmp/cvs-serv30449 Added Files: addrservlet.rb server.rb tasks.txt test_addrservlet.rb Log Message: Added code of ruby example to CVS --- NEW FILE: addrservlet.rb --- require 'webrick' class AddressBookServlet < WEBrick::HTTPServlet::AbstractServlet def do_GET( request, response ) response['content-type'] = 'text/plain' response.body = 'no addresses found' end end --- NEW FILE: server.rb --- #!/usr/bin/ruby require 'webrick' require 'addrservlet' server = WEBrick::HTTPServer.new( :Port => 2000 ) server.mount( "/address", AddressBookServlet ) trap("INT") { server.shutdown } server.start --- NEW FILE: tasks.txt --- Stories 1) anyone can search the entries in the book. 2) anyone can add their name and email address to the book. 3) anyone can remove an entry from the book. Tasks 1a) accept a name and find no result DONE 1b) accept a name and return a result from a hard-coded collection. 1c) Retrieve the entries from a file, specified as a servlet property. Values are held in memory. --- NEW FILE: test_addrservlet.rb --- require 'test/unit' require 'webrick' require 'addrservlet' class MockRequest end class MockResponse include Test::Unit::Assertions def initialize @content_type_set = false @body_set = false end def []=( header, value ) assert_equal( 'content-type', header ) assert_match( /^text\/.*/, value ) @content_type_set = true end def body=( value ) assert_match( /no addresses found/, value ) @body_set = true end def _verify assert( "content-type", @content_type_set ) assert( "body", @body_set ) end end class AddressBookServletTest < Test::Unit::TestCase def test_no_addresses_found request = MockRequest.new response = MockResponse.new servlet = AddressBookServlet.new( {} ) servlet.do_GET( request, response ) response._verify end end |