File Coverage

blib/lib/Test/Spec/Acceptance.pm
Criterion Covered Total %
statement 24 26 92.3
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 31 35 88.5


line stmt bran cond sub pod time code
1             package Test::Spec::Acceptance;
2              
3             # ABSTRACT: Aliases for acceptance-like testing using Test::Spec
4 1     1   717 use parent qw(Exporter);
  1         264  
  1         4  
5 1     1   499 use Test::Spec;
  1         122764  
  1         11  
6              
7             our $VERSION = '0.02';
8              
9             our @ACCEPTANCE_EXPORT = qw( Feature Scenario Given When Then And );
10             our @EXPORT = (
11             @Test::Spec::EXPORT,
12             @Test::Spec::ExportProxy::EXPORT,
13             @ACCEPTANCE_EXPORT,
14             );
15             our @EXPORT_OK = (
16             @Test::Spec::EXPORT_OK,
17             @Test::Spec::ExportProxy::EXPORT_OK,
18             @ACCEPTANCE_EXPORT,
19             );
20             our %EXPORT_TAGS = (all => \@EXPORT_OK);
21              
22             sub import {
23 1     1   7 my $class = shift;
24 1         2 my $callpkg = caller;
25              
26 1         6 strict->import;
27 1         7 warnings->import;
28              
29 1 50       3 if (@_) {
30 0         0 $class->export_to_level(1, $callpkg, @_);
31 0         0 return;
32             }
33              
34 1     1   9 eval qq{
  1         2  
  1         3  
  1         67  
35             package $callpkg;
36             use parent 'Test::Spec::Acceptance';
37             # allow Test::Spec usage errors to be reported via Carp
38             our \@CARP_NOT = qw($callpkg);
39             };
40 1 50       5 die $@ if $@;
41              
42 1         90 Test::Spec->export_to_level(1, $callpkg);
43 1         2058 $class->export_to_level(1, $callpkg);
44             }
45              
46             BEGIN {
47 1     1   856 *Feature = \&Test::Spec::describe;
48 1         3 *Scenario = \&Test::Spec::describe;
49 1         1 *Given = \&Test::Spec::it;
50 1         2 *When = \&Test::Spec::it;
51 1         2 *Then = \&Test::Spec::it;
52 1         36 *And = \&Test::Spec::it;
53             }
54              
55             1;
56              
57             =head1 NAME
58              
59             Test::Spec::Acceptance - Write tests in a declarative specification style
60              
61             =head1 SYNOPSIS
62              
63             use Test::Spec::Acceptance; # Also loads Test::Spec
64              
65             Feature "Test::Spec::Acceptance tests module" => sub {
66             Scenario "Usage example" => sub {
67             my ($number, $accumulated);
68              
69             Given "a relevant number" => sub {
70             $number = 42;
71             };
72             When "we add 0 to it" => sub {
73             $accumulated = $number + 0
74             };
75             When "we add 0 again" => sub {
76             $accumulated = $number + 0
77             };
78             Then "it does not change it's value" => sub {
79             is($accumulated, 42);
80             };
81             };
82             };
83              
84             runtests;
85              
86             =head1 DESCRIPTION
87              
88             This is a shameless wrapper around L. It does everything L does, plus it aliases some exported names to make acceptance-style tests more legible.
89              
90             I understand this is a bit silly and this is not how C is intended to work (using tests without any assertion) but I just think it's nice and more readable. I've had good experiencies expressing some tests this way.
91              
92             The new keywords are:
93              
94             =over 4
95              
96             =item Feature
97              
98             An alias for C.
99              
100             =item Scenario
101              
102             An alias for C.
103              
104             =item Given
105              
106             An alias for C.
107              
108             =item When
109              
110             An alias for C.
111              
112             =item Then
113              
114             An alias for C.
115              
116             =item And
117              
118             An alias for C.
119              
120             =back
121              
122             =head1 SEE ALSO
123              
124             Please, see the excellent L.
125              
126             =cut