File: spec_helper.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 (42 lines) | stat: -rwxr-xr-x 1,155 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
#!/usr/bin/env perl
#
# spec_helper.t
#
# Tests the spec_helper function, which loads helper files relative to
# the current file.
#
########################################################################
#

package Testcase::Spec::SpecHelper;
use Test::Spec;
use base qw(Test::Spec);

our $foo;

describe "spec_helper" => sub {
  before each => sub { $foo = 0 };
  it "should load a Perl file into the calling package" => sub {
    spec_helper "helper_test.pl";
    is($foo, 1);
  };
  it "should load the file even if it has already been loaded" => sub {
    spec_helper "helper_test.pl";
    is($foo, 1);
  };
  it "should treat paths as relative to the spec, not the currently running executable" => sub {
    spec_helper "../t/helper_test.pl";
    is($foo, 1);
  };
  it "should treat absolute paths as absolute" => sub {
    # checks the error message
    eval { spec_helper "/foo/bar/does/not/exist" };
    like($@, qr{'/foo/bar/does/not/exist'});
  };
  it "should raise an error containing the filename if the load fails" => sub {
    eval { spec_helper "doesnotexist.pl" };
    like($@, qr{'doesnotexist.pl'});
  };
};

runtests unless caller;