Compatibility
ruby-web ships with the cgi.rb interface, adapted to use the ruby-web infrastructure.
require 'web/shim/cgi'
cgi = CGI.new
# ...
Custom Templates
You can customize how ruby-web load templates:
require 'web/phprb'
Web::config['load_suffix']['rhtml'] = lambda do |scriptname|
PHPRB::load(scriptname)
end
# or, if you really really love your templating language:
Web::config['load_suffix'].default = lambda do |scriptname|
PHPRB::load(scriptname)
end
Web::load('template.rhtml') # <= will be processed by phprb
phprb is an experimental template parser derived from erb, but not as inspired
by the systems invented by Sun and Microsoft. It has the following rules:
<? ... ?>
Evaluate ruby code.
<?= ... ?>
Evaluate the enclosed ruby code and print the output.
<!--- ... --->
Comment out the enclosed code.
<??, ??>
Print out literal <?? or ??>.
Testing Functions
To access these functions, include Web::Testing in your testcase
require 'web/testing'
require 'web/unit/testcase'
class MyWebTest << Test::Unit::TestCase
include Web::Testing
#...
end
do_request( scriptname, params={} )
Do a mock request to scriptname, passing in params.
scriptname can be /absolute/scriptname.rb if you use set
the docroot using Web::docroot = "...".
Otherwise, use a relative path from the current directory.
params is a hash of request parameters. You can mock
enviroment parameters on an :env key.
do_submit( formname, params={} )
Once you've done a request, you can submit forms on the page.
You can "fill out" fields by passing in params.
assert_content(expected, message="")
fails if content is not set to the provided string.
assert_form_includes(formname, vars)
Assert output content contains a form that includes the given hash of values. ### this could sure use some more docs.
Web::get_content()
the body content of the response (sans headers)
assert_header( name, values, message="" )
Fails if the header has not been set to the provided value(s).
assert_cookie( name, values, message="" )
Fails if cookie values are not present.