File: 02_dependency_check.t

package info (click to toggle)
libdancer-perl 1.3202%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,408 kB
  • ctags: 638
  • sloc: perl: 7,215; xml: 1,977; sh: 51; makefile: 29; sql: 5
file content (55 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;
use Test::More import => ['!pass'];

plan tests => 5;

use Dancer ':syntax';
use File::Spec;
use lib File::Spec->catdir( 't', 'lib' );
use EasyMocker;

{
    # checking that EasyMocker works
    mock 'My::SuperModule'
        => method 'method'
        => should sub { ok( 1, 'EasyMocker mocked a method' ) };

    mock 'My::SuperModule'
        => method 'new_method'
        => should sub { 'blech' };

    eval { My::SuperModule->method };
    if ( !$@ ) {
        is( My::SuperModule->new_method, 'blech', 'Mocked method is good' );
    } else {
        ok( 0, 'Method mocking failed' );
    }
}

my $mock_loads = { };

mock 'Dancer::ModuleLoader' 
    => method 'load' 
    => should sub { $mock_loads->{ $_[1] } };

mock 'Dancer::Session::YAML'
    => method 'new'
    => should sub {1};

# when YAML is not here...
$mock_loads->{'Dancer::Session::YAML'} = 0;
eval { set(session => 'YAML') };
like($@, qr/unable to load session engine 'YAML'/,
    "the YAML session engine depends on YAML");

# when present, I CAN HAZ
$mock_loads->{'Dancer::Session::YAML'} = 1;
eval { set(session => 'YAML') };
is($@, '', "the session engine can be set with CGI::Session");

# load an unknown session engine
eval { set(session => 'galactica') };
like $@, qr/unable to load session engine 'galactica'/,
    "Unknown session engine is refused";