changeset 458:507c0af598ba

improve Http.init_for_test
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 May 2015 12:29:37 -0600
parents 0ca5d1d6250b
children 30544d1a9cbf
files web/src/luan/modules/web/Http.luan
diffstat 1 files changed, 8 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
diff -r 0ca5d1d6250b -r 507c0af598ba web/src/luan/modules/web/Http.luan
--- a/web/src/luan/modules/web/Http.luan	Tue May 05 23:10:34 2015 -0600
+++ b/web/src/luan/modules/web/Http.luan	Wed May 06 12:29:37 2015 -0600
@@ -1,7 +1,4 @@
-local Luan = require "luan:Luan"
-local ipairs = Luan.ipairs
-local to_string = Luan.to_string
-local Table = require "luan:Table"
+local Io = require "luan:Io"
 require "luan:logging/Logging"  -- initialize logging
 
 
@@ -10,9 +7,12 @@
 function init_for_test()
 
 	function get_page(mod_name)
+		local old_out = Io.stdout
 		local mod = require("site:"..mod_name)
 		mod.service()
-		return Table.concat(result)
+		text_writer.close()
+		Io.stdout = old_out
+		return result.read_text()
 	end
 
 	cookies = cookies or {}
@@ -25,14 +25,9 @@
 	response = {
 
 		text_writer = function()
-			result = {}
-			return {
-				write = function(...)
-					for _, v in ipairs{...} do
-						result[#result+1] = to_string(v)
-					end
-				end;
-			}
+			result = Io.uri "string:"
+			text_writer = result.text_writer()
+			return text_writer
 		end;
 
 		set_cookie = function(name,value)