-
-
Save kgoess/e4e4191c364198de044e9760fff4a684 to your computer and use it in GitHub Desktop.
mojo test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Test::More tests => 98; | |
use Test::Mojo; | |
package MyApp { | |
use Mojo::Base 'Mojolicious'; # enables strict and warnings | |
use Carp qw/croak/; | |
sub startup { | |
my $self = shift; | |
$self->helper( 'kg.myhelper' => sub { croak "dying here" } ); | |
# Routes | |
my $route = $self->routes; | |
# start API | |
$route->get('/')->to( | |
controller => 'MyController', | |
action => 'welcome' | |
); | |
} | |
} | |
package MyApp::MyController { | |
use Mojo::Base 'Mojolicious::Controller'; | |
sub welcome { | |
my $self = shift; | |
my $p = $self->kg->myhelper('ptest') | |
or return; | |
$self->render(json => { s => 'Hello there.' }); | |
} | |
} | |
my $t = Test::Mojo->new(MyApp->new); | |
$t->get_ok('/')->status_is(200)->json_is({ s => "Hello there."})->content_is('xx'); | |
# status is 500 and the content is the fancy mojo debugging html document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment