NAME
CGI::Prototype::Mecha - test CGI::Prototype applications with WWW::Mechanize
SYNOPSIS
use CGI::Prototype::Mecha;
my $m = CGI::Prototype::Mecha->new(protoapp => 'My::App');
$m->get('http://mecha/');
ok $m->success, "fetched welcome page" or $m->diag_response;
like $m->content, qr/Select a task/, "welcome page content verified";
DESCRIPTION
WWW::Mechanize
combined with Test::More
is a great toolbench for testing a web application. But you need to have your code installed in the right location on a running server, and you can't poke behind the scenes to see if data structures or databases in your application are as they are expected to be after a particular web hit.
Enter CGI::Prototype::Mecha
, a subclass of WWW::Mechanize
.
Simply create a Mecha object, giving it the name of your CGI::Prototype
-derived application class, and "visit" the magic URL of http://mecha/
. Your application is fired up (loading the classes as needed), and you get a "response" as if it were being sent to the browser.
But, your object is in the same program as your test, so you can set environment variables to simulate auth success or control testing databases. Or even capture STDERR
into a file to make sure that a particular error log value is or is not being written.
Methods
- new
-
Extended from
WWW::Mechanize
. An additionalprotoapp
parameter is understood, expecting aCGI::Prototype
-derived application class (which should be located in the current@INC
). Returns the mecha object. - simple_request
-
Extended from
WWW::Mechanize
(which inherits it directly fromLWP::UserAgent
. This is where the magic happens.Note that visiting any URL that does not start with
http://mecha/
is fatal. A future version may fall back to the originalWWW::Mechanize
, letting you test your app's outbound links properly.As of version 0.20, even "input type=file" fields will be properly handled.
- diag_response
-
A convenience method that dumps the result "as_string" via
diag()
fromTest::More
. - diag_links
-
A convenience method that dumps all the links (text/url) via
diag()
. - diag_forms
-
A convenience method that dumps all the forms via
diag()
.
SEE ALSO
CGI::Prototype, WWW::Mechanize, Test::More
AUTHOR
Randal L. Schwartz, <merlyn@stonehenge.com>
Special thanks to Geekcruises.com and an unnamed large university for providing funding for the development of this module.
COPYRIGHT AND LICENSE
Copyright (C) 2003, 2004 by Randal L. Schwartz
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.