Created
May 27, 2014 13:00
-
-
Save memememomo/ffc50483ece41afee63c to your computer and use it in GitHub Desktop.
Test::Mojoでビルドされたアプリにブラウザでアクセスする ref: http://qiita.com/uchiko/items/8bef175a43889b29b7da
This file contains hidden or 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
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; |
This file contains hidden or 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
$ prove -l t/base.t | |
t/basic.t .. Accepting connections at http://*:50277/ |
This file contains hidden or 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
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