File: 01_settings.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 (58 lines) | stat: -rw-r--r-- 1,234 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
use Test::More tests => 6;
use strict;
use warnings;

use Dancer::App;
use Dancer::Test;

my $app = Dancer::App->new;

is_deeply $app->settings, {}, 
    "settings is an empty hashref";

is $app->setting('foo'), undef,
    "setting 'foo' is undefined";

ok $app->setting('foo' => 42), 
    "set the 'foo' setting to 42";

is $app->setting('foo'), 42,
    "setting 'foo' is 42";

# a setting could be overwritten by a Dancer::App instance

{ 
    package Webapp;
    use Dancer;

    setting onlyroot => 42;
    setting foo => "root";

    get '/root_action' => sub {
        return {
                onlyroot => setting('onlyroot'),
                foo => setting('foo'),
                onlyapp => setting('onlyapp') 
               };
    };

    use File::Spec;
    use lib File::Spec->catdir( 't', 'lib' );
    load_app 'TestApp',
      settings => {
                   foo => 'testapp',
                   onlyapp => '43',
                  };
}


response_content_is_deeply [ GET => '/root_action' ], { 
        onlyroot => 42,
        foo => 'root',
        onlyapp => undef, 
    };
response_content_is_deeply [ GET => '/test_app_setting' ], { 
        onlyroot => 42,
        foo => 'testapp',
        onlyapp => 43, 
    };