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.
- data/ChangeLog +474 -0
- data/INSTALL.txt +9 -0
- data/InstalledFiles +180 -0
- data/LICENSE.txt +74 -0
- data/Rakefile +529 -0
- data/TODO +65 -0
- data/doc/additional.xml +149 -0
- data/doc/core.xml +652 -0
- data/doc/credits/index.xml +52 -0
- data/doc/credits/php.contributors.xml +118 -0
- data/doc/credits/php.language-snippets.ent +622 -0
- data/doc/install/index.xml +136 -0
- data/doc/install/mac/index.xml +21 -0
- data/doc/install/ruby-web.install.rb.instructions.xml +7 -0
- data/doc/install/unix/index.xml +46 -0
- data/doc/install/win/apache1.xml +166 -0
- data/doc/install/win/apache2.xml +141 -0
- data/doc/install/win/iis.xml +162 -0
- data/doc/install/win/index.xml +24 -0
- data/doc/install/win/installer.xml +31 -0
- data/doc/install/win/manual.xml +43 -0
- data/doc/manual.xml +69 -0
- data/doc/old/apache_cgi.txt +23 -0
- data/doc/old/fastcgi.txt +23 -0
- data/doc/old/mod_ruby.txt +21 -0
- data/doc/old/snippets.rdoc +183 -0
- data/doc/old/webrick.txt +23 -0
- data/doc/old/windows_cgi.txt +9 -0
- data/doc/tutorial.xml +14 -0
- data/doc/xsl/manual-multi.xsl +10 -0
- data/doc/xsl/manual-pdf.xsl +6 -0
- data/doc/xsl/manual-single.xsl +6 -0
- data/doc/xsl/manual.css +22 -0
- data/install.rb +1022 -0
- data/lib/formatter.rb +314 -0
- data/lib/html-parser.rb +429 -0
- data/lib/htmlrepair.rb +113 -0
- data/lib/htmlsplit.rb +842 -0
- data/lib/sgml-parser.rb +332 -0
- data/lib/web.rb +68 -0
- data/lib/web/assertinclude.rb +129 -0
- data/lib/web/config.rb +50 -0
- data/lib/web/connection.rb +1070 -0
- data/lib/web/convenience.rb +154 -0
- data/lib/web/formreader.rb +318 -0
- data/lib/web/htmlparser/html-parser.rb +429 -0
- data/lib/web/htmlparser/sgml-parser.rb +332 -0
- data/lib/web/htmltools/element.rb +296 -0
- data/lib/web/htmltools/stparser.rb +276 -0
- data/lib/web/htmltools/tags.rb +286 -0
- data/lib/web/htmltools/tree.rb +139 -0
- data/lib/web/htmltools/xmltree.rb +160 -0
- data/lib/web/htmltools/xpath.rb +71 -0
- data/lib/web/info.rb +63 -0
- data/lib/web/load.rb +210 -0
- data/lib/web/mime.rb +87 -0
- data/lib/web/phprb.rb +340 -0
- data/lib/web/resources/test/cookie.rb +33 -0
- data/lib/web/resources/test/counter.rb +20 -0
- data/lib/web/resources/test/multipart.rb +14 -0
- data/lib/web/resources/test/redirect.rb +8 -0
- data/lib/web/resources/test/stock.rb +33 -0
- data/lib/web/sapi/apache.rb +129 -0
- data/lib/web/sapi/fastcgi.rb +22 -0
- data/lib/web/sapi/install/apache.rb +180 -0
- data/lib/web/sapi/install/iis.rb +93 -0
- data/lib/web/sapi/install/macosx.rb +90 -0
- data/lib/web/sapi/webrick.rb +86 -0
- data/lib/web/session.rb +83 -0
- data/lib/web/shim/cgi.rb +129 -0
- data/lib/web/shim/rails.rb +175 -0
- data/lib/web/stringio.rb +78 -0
- data/lib/web/strscanparser.rb +24 -0
- data/lib/web/tagparser.rb +96 -0
- data/lib/web/testing.rb +666 -0
- data/lib/web/traceoutput.rb +75 -0
- data/lib/web/unit.rb +56 -0
- data/lib/web/upload.rb +59 -0
- data/lib/web/validate.rb +52 -0
- data/lib/web/wiki.rb +557 -0
- data/lib/web/wiki/linker.rb +72 -0
- data/lib/web/wiki/page.rb +201 -0
- data/lib/webunit.rb +27 -0
- data/lib/webunit/assert.rb +152 -0
- data/lib/webunit/converter.rb +154 -0
- data/lib/webunit/cookie.rb +118 -0
- data/lib/webunit/domwalker.rb +185 -0
- data/lib/webunit/exception.rb +14 -0
- data/lib/webunit/form.rb +116 -0
- data/lib/webunit/frame.rb +37 -0
- data/lib/webunit/htmlelem.rb +122 -0
- data/lib/webunit/image.rb +26 -0
- data/lib/webunit/jscript.rb +31 -0
- data/lib/webunit/link.rb +33 -0
- data/lib/webunit/params.rb +321 -0
- data/lib/webunit/parser.rb +229 -0
- data/lib/webunit/response.rb +464 -0
- data/lib/webunit/runtest.rb +41 -0
- data/lib/webunit/table.rb +148 -0
- data/lib/webunit/testcase.rb +45 -0
- data/lib/webunit/ui/cui/testrunner.rb +50 -0
- data/lib/webunit/utils.rb +68 -0
- data/lib/webunit/webunit.rb +28 -0
- data/test/dev/action.rb +83 -0
- data/test/dev/forms.rb +104 -0
- data/test/dev/forms2.rb +104 -0
- data/test/dev/parser.rb +17 -0
- data/test/dev/scripts/dump.rb +24 -0
- data/test/dev/scripts/makedist.rb +62 -0
- data/test/dev/scripts/uri.rb +41 -0
- data/test/dev/scripts/uri/common.rb +432 -0
- data/test/dev/scripts/uri/ftp.rb +149 -0
- data/test/dev/scripts/uri/generic.rb +1106 -0
- data/test/dev/scripts/uri/http.rb +76 -0
- data/test/dev/scripts/uri/https.rb +26 -0
- data/test/dev/scripts/uri/ldap.rb +238 -0
- data/test/dev/scripts/uri/mailto.rb +260 -0
- data/test/dev/scripts/urireg.rb +174 -0
- data/test/dev/simpledispatcher.rb +156 -0
- data/test/dev/test.action.rb +146 -0
- data/test/dev/test.formreader.rb +463 -0
- data/test/dev/test.simpledispatcher.rb +186 -0
- data/test/dev/webunit/conv/digit-0.rb +21 -0
- data/test/dev/webunit/conv/digit-1.rb +17 -0
- data/test/dev/webunit/conv/digit.rb +23 -0
- data/test/dev/webunit/conv/test_digit-0.rb +16 -0
- data/test/dev/webunit/conv/test_digit-1.rb +19 -0
- data/test/dev/webunit/conv/test_digit.rb +26 -0
- data/test/dev/webunit/conv/test_digit_view-0.rb +76 -0
- data/test/dev/webunit/conv/test_digit_view-1.rb +102 -0
- data/test/dev/webunit/conv/test_digit_view.rb +134 -0
- data/test/installation/htdocs/cgi_test.rb +296 -0
- data/test/installation/htdocs/test_install.rb +4 -0
- data/test/installation/runwebtest.rb +5 -0
- data/test/installation/test_cookie.rb +128 -0
- data/test/installation/test_form.rb +47 -0
- data/test/installation/test_multipart.rb +51 -0
- data/test/installation/test_request.rb +24 -0
- data/test/installation/test_response.rb +35 -0
- data/test/unit/htdocs/cookie.rb +32 -0
- data/test/unit/htdocs/multipart.rb +28 -0
- data/test/unit/htdocs/redirect.rb +12 -0
- data/test/unit/htdocs/simple.rb +13 -0
- data/test/unit/htdocs/stock.rb +33 -0
- data/test/unit/test_assert.rb +162 -0
- data/test/unit/test_cookie.rb +114 -0
- data/test/unit/test_domwalker.rb +77 -0
- data/test/unit/test_form.rb +42 -0
- data/test/unit/test_frame.rb +40 -0
- data/test/unit/test_htmlelem.rb +74 -0
- data/test/unit/test_image.rb +45 -0
- data/test/unit/test_jscript.rb +57 -0
- data/test/unit/test_link.rb +85 -0
- data/test/unit/test_multipart.rb +51 -0
- data/test/unit/test_params.rb +210 -0
- data/test/unit/test_parser.rb +53 -0
- data/test/unit/test_response.rb +150 -0
- data/test/unit/test_table.rb +70 -0
- data/test/unit/test_utils.rb +106 -0
- data/test/unit/test_webunit.rb +28 -0
- data/test/web/mod_ruby_stub.rb +39 -0
- data/test/web/test.assertinclude.rb +109 -0
- data/test/web/test.buffer.rb +182 -0
- data/test/web/test.code.loader.rb +78 -0
- data/test/web/test.config.rb +31 -0
- data/test/web/test.error.handling.rb +91 -0
- data/test/web/test.formreader-2.0.rb +352 -0
- data/test/web/test.load.rb +125 -0
- data/test/web/test.mime-type.rb +23 -0
- data/test/web/test.narf.cgi.rb +106 -0
- data/test/web/test.phprb.rb +239 -0
- data/test/web/test.request.rb +368 -0
- data/test/web/test.response.rb +637 -0
- data/test/web/test.ruby-web.rb +10 -0
- data/test/web/test.session.rb +50 -0
- data/test/web/test.shim.cgi.rb +96 -0
- data/test/web/test.tagparser.rb +65 -0
- data/test/web/test.template2.rb +297 -0
- data/test/web/test.testing2.rb +318 -0
- data/test/web/test.upload.rb +45 -0
- data/test/web/test.validate.rb +46 -0
- data/test/web/test.web.test.rb +495 -0
- data/test/wiki/test.history.rb +297 -0
- data/test/wiki/test.illustration_page.rb +287 -0
- data/test/wiki/test.linker.rb +197 -0
- data/test/wiki/test.tarpit.rb +56 -0
- data/test/wiki/test.wiki.rb +300 -0
- data/test/wikitestroot/admin.rb +7 -0
- data/test/wikitestroot/wiki.rb +6 -0
- metadata +234 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
= test for WebUnit::Table
|
|
3
|
+
Copyright(C) 2001 yuichi TAKAHASHI
|
|
4
|
+
$Id: test_table.rb,v 1.1.1.1 2003/01/21 11:50:40 yuichi Exp $
|
|
5
|
+
=end
|
|
6
|
+
|
|
7
|
+
require 'webunit/webunit'
|
|
8
|
+
require 'runit/cui/testrunner'
|
|
9
|
+
|
|
10
|
+
module WebUnit
|
|
11
|
+
|
|
12
|
+
class TestTable < WebUnit::TestCase
|
|
13
|
+
|
|
14
|
+
def test_accessor
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_Table
|
|
18
|
+
|
|
19
|
+
url = @urlbase + "webunit/table.html"
|
|
20
|
+
response = Response::get( url )
|
|
21
|
+
|
|
22
|
+
table = response.tables[0]
|
|
23
|
+
|
|
24
|
+
assert_instance_of( Array, table.rows )
|
|
25
|
+
assert_equals( 4, table.rows.size )
|
|
26
|
+
|
|
27
|
+
assert_exception( ArgumentError ){ table.at(0) }
|
|
28
|
+
assert_instance_of( TableRow, table.at(1) )
|
|
29
|
+
assert_instance_of( TableRow, table.at(4) )
|
|
30
|
+
assert_exception( RuntimeError ){ table.at(5) }
|
|
31
|
+
|
|
32
|
+
assert_exception( ArgumentError ){ table.at(0,1) }
|
|
33
|
+
assert_exception( ArgumentError ){ table.at(1,0) }
|
|
34
|
+
assert_instance_of( TableCell, table.at(1,1) )
|
|
35
|
+
assert_instance_of( TableCell, table.at(4,3) )
|
|
36
|
+
assert_instance_of( NilTableCell, table.at(5,1) )
|
|
37
|
+
assert_instance_of( NilTableCell, table.at(1,4) )
|
|
38
|
+
|
|
39
|
+
assert_equals( "this 11", table.at(1,1).data )
|
|
40
|
+
assert_equals( "test 23", table.at(2,3).data )
|
|
41
|
+
assert_equals( "this 21", table.at(3,1).data )
|
|
42
|
+
assert_equals( "test 32", table.at(3,2).data )
|
|
43
|
+
assert_equals( "test 32", table.at(3,3).data )
|
|
44
|
+
assert_equals( "this 21", table.at(4,1).data )
|
|
45
|
+
|
|
46
|
+
table = response.tables[1]
|
|
47
|
+
|
|
48
|
+
assert_equals( "green", table.at(1).attrs['bgcolor'] )
|
|
49
|
+
assert_equals( "blue", table.at(2).attrs['bgcolor'] )
|
|
50
|
+
assert_equals( "red", table.at(3).attrs['bgcolor'] )
|
|
51
|
+
|
|
52
|
+
table = response.tables[2]
|
|
53
|
+
|
|
54
|
+
assert_equals( "", table.at(3,1).data )
|
|
55
|
+
assert_equals( "ggg", table.at(3,1).find("a")[0].data )
|
|
56
|
+
|
|
57
|
+
assert_include( "ggg", table.at(3,1) )
|
|
58
|
+
assert( table.at(3,1).has?( response.link ) )
|
|
59
|
+
|
|
60
|
+
assert_equals( 3, table.row_index( "ggg" ) )
|
|
61
|
+
assert_equals( 4, table.row_index( "kkk", 2 ) )
|
|
62
|
+
|
|
63
|
+
assert_equals( 2, table.col_index( "bbb" ) )
|
|
64
|
+
assert_equals( 1, table.col_index( "ggg", 3 ) )
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
= test for WebUnit::Utils
|
|
3
|
+
Copyright(C) 2001 yuichi TAKAHASHI
|
|
4
|
+
$Id: test_utils.rb,v 1.1.1.1 2003/01/21 11:50:40 yuichi Exp $
|
|
5
|
+
=end
|
|
6
|
+
|
|
7
|
+
require 'webunit/webunit'
|
|
8
|
+
require 'runit/cui/testrunner'
|
|
9
|
+
|
|
10
|
+
module WebUnit
|
|
11
|
+
|
|
12
|
+
class TestUtils < WebUnit::TestCase
|
|
13
|
+
|
|
14
|
+
def test_parse_url
|
|
15
|
+
|
|
16
|
+
url = "http://localhost/xxxx.html"
|
|
17
|
+
prot, host, port, path = parse_url( url )
|
|
18
|
+
|
|
19
|
+
assert_equals( 'http', prot )
|
|
20
|
+
assert_equals( 'localhost', host )
|
|
21
|
+
assert_equals( 80, port )
|
|
22
|
+
assert_equals( '/xxxx.html', path )
|
|
23
|
+
|
|
24
|
+
url = "http://localhost/"
|
|
25
|
+
prot, host, port, path = parse_url( url )
|
|
26
|
+
|
|
27
|
+
assert_equals( 'http', prot )
|
|
28
|
+
assert_equals( 'localhost', host )
|
|
29
|
+
assert_equals( 80, port )
|
|
30
|
+
assert_equals( '/', path )
|
|
31
|
+
|
|
32
|
+
url = "http://localhost"
|
|
33
|
+
prot, host, port, path = parse_url( url )
|
|
34
|
+
|
|
35
|
+
assert_equals( 'http', prot )
|
|
36
|
+
assert_equals( 'localhost', host )
|
|
37
|
+
assert_equals( 80, port )
|
|
38
|
+
assert_equals( '', path )
|
|
39
|
+
|
|
40
|
+
url = "file:/home/yyyy/xxxx.html"
|
|
41
|
+
prot, host, port, path = parse_url( url )
|
|
42
|
+
|
|
43
|
+
assert_equals( 'file', prot )
|
|
44
|
+
assert_equals( nil, host )
|
|
45
|
+
assert_equals( nil, port )
|
|
46
|
+
assert_equals( '/home/yyyy/xxxx.html', path )
|
|
47
|
+
|
|
48
|
+
url = "yyyy/xxxx.html"
|
|
49
|
+
prot, host, port, path = parse_url( url )
|
|
50
|
+
|
|
51
|
+
assert_equals( nil, prot )
|
|
52
|
+
assert_equals( nil, host )
|
|
53
|
+
assert_equals( nil, port )
|
|
54
|
+
assert_equals( 'yyyy/xxxx.html', path )
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_orthop_url
|
|
59
|
+
|
|
60
|
+
url = "http://localhost/xxxx.html"
|
|
61
|
+
assert_equals( 'http://localhost:80/xxxx.html', orthop_url( url ) )
|
|
62
|
+
|
|
63
|
+
url = "http://local-host/"
|
|
64
|
+
assert_equals( 'http://local-host:80/', orthop_url( url ) )
|
|
65
|
+
|
|
66
|
+
url = "http://localhost"
|
|
67
|
+
assert_equals( 'http://localhost:80', orthop_url( url ) )
|
|
68
|
+
|
|
69
|
+
url = "http://localhost/a/./xxxx.html"
|
|
70
|
+
assert_equals( 'http://localhost:80/a/xxxx.html', orthop_url( url ) )
|
|
71
|
+
|
|
72
|
+
url = "http://localhost/a/../xxxx.html"
|
|
73
|
+
assert_equals( 'http://localhost:80/xxxx.html', orthop_url( url ) )
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_complete_url
|
|
78
|
+
|
|
79
|
+
base = "http://localhost:80/a/xxxx.html"
|
|
80
|
+
|
|
81
|
+
url = 'http://localhost:80/a/yyyy.html'
|
|
82
|
+
assert_equals( url, complete_url( url, base ) )
|
|
83
|
+
|
|
84
|
+
url = 'http://localhost:80/yyyy.html'
|
|
85
|
+
assert_equals( url, complete_url( '/yyyy.html', base ) )
|
|
86
|
+
|
|
87
|
+
url = 'http://localhost:80/a/yyyy.html'
|
|
88
|
+
assert_equals( url, complete_url( 'yyyy.html', base ) )
|
|
89
|
+
|
|
90
|
+
assert_equals( base, complete_url( nil, base ) )
|
|
91
|
+
|
|
92
|
+
base = "http://localhost:80/a/xxxx.html?args..."
|
|
93
|
+
url = 'http://localhost:80/a/xxxx.html'
|
|
94
|
+
assert_equals( url, complete_url( nil, base ) )
|
|
95
|
+
|
|
96
|
+
url = 'xxxx.html'
|
|
97
|
+
assert_equals( url, complete_url( url, nil ) )
|
|
98
|
+
|
|
99
|
+
url = 'http://localhost:80/a/xxxx.html'
|
|
100
|
+
assert_equals( url, complete_url( url, nil ) )
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
= test for WebUnit
|
|
3
|
+
Copyright(C) 2001 yuichi TAKAHASHI
|
|
4
|
+
$Id: test_webunit.rb,v 1.2 2004/02/11 04:26:40 yuichi Exp $
|
|
5
|
+
=end
|
|
6
|
+
|
|
7
|
+
require 'webunit/webunit'
|
|
8
|
+
require 'runit/cui/testrunner'
|
|
9
|
+
|
|
10
|
+
if $0 == __FILE__
|
|
11
|
+
|
|
12
|
+
module WebUnit
|
|
13
|
+
|
|
14
|
+
class TestWebUnit < WebUnit::TestCase
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if ARGV.size == 0
|
|
20
|
+
suite = WebUnit::TestWebUnit::suite
|
|
21
|
+
else
|
|
22
|
+
suite = RUNIT::TestSuite.new
|
|
23
|
+
ARGV.each do |testmethod|
|
|
24
|
+
suite.add_test( WebUnit::TestWebUnit::new( testmethod ) )
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
RUNIT::CUI::TestRunner.run( suite )
|
|
28
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Apache
|
|
2
|
+
class Request
|
|
3
|
+
attr_reader :status_line, :content_type, :content_encoding, :headers_out, :headers_in
|
|
4
|
+
attr_writer :status_line, :content_type, :content_encoding
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@headers_out = {}
|
|
8
|
+
eval <<-EVAL
|
|
9
|
+
def @headers_out.add( k, v )
|
|
10
|
+
self[k] ||= []
|
|
11
|
+
self[k].push v
|
|
12
|
+
end
|
|
13
|
+
EVAL
|
|
14
|
+
@headers_in = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def sent?
|
|
18
|
+
@sent
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def send_http_header
|
|
22
|
+
@sent = true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def args
|
|
26
|
+
"key=some%20value&anotherKey=someother%20value"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def Apache.reset
|
|
31
|
+
@@request = nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@@request = nil
|
|
35
|
+
def Apache::request
|
|
36
|
+
@@request ||= Request.new
|
|
37
|
+
@@request
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
class TestHashCompare < Test::Unit::TestCase
|
|
2
|
+
def test_includes_same
|
|
3
|
+
assert_includes( {"a" => "aa"} , {"a" => "aa"} )
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def test_includes_missing
|
|
7
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
8
|
+
assert_includes( { "a" => "aa", "b" => "bb" } , {"a" => "aa"} )
|
|
9
|
+
}
|
|
10
|
+
assert e.to_s.index( "Missing from actual: b => \"bb\"" )
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_includes_different
|
|
14
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
15
|
+
assert_includes( {"a" => "aa"} , { "a" => "bb" } )
|
|
16
|
+
}
|
|
17
|
+
assert e.to_s.index("Difference: required <a => \"aa\"> was <a => \"bb\">" )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_includes_multi_level
|
|
21
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
22
|
+
assert_includes( {"a" => { "a" => "aa", "b" => "bb" }} , { "a" => { "a" => "aa", "b" => "cc"}} )
|
|
23
|
+
}
|
|
24
|
+
assert e.to_s.index("Difference: required <a.b => \"bb\"> was <a.b => \"cc\">")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_includes_array_with_difference
|
|
28
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
29
|
+
assert_includes( {"a" => [{ "a" => "aa" }, {"b" => "bb" }]},{ "a" => [ {"a" => "aa"}, {"b" => "cc"}]})
|
|
30
|
+
}
|
|
31
|
+
assert e.to_s.index("Difference: required <a[1].b => \"bb\"> was <a[1].b => \"cc\">")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_includes_array_with_items_missing
|
|
35
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
36
|
+
assert_includes( { "a" => [ {"a" => "aa"}, {"b" => "cc"}]} , {"a" => [{ "a" => "aa" }]} )
|
|
37
|
+
}
|
|
38
|
+
assert e.to_s.index("Missing from actual: a[1] => {\"b\"=>\"cc\"}")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_includes_hash_when_should_not
|
|
42
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
43
|
+
assert_includes( {"a" => "b"} , { "a" => { "a" => "aa", "b" => "cc"}} )
|
|
44
|
+
}
|
|
45
|
+
assert e.to_s.index("Difference: required <a => \"b\"> was <a => {\"a\"=>\"aa\", \"b\"=>\"cc\"}>")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_does_not_include_hash_when_it_should
|
|
49
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
50
|
+
assert_includes( { "a" => { "a" => "aa" , "b" => "cc"}}, {"a" => "b"} )
|
|
51
|
+
}
|
|
52
|
+
assert e.to_s.index("Difference: required <a => {\"a\"=>\"aa\", \"b\"=>\"cc\"}> was <a => \"b\">")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_includes_array_when_should_not
|
|
56
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
57
|
+
assert_includes( {"a" => "a"}, { "a" => [ {"a" => "aa"}, {"b" => "cc"}]} )
|
|
58
|
+
}
|
|
59
|
+
assert e.to_s.index("Difference: required <a => \"a\"> was <a => [{\"a\"=>\"aa\"}, {\"b\"=>\"cc\"}]>")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_does_not_include_array_when_it_should
|
|
63
|
+
e = assert_raises( Test::Unit::AssertionFailedError ) {
|
|
64
|
+
assert_includes( {"a" => "b"} , { "a" => { "a" => "aa" , "b" => "cc"}} )
|
|
65
|
+
}
|
|
66
|
+
assert e.to_s.index("Difference: required <a => \"b\"> was <a => {\"a\"=>\"aa\", \"b\"=>\"cc\"}>" )
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_assert_includes
|
|
70
|
+
assert_includes( {"a" => { "a" => "aa" }}, { "a" => { "a" => "aa" , "b" => "aa"}} )
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_assert_includes2
|
|
74
|
+
assert_raises(Test::Unit::AssertionFailedError) {
|
|
75
|
+
assert_includes( { "a" => { "a" => "aa" , "b" => "cc"}}, {"a" => { "c" => "bb" },"b" => { "c" => "bb" }})
|
|
76
|
+
}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_assert_includes_array
|
|
80
|
+
assert_includes( ["a"],[ "a","b"] )
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_demonstrate_failure
|
|
84
|
+
assert_raises(Test::Unit::AssertionFailedError) {
|
|
85
|
+
assert_includes(["a","b"],[ "a"])
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class Trivial
|
|
90
|
+
attr_accessor :name
|
|
91
|
+
def initialize( name )
|
|
92
|
+
@name = name
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_compare_object_tree_to_hash1
|
|
97
|
+
assert_includes({"name" => "patrick"}, Trivial.new("patrick"))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_compare_object_tree_to_hash2
|
|
101
|
+
assert_includes({"name" => { "name" => "patrick" }}, Trivial.new(Trivial.new("patrick")))
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# TODO:
|
|
106
|
+
# reports an error if either item is not a hash
|
|
107
|
+
# improve error reporting when comparing a hash to an array and vice versa
|
|
108
|
+
# add an enhanced version of assert equals
|
|
109
|
+
end
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
class TestBuffer < Test::Unit::TestCase
|
|
2
|
+
include Web::Testing
|
|
3
|
+
def setup
|
|
4
|
+
Web::setup
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def teardown
|
|
8
|
+
Web::teardown
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Web::filter is an alias to ob_start
|
|
12
|
+
def test_filter
|
|
13
|
+
Web::open( :out=>'' ) do
|
|
14
|
+
Web::filter do |content|
|
|
15
|
+
[ "start", content, "end" ].join(",")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Web::write "middle"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
assert_equal( "start,middle,end", Web::get_content )
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# ob_start -- Turn on output buffering
|
|
26
|
+
def test_ob_start
|
|
27
|
+
Web::open( :out=>'' ) do
|
|
28
|
+
Web::ob_start do |content|
|
|
29
|
+
[ "start", content, "end" ].join(",")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Web::write "middle"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
assert_equal( "start,middle,end", Web::get_content )
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# ob_flush -- Flush (send) the output buffer
|
|
39
|
+
def test_ob_flush
|
|
40
|
+
Web::open( :out=>'' ) do
|
|
41
|
+
Web::ob_start do |content|
|
|
42
|
+
"[" + content +"]"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
Web::write "write 1"
|
|
46
|
+
|
|
47
|
+
Web::ob_flush
|
|
48
|
+
|
|
49
|
+
Web::write "write 2"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
assert_equal( '[write 1][write 2]', Web::get_content )
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# ob_clean -- erase the output buffer
|
|
56
|
+
def test_ob_clean
|
|
57
|
+
Web::open( :out=>'' ) do
|
|
58
|
+
Web::write "this text will be erased"
|
|
59
|
+
Web::ob_clean
|
|
60
|
+
Web::write "expected content"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
assert_equal( 'expected content', Web::get_content )
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# ob_end_clean -- Clean (erase) the output buffer and turn off output buffering
|
|
67
|
+
def test_ob_end_clean
|
|
68
|
+
Web::open( :out=>'' ) do
|
|
69
|
+
Web::ob_start do |content|
|
|
70
|
+
"[" + content + "]"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
Web::ob_start do |content|
|
|
74
|
+
"{" + content + "}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
Web::write "this content will not be seen"
|
|
78
|
+
|
|
79
|
+
assert( Web::ob_end_clean )
|
|
80
|
+
|
|
81
|
+
Web::write "expected content"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
assert_equal( '[expected content]', Web::get_content )
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# ob_end_flush -- Flush (send) the output buffer and turn off output buffering
|
|
88
|
+
def test_ob_end_flush
|
|
89
|
+
Web::open( :out=>'' ) do
|
|
90
|
+
Web::ob_start do |content|
|
|
91
|
+
"[" + content + "]"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
Web << "expected content"
|
|
95
|
+
|
|
96
|
+
Web::ob_end_flush
|
|
97
|
+
|
|
98
|
+
Web << "a little more"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
assert_equal( '[expected content]a little more', Web::get_content )
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# ob_get_clean -- Get current buffer contents and delete current output buffer
|
|
105
|
+
def test_ob_get_clean
|
|
106
|
+
Web::open( :out=>'' ) do
|
|
107
|
+
Web::ob_start do |content|
|
|
108
|
+
"[" + content + "]"
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
Web << 'expected content'
|
|
112
|
+
assert_equal( 'expected content', Web::ob_get_clean )
|
|
113
|
+
Web << 'more content'
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
assert_equal( 'more content', Web::get_content )
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# ob_get_contents -- Return the contents of the output buffer
|
|
120
|
+
def test_ob_get_contents
|
|
121
|
+
Web::open( :out=>'' ) do
|
|
122
|
+
Web << 'expected'
|
|
123
|
+
assert_equal( 'expected', Web::ob_get_contents )
|
|
124
|
+
end
|
|
125
|
+
assert_equal( 'expected', Web::get_content )
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# ob_get_flush -- Flush the output buffer, return it as a string and turn off output buffering
|
|
129
|
+
def test_ob_get_flush
|
|
130
|
+
Web::open( :out=>'' ) do
|
|
131
|
+
Web::ob_start do |content|
|
|
132
|
+
"[" + content + "]"
|
|
133
|
+
end
|
|
134
|
+
Web << 'expected'
|
|
135
|
+
assert_equal( 'expected', Web::ob_get_flush )
|
|
136
|
+
Web::ob_end_clean
|
|
137
|
+
end
|
|
138
|
+
assert_equal( '[expected]', Web::get_content )
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# ob_get_length -- Return the length of the output buffer
|
|
142
|
+
# ob_get_contents -- Return the contents of the output buffer
|
|
143
|
+
def test_ob_get_length
|
|
144
|
+
Web::open( :out=>'' ) do
|
|
145
|
+
Web << 'expected'
|
|
146
|
+
assert_equal( 8, Web::ob_get_length )
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# ob_get_level -- Return the nesting level of the output buffering mechanism
|
|
151
|
+
def test_ob_get_level
|
|
152
|
+
Web::open( :out=>'' ) do
|
|
153
|
+
assert_equal( 1, Web::ob_get_level )
|
|
154
|
+
Web::ob_start
|
|
155
|
+
assert_equal( 2, Web::ob_get_level )
|
|
156
|
+
Web::ob_start
|
|
157
|
+
assert_equal( 3, Web::ob_get_level )
|
|
158
|
+
Web::ob_end_clean
|
|
159
|
+
assert_equal( 2, Web::ob_get_level )
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# ob_list_handlers -- List all output handlers in use
|
|
164
|
+
def test_ob_list_handlers
|
|
165
|
+
Web::open( :out=>'' ) do
|
|
166
|
+
Web::ob_start do |content|
|
|
167
|
+
"[" + content + "]"
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
assert_equal( "[expected]",
|
|
171
|
+
Web::ob_list_handlers.last.callback.call('expected') )
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# ob_get_status -- Get status of output buffers
|
|
176
|
+
# ob_implicit_flush -- Turn implicit flush on/off
|
|
177
|
+
# ob_gzhandler -- ob_start callback function to gzip output buffer
|
|
178
|
+
# output_add_rewrite_var -- Add URL rewriter values
|
|
179
|
+
# output_reset_rewrite_vars
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
end
|