ruby-web 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. data/ChangeLog +474 -0
  2. data/INSTALL.txt +9 -0
  3. data/InstalledFiles +180 -0
  4. data/LICENSE.txt +74 -0
  5. data/Rakefile +529 -0
  6. data/TODO +65 -0
  7. data/doc/additional.xml +149 -0
  8. data/doc/core.xml +652 -0
  9. data/doc/credits/index.xml +52 -0
  10. data/doc/credits/php.contributors.xml +118 -0
  11. data/doc/credits/php.language-snippets.ent +622 -0
  12. data/doc/install/index.xml +136 -0
  13. data/doc/install/mac/index.xml +21 -0
  14. data/doc/install/ruby-web.install.rb.instructions.xml +7 -0
  15. data/doc/install/unix/index.xml +46 -0
  16. data/doc/install/win/apache1.xml +166 -0
  17. data/doc/install/win/apache2.xml +141 -0
  18. data/doc/install/win/iis.xml +162 -0
  19. data/doc/install/win/index.xml +24 -0
  20. data/doc/install/win/installer.xml +31 -0
  21. data/doc/install/win/manual.xml +43 -0
  22. data/doc/manual.xml +69 -0
  23. data/doc/old/apache_cgi.txt +23 -0
  24. data/doc/old/fastcgi.txt +23 -0
  25. data/doc/old/mod_ruby.txt +21 -0
  26. data/doc/old/snippets.rdoc +183 -0
  27. data/doc/old/webrick.txt +23 -0
  28. data/doc/old/windows_cgi.txt +9 -0
  29. data/doc/tutorial.xml +14 -0
  30. data/doc/xsl/manual-multi.xsl +10 -0
  31. data/doc/xsl/manual-pdf.xsl +6 -0
  32. data/doc/xsl/manual-single.xsl +6 -0
  33. data/doc/xsl/manual.css +22 -0
  34. data/install.rb +1022 -0
  35. data/lib/formatter.rb +314 -0
  36. data/lib/html-parser.rb +429 -0
  37. data/lib/htmlrepair.rb +113 -0
  38. data/lib/htmlsplit.rb +842 -0
  39. data/lib/sgml-parser.rb +332 -0
  40. data/lib/web.rb +68 -0
  41. data/lib/web/assertinclude.rb +129 -0
  42. data/lib/web/config.rb +50 -0
  43. data/lib/web/connection.rb +1070 -0
  44. data/lib/web/convenience.rb +154 -0
  45. data/lib/web/formreader.rb +318 -0
  46. data/lib/web/htmlparser/html-parser.rb +429 -0
  47. data/lib/web/htmlparser/sgml-parser.rb +332 -0
  48. data/lib/web/htmltools/element.rb +296 -0
  49. data/lib/web/htmltools/stparser.rb +276 -0
  50. data/lib/web/htmltools/tags.rb +286 -0
  51. data/lib/web/htmltools/tree.rb +139 -0
  52. data/lib/web/htmltools/xmltree.rb +160 -0
  53. data/lib/web/htmltools/xpath.rb +71 -0
  54. data/lib/web/info.rb +63 -0
  55. data/lib/web/load.rb +210 -0
  56. data/lib/web/mime.rb +87 -0
  57. data/lib/web/phprb.rb +340 -0
  58. data/lib/web/resources/test/cookie.rb +33 -0
  59. data/lib/web/resources/test/counter.rb +20 -0
  60. data/lib/web/resources/test/multipart.rb +14 -0
  61. data/lib/web/resources/test/redirect.rb +8 -0
  62. data/lib/web/resources/test/stock.rb +33 -0
  63. data/lib/web/sapi/apache.rb +129 -0
  64. data/lib/web/sapi/fastcgi.rb +22 -0
  65. data/lib/web/sapi/install/apache.rb +180 -0
  66. data/lib/web/sapi/install/iis.rb +93 -0
  67. data/lib/web/sapi/install/macosx.rb +90 -0
  68. data/lib/web/sapi/webrick.rb +86 -0
  69. data/lib/web/session.rb +83 -0
  70. data/lib/web/shim/cgi.rb +129 -0
  71. data/lib/web/shim/rails.rb +175 -0
  72. data/lib/web/stringio.rb +78 -0
  73. data/lib/web/strscanparser.rb +24 -0
  74. data/lib/web/tagparser.rb +96 -0
  75. data/lib/web/testing.rb +666 -0
  76. data/lib/web/traceoutput.rb +75 -0
  77. data/lib/web/unit.rb +56 -0
  78. data/lib/web/upload.rb +59 -0
  79. data/lib/web/validate.rb +52 -0
  80. data/lib/web/wiki.rb +557 -0
  81. data/lib/web/wiki/linker.rb +72 -0
  82. data/lib/web/wiki/page.rb +201 -0
  83. data/lib/webunit.rb +27 -0
  84. data/lib/webunit/assert.rb +152 -0
  85. data/lib/webunit/converter.rb +154 -0
  86. data/lib/webunit/cookie.rb +118 -0
  87. data/lib/webunit/domwalker.rb +185 -0
  88. data/lib/webunit/exception.rb +14 -0
  89. data/lib/webunit/form.rb +116 -0
  90. data/lib/webunit/frame.rb +37 -0
  91. data/lib/webunit/htmlelem.rb +122 -0
  92. data/lib/webunit/image.rb +26 -0
  93. data/lib/webunit/jscript.rb +31 -0
  94. data/lib/webunit/link.rb +33 -0
  95. data/lib/webunit/params.rb +321 -0
  96. data/lib/webunit/parser.rb +229 -0
  97. data/lib/webunit/response.rb +464 -0
  98. data/lib/webunit/runtest.rb +41 -0
  99. data/lib/webunit/table.rb +148 -0
  100. data/lib/webunit/testcase.rb +45 -0
  101. data/lib/webunit/ui/cui/testrunner.rb +50 -0
  102. data/lib/webunit/utils.rb +68 -0
  103. data/lib/webunit/webunit.rb +28 -0
  104. data/test/dev/action.rb +83 -0
  105. data/test/dev/forms.rb +104 -0
  106. data/test/dev/forms2.rb +104 -0
  107. data/test/dev/parser.rb +17 -0
  108. data/test/dev/scripts/dump.rb +24 -0
  109. data/test/dev/scripts/makedist.rb +62 -0
  110. data/test/dev/scripts/uri.rb +41 -0
  111. data/test/dev/scripts/uri/common.rb +432 -0
  112. data/test/dev/scripts/uri/ftp.rb +149 -0
  113. data/test/dev/scripts/uri/generic.rb +1106 -0
  114. data/test/dev/scripts/uri/http.rb +76 -0
  115. data/test/dev/scripts/uri/https.rb +26 -0
  116. data/test/dev/scripts/uri/ldap.rb +238 -0
  117. data/test/dev/scripts/uri/mailto.rb +260 -0
  118. data/test/dev/scripts/urireg.rb +174 -0
  119. data/test/dev/simpledispatcher.rb +156 -0
  120. data/test/dev/test.action.rb +146 -0
  121. data/test/dev/test.formreader.rb +463 -0
  122. data/test/dev/test.simpledispatcher.rb +186 -0
  123. data/test/dev/webunit/conv/digit-0.rb +21 -0
  124. data/test/dev/webunit/conv/digit-1.rb +17 -0
  125. data/test/dev/webunit/conv/digit.rb +23 -0
  126. data/test/dev/webunit/conv/test_digit-0.rb +16 -0
  127. data/test/dev/webunit/conv/test_digit-1.rb +19 -0
  128. data/test/dev/webunit/conv/test_digit.rb +26 -0
  129. data/test/dev/webunit/conv/test_digit_view-0.rb +76 -0
  130. data/test/dev/webunit/conv/test_digit_view-1.rb +102 -0
  131. data/test/dev/webunit/conv/test_digit_view.rb +134 -0
  132. data/test/installation/htdocs/cgi_test.rb +296 -0
  133. data/test/installation/htdocs/test_install.rb +4 -0
  134. data/test/installation/runwebtest.rb +5 -0
  135. data/test/installation/test_cookie.rb +128 -0
  136. data/test/installation/test_form.rb +47 -0
  137. data/test/installation/test_multipart.rb +51 -0
  138. data/test/installation/test_request.rb +24 -0
  139. data/test/installation/test_response.rb +35 -0
  140. data/test/unit/htdocs/cookie.rb +32 -0
  141. data/test/unit/htdocs/multipart.rb +28 -0
  142. data/test/unit/htdocs/redirect.rb +12 -0
  143. data/test/unit/htdocs/simple.rb +13 -0
  144. data/test/unit/htdocs/stock.rb +33 -0
  145. data/test/unit/test_assert.rb +162 -0
  146. data/test/unit/test_cookie.rb +114 -0
  147. data/test/unit/test_domwalker.rb +77 -0
  148. data/test/unit/test_form.rb +42 -0
  149. data/test/unit/test_frame.rb +40 -0
  150. data/test/unit/test_htmlelem.rb +74 -0
  151. data/test/unit/test_image.rb +45 -0
  152. data/test/unit/test_jscript.rb +57 -0
  153. data/test/unit/test_link.rb +85 -0
  154. data/test/unit/test_multipart.rb +51 -0
  155. data/test/unit/test_params.rb +210 -0
  156. data/test/unit/test_parser.rb +53 -0
  157. data/test/unit/test_response.rb +150 -0
  158. data/test/unit/test_table.rb +70 -0
  159. data/test/unit/test_utils.rb +106 -0
  160. data/test/unit/test_webunit.rb +28 -0
  161. data/test/web/mod_ruby_stub.rb +39 -0
  162. data/test/web/test.assertinclude.rb +109 -0
  163. data/test/web/test.buffer.rb +182 -0
  164. data/test/web/test.code.loader.rb +78 -0
  165. data/test/web/test.config.rb +31 -0
  166. data/test/web/test.error.handling.rb +91 -0
  167. data/test/web/test.formreader-2.0.rb +352 -0
  168. data/test/web/test.load.rb +125 -0
  169. data/test/web/test.mime-type.rb +23 -0
  170. data/test/web/test.narf.cgi.rb +106 -0
  171. data/test/web/test.phprb.rb +239 -0
  172. data/test/web/test.request.rb +368 -0
  173. data/test/web/test.response.rb +637 -0
  174. data/test/web/test.ruby-web.rb +10 -0
  175. data/test/web/test.session.rb +50 -0
  176. data/test/web/test.shim.cgi.rb +96 -0
  177. data/test/web/test.tagparser.rb +65 -0
  178. data/test/web/test.template2.rb +297 -0
  179. data/test/web/test.testing2.rb +318 -0
  180. data/test/web/test.upload.rb +45 -0
  181. data/test/web/test.validate.rb +46 -0
  182. data/test/web/test.web.test.rb +495 -0
  183. data/test/wiki/test.history.rb +297 -0
  184. data/test/wiki/test.illustration_page.rb +287 -0
  185. data/test/wiki/test.linker.rb +197 -0
  186. data/test/wiki/test.tarpit.rb +56 -0
  187. data/test/wiki/test.wiki.rb +300 -0
  188. data/test/wikitestroot/admin.rb +7 -0
  189. data/test/wikitestroot/wiki.rb +6 -0
  190. metadata +234 -0
@@ -0,0 +1,10 @@
1
+ class TestRubyWeb < Test::Unit::TestCase
2
+ def test_parse_options
3
+ args = ['ruby-web', '-a', '-b', '--something', '--', 'program', 'program opt']
4
+ switches = Web::argv_switches( args )
5
+ assert_equal( ['-a', '-b', '--something'], switches )
6
+ assert_equal( ['program', 'program opt'], args )
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,50 @@
1
+ class TestSession < Test::Unit::TestCase
2
+ def test_session_ids_are_uniq
3
+ assert_equal( 1000, Array.new( 1000 ).collect {
4
+ Web::Session.create_id
5
+ }.uniq.length )
6
+ end
7
+
8
+ def test_set_value_on_session
9
+ cgi = Web::Connection.new( :out => "" )
10
+ cgi.session["testvar"] = "test"
11
+ assert_equal( "test", cgi.session["testvar"] )
12
+ end
13
+
14
+ def test_session_end_to_end
15
+ cgi = Web::Connection.new( :out => "" )
16
+ cgi.session["key"] = ["value"]
17
+ session_id = cgi.cookies_sent["_session_id"]
18
+
19
+ Web::Connection.new( :out => "", :cookies => { "_session_id", session_id } )
20
+
21
+ assert_equal( ["value"], cgi.session["key"] )
22
+ end
23
+
24
+ def test_clear_session
25
+ cgi = Web::Connection.new( :out => "" )
26
+ cgi.session["aKey"] = "aValue"
27
+ cgi.close
28
+
29
+ session_id = cgi.cookies_sent["_session_id"]
30
+ Web::Connection.new( :out => "", :cookies => { "_session_id", session_id } )
31
+
32
+ cgi.session.reset
33
+ assert_nil( cgi.session["aKey"] )
34
+ end
35
+
36
+ def test_can_iterate_over_session
37
+ cgi = Web::Connection.new( :out => "" )
38
+ cgi.session["aKey"] = "1"
39
+ cgi.session["aKey2"] = "2"
40
+ cgi.close
41
+
42
+ values = []
43
+ cgi.session.each do |i,j|
44
+ values << j
45
+ end
46
+ assert_equal [ "1" , "2" ], values
47
+ end
48
+ end
49
+
50
+
@@ -0,0 +1,96 @@
1
+ require 'web/shim/cgi'
2
+
3
+ class TestCGIShim < Test::Unit::TestCase
4
+ include Web::Testing
5
+
6
+ def setup
7
+ @pwd = Dir.pwd
8
+ if File.exists?( temp_dir + "/test_dir/" )
9
+ rm_rf(temp_dir + "/test_dir")
10
+ end
11
+ Dir.mkdir(temp_dir + "/test_dir/")
12
+ Dir.chdir(temp_dir + "/test_dir/")
13
+ #@docroot = Web.get_docroot
14
+ #Web.set_docroot( temp_dir + "/test_dir/")
15
+ end
16
+
17
+ def teardown
18
+ Dir.chdir(@pwd)
19
+ rm_rf(temp_dir + "/test_dir")
20
+ #Web.set_docroot( @docroot )
21
+ end
22
+
23
+ def write_file file
24
+ File.open( temp_dir + "/test_dir/app.rb" , "w" ) do |f|
25
+ f.write <<-EOF
26
+ require 'web/shim/cgi'
27
+ cgi = CGI.new
28
+ require 'test/unit/assertions'
29
+ include Test::Unit::Assertions
30
+ EOF
31
+ f.write file
32
+ end
33
+ end
34
+
35
+ def test_single_params
36
+ write_file <<-EOF
37
+ assert_equal( 'Dave Thomas', cgi['name'] )
38
+ assert_equal( 'flexible', cgi['reason'] )
39
+ EOF
40
+
41
+ do_request( "app.rb",
42
+ 'name' => 'Dave Thomas',
43
+ 'reason' => 'flexible' )
44
+ end
45
+
46
+ def test_multiple_params
47
+ write_file <<-EOF
48
+ assert_equal( ['Dave Thomas'], cgi.params['name'] )
49
+ assert_equal( ['flexible',
50
+ 'transparent',
51
+ 'fun'],
52
+ cgi.params['reason'] )
53
+ cgi.params['name'] = [ cgi['name'].upcase ]
54
+ assert_equal( {'name' => ['DAVE THOMAS'],
55
+ 'reason' => ['flexible','transparent','fun'] },
56
+ cgi.params )
57
+ EOF
58
+
59
+ do_request( "app.rb",
60
+ 'name' => 'Dave Thomas',
61
+ 'reason' => ['flexible','transparent','fun'] )
62
+
63
+ end
64
+
65
+ def test_has_key?
66
+ write_file <<-EOF
67
+ assert_equal( true, cgi.has_key?('name') )
68
+ assert_equal( false, cgi.has_key?('age') )
69
+ EOF
70
+
71
+ do_request( "app.rb",
72
+ 'name' => 'Dave Thomas',
73
+ 'reason' => ['flexible','transparent','fun'] )
74
+ end
75
+
76
+ def test_escape
77
+ str = "Nicholas Payton/Trumpet & Flugel Horn"
78
+ esc = 'Nicholas+Payton%2FTrumpet+%26+Flugel+Horn'
79
+ assert_equal(esc, CGI.escape(str) )
80
+ assert_equal(str, CGI.unescape(str) )
81
+ end
82
+
83
+ def test_escapeHTML
84
+ str = 'a < 100 && b > 200'
85
+ esc = 'a &lt; 100 &amp;&amp; b &gt; 200'
86
+ assert_equal(esc, CGI.escapeHTML(str) )
87
+ assert_equal(str, CGI.unescapeHTML(esc) )
88
+ end
89
+
90
+ def test_escapeElement
91
+ str = '<hr><a href="/mp3">Click Here</a><br>'
92
+ esc = '<hr>&lt;a href=&quot;/mp3&quot;&gt;Click Here&lt;/a&gt;<br>'
93
+ assert_equal( esc, CGI::escapeElement( str, 'A' ) )
94
+ assert_equal( str, CGI::unescapeElement( str, 'A' ) )
95
+ end
96
+ end
@@ -0,0 +1,65 @@
1
+ class TestAttributeParser < Test::Unit::TestCase
2
+ def test_test_no_attributes
3
+ block_used = false
4
+ StrScanParser.new(StringScanner.new("<narf:name>")).match_tag { |tag|
5
+ assert_equal( "name", tag.name )
6
+ assert_equal( {}, tag.attributes )
7
+ block_used = true
8
+ }
9
+ assert block_used
10
+ end
11
+
12
+ def test_test_one_attribute
13
+ block_used = false
14
+ StrScanParser.new(StringScanner.new("<narf:name foo=bar>")).match_tag { |tag|
15
+ assert_equal( "name", tag.name )
16
+ assert_equal( { "foo" => "bar" }, tag.attributes )
17
+ block_used = true
18
+ }
19
+ assert block_used
20
+ end
21
+
22
+ def test_quoted_value
23
+ block_used = false
24
+ StrScanParser.new(StringScanner.new("<narf:name foo=\"bar x\">")).match_tag{ |tag|
25
+ assert_equal( "name", tag.name )
26
+ assert_equal( { "foo" => "bar x" }, tag.attributes )
27
+ block_used = true
28
+ }
29
+ assert block_used
30
+ end
31
+
32
+ def test_test_two_attributes
33
+ block_used = false
34
+ StrScanParser.new(StringScanner.new("<narf:name foo=bar x=y>")).match_tag{|tag|
35
+ assert_equal( "name", tag.name )
36
+ assert_equal( { "foo" => "bar", "x" => "y" }, tag.attributes )
37
+ block_used = true
38
+ }
39
+ assert block_used
40
+ end
41
+
42
+ def test_test_unclosed_tag
43
+ assert_raises(TagNotClosedException) {
44
+ StrScanParser.new(StringScanner.new("<narf:name foo=bar x=y")).match_tag {}
45
+ }
46
+ end
47
+
48
+ def test_test_no_tag_name
49
+ assert_raises(TagNotNamedException) {
50
+ StrScanParser.new(StringScanner.new("<narf: name foo=bar x=y")).match_tag {}
51
+ }
52
+ end
53
+
54
+ def test_missing_attribute_value
55
+ assert_raises(MissingAttributeException) {
56
+ StrScanParser.new(StringScanner.new("<narf:name foo=")).match_tag {}
57
+ }
58
+ end
59
+
60
+ def test_missing_quote
61
+ assert_raises(MissingQuoteException) {
62
+ StrScanParser.new(StringScanner.new("<narf:name foo=\"foo}")).match_tag {}
63
+ }
64
+ end
65
+ end
@@ -0,0 +1,297 @@
1
+ module TemplateTestEnvironment
2
+ def get_test_dir
3
+ File.expand_path(File.join(temp_dir,"test_dir"))
4
+ end
5
+
6
+ def temp_file filename
7
+ File.expand_path(File.join(get_test_dir,"templates",filename))
8
+ end
9
+
10
+ def write_template contents, filename = "test.html"
11
+ File.open( File.expand_path(File.join(get_test_dir,"templates",filename)) ,"w") { | file | file.write contents }
12
+ end
13
+
14
+ def handle_request cgi, filename = "test.html"
15
+ cgi.print_template( filename, { "var" => cgi["displayVar"] } )
16
+ end
17
+
18
+ def setup_test_dir
19
+ Web::teardown
20
+ Web::setup
21
+
22
+ template_dir = File.expand_path((File.join("#{get_test_dir}","templates")))
23
+
24
+ unless Web::config[:load_path].include? template_dir
25
+ Web::config[:load_path] << template_dir
26
+ end
27
+
28
+ remove_test_dir
29
+ Dir.mkdir(get_test_dir)
30
+ Dir.mkdir(template_dir)
31
+
32
+ end
33
+
34
+ def remove_test_dir
35
+ if File.exists? get_test_dir
36
+ rm_rf(get_test_dir)
37
+ end
38
+ end
39
+
40
+ def write_file file, filename="app.rb"
41
+ File.open( File.expand_path(File.join("#{get_test_dir}",filename)), "w" ) { |f| f.write(file) }
42
+ end
43
+ end
44
+
45
+ class TestTemplate < Test::Unit::TestCase
46
+ include TemplateTestEnvironment
47
+ include Web::Testing
48
+
49
+ def setup
50
+ Web::setup( :document_root => get_test_dir, :out => '' )
51
+ setup_test_dir
52
+ end
53
+
54
+ def teardown
55
+ Web::teardown
56
+ remove_test_dir
57
+ end
58
+
59
+ def test_template_file
60
+ write_template( "here's a test" )
61
+ assert_equal( "#{temp_dir}/test_dir/templates/test.html",
62
+ Web::template_file( "test.html" ) )
63
+
64
+ teardown
65
+ setup
66
+
67
+ begin
68
+ File.open( "test.html", "w" ) { |f|
69
+ f.write("here's a test")
70
+ }
71
+ assert_equal( "./test.html",
72
+ Web::template_file( "test.html" ) )
73
+ ensure
74
+ File.delete( "test.html" )
75
+ end
76
+
77
+ end
78
+
79
+ def test_template_dir_precedence
80
+ write_template( "here's a test" )
81
+ begin
82
+ File.open( "test.html", "w" ) { |f|
83
+ f.write("here's a test")
84
+ }
85
+ assert_equal( "./test.html",
86
+ Web::template_file( "test.html" ) )
87
+ ensure
88
+ File.delete( "test.html" )
89
+ end
90
+ end
91
+
92
+ # ========= Variable Resolution ==========
93
+ def test_print_vars
94
+ write_template "x<%= Web::local['foo'] %>y<%= Web::local['bar'] %>z"
95
+ vars = { "foo" => "FOO", "bar" => "BAR" }
96
+ Web::options[:local] = vars
97
+ Web::load( "test.html" )
98
+ Web::close
99
+
100
+ Web::assert_content "xFOOyBARz"
101
+ end
102
+
103
+ def test_comments
104
+ write_template "x<%# this will be missing %>y<%# this too %>z"
105
+ Web::load( "test.html" )
106
+ Web::close
107
+ Web::assert_content "xyz"
108
+ end
109
+
110
+ # TODO: add <!--- ---> comments to erb?
111
+ def todo_test_comments_with_internal_tags
112
+ write_template "x<%# this will be <%= missing %> %>y<%# this too %>z"
113
+ Web::load( "test.html" )
114
+ Web::close
115
+ Web::assert_content "xyz"
116
+ end
117
+
118
+ def deprecated_test_throw_exception_if_var_doesnt_exist
119
+ write_template "x<%= Web::local['foo'] %>y<%= Web::local['bar'] %>z"
120
+ vars = { "foo" => "FOO" }
121
+
122
+ assert_raises(NameError) {
123
+ Web::options[:local] = vars
124
+ Web::load( "test.html" )
125
+
126
+ }
127
+ end
128
+
129
+ def test_nil_values_display_nothing
130
+ write_template "x<%= Web::local['foo'] %>yz"
131
+ vars = { "foo" => nil }
132
+ Web::options[:local] = vars
133
+ Web::load( "test.html" )
134
+ Web::close
135
+ Web::assert_content "xyz"
136
+ end
137
+
138
+
139
+ class TestClass
140
+ attr_reader :var
141
+
142
+ def initialize var
143
+ @var = var
144
+ end
145
+
146
+ def foo
147
+ TestClass.new("XXX")
148
+ end
149
+ end
150
+
151
+ def test_print_method
152
+ write_template "x<%= Web::local['foo'].var %>y<%= Web::local['bar'] %>z"
153
+ vars = { "foo" => TestClass.new("FOO"), "bar" => "BAR" }
154
+
155
+ Web::options[:local] = vars
156
+ Web::load( "test.html" )
157
+ Web::close
158
+ Web::assert_content "xFOOyBARz"
159
+ end
160
+
161
+ def test_template
162
+ write_template "<html><body><h1>hi</h1></body></html>"
163
+
164
+ Web::load( "test.html" )
165
+ Web::close
166
+ Web::assert_template_used( "test.html" )
167
+ end
168
+
169
+ def test_exception_thrown_if_no_template_used
170
+ write_template "<html><body><h1>{$var}</h1></body></html>"
171
+
172
+ assert_raises(Test::Unit::AssertionFailedError) do
173
+ Web::assert_template_used( "/test.html" )
174
+ end
175
+ end
176
+
177
+ def test_template_fails_assertion_with_wrong_template
178
+ write_template "<html><body><h1>{$var}</h1></body></html>"
179
+
180
+ Web::load( "test.html" )
181
+ Web::close
182
+
183
+ assert_raises( Test::Unit::AssertionFailedError ) do
184
+ Web::assert_template_used( "test_not_it.html" )
185
+ end
186
+
187
+ end
188
+
189
+ def test_assert_template_not_used
190
+ write_template "<html><body><h1>foo</h1></body></html>"
191
+ Web::load( "test.html" )
192
+ Web::close
193
+ Web::assert_template_not_used( "foo.html" )
194
+ end
195
+
196
+ def test_assert_template_not_used_with_no_template_used
197
+ write_template "<html><body><h1>foo</h1></body></html>"
198
+
199
+ Web::assert_template_not_used( "test.html" )
200
+ end
201
+
202
+ def test_basic_load
203
+ write_template "blah blah blah"
204
+ Web::load( "test.html" )
205
+ Web::close
206
+ Web::assert_content "blah blah blah"
207
+ end
208
+
209
+ def test_print_template_survives_enormous_templates
210
+ bad_template = ""
211
+
212
+ 1.upto(1000){ |i|
213
+ bad_template += "this template sucks\n"
214
+ }
215
+
216
+ write_template( bad_template )
217
+ Web::load( "test.html" )
218
+ Web::close
219
+
220
+ Web::assert_content bad_template
221
+ end
222
+
223
+ end
224
+
225
+
226
+ class TestIncludes < Test::Unit::TestCase
227
+ include TemplateTestEnvironment
228
+ include Web::Testing
229
+
230
+ def setup
231
+ Web::setup( :document_root => get_test_dir )
232
+ setup_test_dir
233
+ end
234
+
235
+ def teardown
236
+ Web::teardown
237
+ remove_test_dir
238
+ end
239
+
240
+
241
+ def test_include_prints_contents
242
+ write_template "<html><body><% Web::load( \"incfile.html\" ) %></body></html>" , "test.html"
243
+ write_template "<h1>Hello</h1>", "incfile.html"
244
+
245
+ Web::load( "test.html" )
246
+ Web::close
247
+
248
+ Web.assert_content "<html><body><h1>Hello</h1></body></html>"
249
+ end
250
+
251
+ def test_assert_template_used_works_for_included_templates
252
+ write_template "<html><body><% Web::load( \"incfile.html\" ) %></body></html>" , "test.html"
253
+ write_template "<h1><%= Web::local['foo']['name'] %></h1>", "incfile.html"
254
+
255
+ Web::options[:local] = { "foo" => { "name" => "bar" }}
256
+ Web::load( "test.html" )
257
+ Web::close
258
+
259
+ Web.assert_content "<html><body><h1>bar</h1></body></html>"
260
+
261
+ Web.assert_template_used 'test.html'
262
+ Web.assert_template_used 'incfile.html'
263
+ end
264
+
265
+ def todo_assert_template_used_works_for_multiple_print_template_calls
266
+
267
+ end
268
+
269
+ def test_load_with_variables
270
+ write_template "<html><body><% Web::load 'incfile.html' %></body></html>" , "test.html"
271
+ write_template "<h1><%= Web::local['foo']['name'] %></h1>", "incfile.html"
272
+
273
+ Web::local.merge!( { "foo" => { "name" => "bar" }} )
274
+
275
+ Web::load( "test.html" )
276
+ Web::close
277
+ Web.assert_content "<html><body><h1>bar</h1></body></html>"
278
+ end
279
+
280
+ def test_exception_thrown_if_template_doesnt_exist
281
+ write_template "<html><body><% Web::load 'nonexistant.html' %></body></html>" , "test.html"
282
+
283
+ assert_raises( LoadError ) do
284
+ Web::load( "test.html" )
285
+ end
286
+ end
287
+
288
+ def test_load_filename_from_var
289
+ write_template "<html><body><% Web::load( Web::local['incfile'] ) %></body></html>" , "test.html"
290
+ write_template "<h1><%= Web::local['foo']['name'] %></h1>", "incfile.html"
291
+
292
+ Web::options[:local] = { "foo" => { "name" => "bar" }, "incfile" => "incfile.html" }
293
+ Web::load( "test.html" )
294
+ Web::close
295
+ Web.assert_content "<html><body><h1>bar</h1></body></html>"
296
+ end
297
+ end