Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created May 27, 2014 13:00
Show Gist options
  • Save memememomo/ffc50483ece41afee63c to your computer and use it in GitHub Desktop.
Save memememomo/ffc50483ece41afee63c to your computer and use it in GitHub Desktop.
Test::Mojoでビルドされたアプリにブラウザでアクセスする ref: http://qiita.com/uchiko/items/8bef175a43889b29b7da
use strict;
use warnings;
use Test::More;
use Test::Mojo;
use t::Util;
my $t = Test::Mojo->new('MyApp');
# ここでサーバが立ち上がり、ブロックされる
t::Util::run_server($t->app);
$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
done_testing;
$ prove -l t/base.t
t/basic.t .. Accepting connections at http://*:50277/
package t::Util;
use strict;
use warnings;
use utf8;
use Net::EmptyPort qw(empty_port);
use Mojo::Server::Daemon;
sub run_server {
my ($app) = @_;
my $port = empty_port();
warn "Accepting connections at http://*:$port/\n";
my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:'.$port]);
$daemon->app($app);
$daemon->run;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment