Debian Codegraph @

t/examples/simple_calculator.t

raw
1 use strict;
2 use warnings;
3
4 use FindBin ();
5
6 use Test::More;
7 use Plack::Test;
8 use HTTP::Request::Common qw(GET POST);
9
10 my $app = do "$FindBin::Bin/../../examples/single/simple_calculator.psgi";
11 is( ref $app, 'CODE', 'Got app' );
12
13 my $test = Plack::Test->create($app);
14
15 my $res = $test->request( GET '/' );
16 ok( $res->is_success, '[GET /] successful' );
17 like( $res->content, qr/powered by Dancer/, 'Content looks ok' );
18
19 subtest add => sub {
20 plan tests => 2;
21 my $res = $test->request( GET '/add/19/23' );
22 ok( $res->is_success, '[GET /add/] successful' );
23 is( $res->content, 42, 'Content looks ok' );
24 };
25
26 subtest multiply => sub {
27 plan tests => 2;
28 my $res = $test->request( GET '/multiply?x=10&y=5' );
29 ok( $res->is_success, '[GET /multiply/] successful' );
30 is( $res->content, 50, 'Content looks ok' );
31 };
32
33 subtest division => sub {
34 plan tests => 2;
35 my $res = $test->request( POST '/division', { x=>10, y=>5 } );
36 ok( $res->is_success, '[GET /division/] successful' );
37 is( $res->content, 2, 'Content looks ok' );
38 };
39
40 done_testing();
41