end0tknr's kipple - 新web写経開発

http://d.hatena.ne.jp/end0tknr/ から移転しました

(再)Amon2 for perl のControllerに対するTest::Moreによるunit test

end0tknr.hateblo.jp

↑こんな風にplug-inを書いて頑張らなくても Plack::Util::load_psgi や Test::WWW::Mechanize::PSGI で十分実現できるそうです。↓

use strict;
use warnings;
use utf8;
use HTTP::Cookies;
use JSON;
use Plack::Test;
use Plack::Util;
use Test::More;
use Test::Requires 'Test::WWW::Mechanize::PSGI';
use Data::Dumper;

$ENV{"PLACK_ENV"} = 'development';

my $cookie_jar = HTTP::Cookies->new(file => "./cookie.txt",
                                    autosave => 1,
                                    ignore_discard => 1);
$cookie_jar->set_cookie(undef,                  #version
                        "HTTP_mavi-id",         #key
                        'ushiro',               #val
                        "/",                    #pathu
                        "localhost.local");     #domain

my $app = Plack::Util::load_psgi 'script/ean-server';
my $mech = Test::WWW::Mechanize::PSGI->new(app => $app,
                                           cookie_jar=>$cookie_jar);

subtest 'sub_test_name_1'=> sub {
    $mech->get_ok("/");
    $mech->title_like(qr/トップ/s);
    $mech->content_like(qr/ean/s);
};

subtest 'sub_test_name_2'=> sub {
    $mech->get_ok("/report/group/settings");
    my $res_data = JSON::from_json( $mech->content );

    print STDERR Dumper($res_data);
    
};

done_testing;