Skip to content

Instantly share code, notes, and snippets.

@kgoess
Created June 2, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgoess/e4e4191c364198de044e9760fff4a684 to your computer and use it in GitHub Desktop.
Save kgoess/e4e4191c364198de044e9760fff4a684 to your computer and use it in GitHub Desktop.
mojo test
#!/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