[Dancer-users] Best way to test using Test::WWW::Mechanize?
Marco Fontani
mfontani at cpan.org
Tue Feb 22 16:58:51 CET 2011
On Tue, Feb 22, 2011 at 3:35 PM, Michael Alan Dorman
<mdorman at ironicdesign.com> wrote:
> So, this worked (using the output of 'dancer -a Foo'):
>
> ----->8-----
> #!/usr/bin/perl
> use Dancer qw{:syntax};
> use Foo;
> use Test::More tests => 2;
> require Test::WWW::Mechanize::PSGI;
> set apphandler => 'PSGI';
> my $test = Test::WWW::Mechanize::PSGI->new (app => do ("bin/app.pl"));
> $test->get_ok ('/') or diag $test->content;
> $test->content_contains ('Tutorial');
> -----8<-----
>
> The thing that confuses and annoys me is the need to use 'do'---mostly
> because I don't quite understand why I need it. I tried:
http://search.cpan.org/dist/Test-WWW-Mechanize-PSGI/lib/Test/WWW/Mechanize/PSGI.pm#new
needs the code ref to start your app, which is what you give it with
the " do 'filename' " construct.
The reason it needs that is due to what the PSGI specification says an app _is_:
http://search.cpan.org/dist/PSGI/PSGI.pod#Applications
Applications:
Applications are web applications that actually get HTTP requests
and return HTTP response.
In PSGI it's a *code reference*
http://search.cpan.org/dist/PSGI/PSGI.pod#SPECIFICATION
A PSGI application is a Perl code reference.
the do() you are using gives the PSGI tester the code reference it
needs (your app) to run tests against.
-marco-
--
Marco Fontani
Glasgow Perl Mongers - http://glasgow.pm.org/
Join the RackSpace Cloud at: http://www.rackspacecloud.com/277.html
More information about the Dancer-users
mailing list