File: 12_response.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (63 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use Test::More tests => 23;

use strict;
use warnings;

use Dancer::Response;

my $r = Dancer::Response->new();
is $r->status => 200, "status looks good";
isa_ok $r->{headers} => 'HTTP::Headers';

$r->status(500);
is $r->status => 500;

Dancer::SharedData->response->status(200);
is $r->status => 200;

$r->content_type('text/plain');
is($r->content_type                           => 'text/plain');
is($r->header('Content-Type')                 => 'text/plain');
is(Dancer::SharedData->response->content_type => 'text/plain');

$r->headers('X-Bar' => 3);
is $r->header('X-Bar') => 3;

$r->header('X-Baz' => 2);
is $r->header('X-Baz') => 2;

$r->pass(1);
ok $r->has_passed;

my $headers = $r->headers_to_array;

ok $headers;
is ref $headers, 'ARRAY';
is_deeply $headers => [ 'Content-Type' => 'text/plain', 'X-Bar' => 3, 'X-Baz' => 2];

$r->content('foo');
ok $r->exists;
is $r->content => 'foo';

Dancer::SharedData->response->content('bar');
ok(Dancer::SharedData->response->exists);
is(Dancer::SharedData->response->content => 'bar');

# test for halt && halted
Dancer::Response->new(content => 'this is ok');
eval { Dancer::SharedData->response->halt('this is not ok'); };
$r = Dancer::SharedData->response();

is $r->status  => 200;
is $r->content => 'this is not ok';
is $r->halted  => 1;

Dancer::Response->new(content => 'this is ok');
eval {
    Dancer::SharedData->response->halt(Dancer::Response->new(status => 500,
                                                             content => 'this is not ok'));
};
$r = Dancer::SharedData->response();
is $r->status  => 500;
is $r->content => 'this is not ok';
is $r->halted  => 1;