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             # ABSTRACT: Aliases for acceptance-like testing using Test::Spec
3 1     1   713 use parent qw(Exporter);
  1         270  
  1         5  
4 1     1   475 use Test::Spec;
  1         122763  
  1         6  
5              
6             our $VERSION = '0.01';
7              
8             our @ACCEPTANCE_EXPORT = qw( Feature Scenario Given When Then And );
9             our @EXPORT = (
10             @Test::Spec::EXPORT,
11             @Test::Spec::ExportProxy::EXPORT,
12             @ACCEPTANCE_EXPORT,
13             );
14             our @EXPORT_OK = (
15             @Test::Spec::EXPORT_OK,
16             @Test::Spec::ExportProxy::EXPORT_OK,
17             @ACCEPTANCE_EXPORT,
18             );
19             our %EXPORT_TAGS = (all => \@EXPORT_OK);
20              
21             sub import {
22 1     1   7 my $class = shift;
23 1         1 my $callpkg = caller;
24              
25 1         5 strict->import;
26 1         7 warnings->import;
27              
28 1 50       4 if (@_) {
29 0         0 $class->export_to_level(1, $callpkg, @_);
30 0         0 return;
31             }
32              
33 1     1   8 eval qq{
  1         2  
  1         10  
  1         77  
34             package $callpkg;
35             use parent 'Test::Spec::Acceptance';
36             # allow Test::Spec usage errors to be reported via Carp
37             our \@CARP_NOT = qw($callpkg);
38             };
39 1 50       4 die $@ if $@;
40              
41 1         78 Test::Spec->export_to_level(1, $callpkg);
42 1         2004 $class->export_to_level(1, $callpkg);
43             }
44              
45             BEGIN {
46 1     1   767 *Feature = \&Test::Spec::describe;
47 1         2 *Scenario = \&Test::Spec::describe;
48 1         2 *Given = \&Test::Spec::it;
49 1         3 *When = \&Test::Spec::it;
50 1         1 *Then = \&Test::Spec::it;
51 1         40 *And = \&Test::Spec::it;
52             }
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