File Coverage

blib/lib/Test/BDD/Cucumber/Harness.pm
Criterion Covered Total %
statement 25 30 83.3
branch n/a
condition n/a
subroutine 14 19 73.6
pod 15 15 100.0
total 54 64 84.3


line stmt bran cond sub pod time code
1 22     22   14855 use v5.14;
  22         98  
2 22     22   137 use warnings;
  22         48  
  22         1921  
3              
4             package Test::BDD::Cucumber::Harness 0.87;
5              
6             =head1 NAME
7              
8             Test::BDD::Cucumber::Harness - Base class for creating harnesses
9              
10             =head1 VERSION
11              
12             version 0.87
13              
14             =head1 DESCRIPTION
15              
16             Harnesses allow your feature files to be executed while telling the outside
17             world about how the testing is going, and what's being tested. This is a base
18             class for creating new harnesses. You can see
19             L and
20             L for examples, although if you need
21             to interact with the results in a more exciting way, you'd be best off
22             interacting with L.
23              
24             =head1 METHODS / EVENTS
25              
26             =cut
27              
28 22     22   142 use Moo;
  22         47  
  22         184  
29 22     22   10356 use Types::Standard qw( ArrayRef );
  22         50  
  22         231  
30              
31             has 'results' => ( is => 'ro', default => sub { [] }, isa => ArrayRef );
32              
33             =head2 feature
34              
35             =head2 feature_done
36              
37             Called at the start and end of feature execution respectively. Both methods
38             accept a single argument of a L.
39              
40             =cut
41              
42 0     0 1 0 sub feature { my ( $self, $feature ) = @_; }
43 9     9 1 74 sub feature_done { my ( $self, $feature ) = @_; }
44              
45             =head2 background
46              
47             =head2 background_done
48              
49             If you have a background section, then we execute it as a quasi-scenario step
50             before each scenario. These hooks are fired before and after that, and passed
51             in the L that represents the Background
52             section, and a a dataset hash (although why would you use that?)
53              
54             =cut
55              
56 66     66 1 314 sub background { my ( $self, $scenario, $dataset ) = @_; }
57 66     66 1 273 sub background_done { my ( $self, $scenario, $dataset ) = @_; }
58              
59             =head2 scenario
60              
61             =head2 scenario_done
62              
63             Called at the start and end of scenario execution respectively. Both methods
64             accept a L module and a dataset hash.
65              
66             =cut
67              
68 0     0 1 0 sub scenario { my ( $self, $scenario, $dataset ) = @_; }
69 0     0 1 0 sub scenario_done { my ( $self, $scenario, $dataset ) = @_; }
70              
71             =head2 scenario_skip
72              
73             Called instead of C and C when a scenario is skipped.
74             Although the only reason for skipping scenarios currently is being excluded
75             due to tag expressions, this may change in the future.
76              
77             =cut
78              
79 64     64 1 232 sub scenario_skip { my ( $self, $scenario, $dataset ) = @_; }
80              
81             =head2 step
82              
83             =head2 step_done
84              
85             Called at the start and end of step execution respectively. Both methods
86             accept a L object. C also accepts
87             a L object and an arrayref of arrayrefs with
88             locations of consolidated matches, for highlighting.
89              
90             [ [2,5], [7,9] ]
91              
92             =cut
93              
94 0     0 1 0 sub step { my ( $self, $context ) = @_; }
95 0     0 1 0 sub step_done { my ( $self, $context, $result ) = @_; }
96              
97             =head2 sub_step
98              
99             =head2 sub_step_done
100              
101             As per C and C, but for steps that have been called from other
102             steps. None of the included harnesses respond to these methods, because
103             generally the whole thing should be transparent, and the parent step handles
104             passes, failures, etc.
105              
106             =cut
107              
108 24     24 1 71 sub sub_step { my ( $self, $context ) = @_; }
109 24     24 1 69 sub sub_step_done { my ( $self, $context, $result ) = @_; }
110              
111             =head2 startup
112              
113             =head2 shutdown
114              
115             Some tests will run one feature, some will run many. For this reason, you may
116             have harnesses that have something they need to do on start (print an HTML
117             header), that they shouldn't do at the start of every feature, or a close-down
118             task (like running C), that again shouldn't happen on I
119             feature close-out, just the last.
120              
121             Just C<$self> as the single argument for both.
122              
123             =cut
124              
125 14     14 1 50 sub startup { my $self = shift; }
126 9     9 1 32 sub shutdown { my $self = shift; }
127              
128             =head2 add_result
129              
130             Called before C with the step's result. Expected to silently add the
131             result in to a pool that facilitate the C method. No need to override
132             this behaviour.
133              
134             =head2 result
135              
136             Returns a collective view on the passing status of all steps run so far,
137             as a L object. Default implementation should
138             be fine for all your needs.
139              
140             =cut
141              
142             sub add_result {
143 987     987 1 1872 my $self = shift;
144 987         1832 push( @{ $self->results }, shift() );
  987         5076  
145             }
146              
147             sub result {
148 14     14 1 34 my $self = shift;
149             return Test::BDD::Cucumber::Model::Result->from_children(
150 14         35 @{ $self->results } );
  14         139  
151             }
152              
153             =head1 AUTHOR
154              
155             Peter Sergeant C
156              
157             =head1 LICENSE
158              
159             Copyright 2019-2023, Erik Huelsmann
160             Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl
161              
162             =cut
163              
164             1;