File: mocks_imports.t

package info (click to toggle)
libtest-spec-perl 0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 252 kB
  • sloc: perl: 2,050; makefile: 2
file content (79 lines) | stat: -rwxr-xr-x 1,918 bytes parent folder | download | duplicates (5)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env perl
#
# mocks_imports.t
#
# Test the way Test::Spec::Mocks exports symbols.
#
########################################################################
#

package Testcase::Spec::Mocks::Imports;
use Test::Spec;
use base qw(Test::Spec);
use Package::Stash;

no strict 'refs';

describe "Test::Spec::Mocks" => sub {

  # start each test with a clean slate
  before each => sub {
    for my $pkg (qw(UNIVERSAL A)) {
      my $stash = Package::Stash->new($pkg);
      for my $sym (qw(&stubs &stub &expects &mock)) {
        $stash->remove_symbol($sym);
      }
    }
  };

  it "should not export symbols unless asked" => sub {
    {
      package A;
      require Test::Spec::Mocks;
    }
    ok(!defined(&{"UNIVERSAL::stubs"}) && !defined(&{"A::stubs"}));
  };

  it "should export &stubs into UNIVERSAL" => sub {
    {
      package A;
      eval "use Test::Spec::Mocks";
      die $@ if $@;
    }
    is( \&{"UNIVERSAL::stubs"}, \&{"Test::Spec::Mocks::stubs"} );
  };

  it "should export &stubs into UNIVERSAL even when listed in the import list" => sub {
    {
      package A;
      eval "use Test::Spec::Mocks qw(stubs)";
      die $@ if $@;
    }
    ok( \&{"UNIVERSAL::stubs"} == \&{"Test::Spec::Mocks::stubs"} && !defined(&{"A::stubs"}) );
  };

  it "should export &stub into the current pacakge" => sub {
    {
      package A;
      eval "use Test::Spec::Mocks";
      die $@ if $@;
    }
    is( \&{"A::stub"}, \&{"Test::Spec::Mocks::stub"} );
  };

  it "should export &stub into the current package even when &stubs is in the import list"  => sub {
    {
      package A;
      eval "use Test::Spec::Mocks qw(stub stubs)";
      die $@ if $@;
    }
    ok( \&{"UNIVERSAL::stubs"} == \&{"Test::Spec::Mocks::stubs"}
        && !defined(&{"A::stubs"})
        && !defined(&{"UNIVERSAL::stub"})
        && \&{"A::stub"} == \&{"Test::Spec::Mocks::stub"}
    );
  };

};

runtests unless caller;