Skip to content

Commit

Permalink
added example for extracting additional information from test applica…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
kraih committed Nov 19, 2012
1 parent aac4688 commit 536ea37
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.58 2012-11-18
3.58 2012-11-19
- Improved documentation.
- Improved tests.
- Fixed state bugs in Mojo::Content::MultiPart.
Expand Down
4 changes: 4 additions & 0 deletions lib/Test/Mojo.pm
Expand Up @@ -431,6 +431,10 @@ Access application with L<Mojo::UserAgent/"app">.
if $self->req->url->path->contains('/user');
});
# Extract additional information
my $stash;
$t->app->hook(after_dispatch => sub { $stash = shift->stash });
=head2 C<content_is>
$t = $t->content_is('working!');
Expand Down
7 changes: 7 additions & 0 deletions t/mojolicious/group_lite_app.t
Expand Up @@ -205,6 +205,10 @@ get '/one_format' => [format => 'xml'] => {text => 'One format.'};

my $t = Test::Mojo->new;

# Preserve stash
my $stash;
$t->app->hook(after_dispatch => sub { $stash = shift->stash });

# GET /expiration (zero expiration persists)
$t->ua->max_redirects(1);
$t->get_ok('/expiration?redirect=1')->status_is(200)
Expand Down Expand Up @@ -237,6 +241,7 @@ $t->get_ok('/param_auth')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is("Not Bender!\n");
is $stash->{_name}, undef, 'no "_name" value';

# GET /param_auth?name=Bender
$t->get_ok('/param_auth?name=Bender')->status_is(200)
Expand All @@ -259,6 +264,7 @@ $t->get_ok('/param_auth/too?name=Bender')->status_is(200)
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
->content_is("stash too!!!!!!!\n");
ok $t->tx->res->cookie('mojolicious')->expires, 'has expiration';
is $stash->{_name}, 'stash', 'right "_name" value';

# GET /bridge2stash (with cookies, session and flash)
$t->get_ok('/bridge2stash')->status_is(200)
Expand Down Expand Up @@ -326,6 +332,7 @@ $t->get_ok('/with/under/count' => {'X-Bender' => 'Rodriguez'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('X-Under' => 1)->content_is("counter\n");
is $stash->{_name}, undef, 'no "_name" value';

# GET /bridge2stash (again)
$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200)
Expand Down

0 comments on commit 536ea37

Please sign in to comment.