File Coverage

blib/lib/Test/BDD/Cucumber/Model/Result.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1 22     22   273 use v5.14;
  22         91  
2 22     22   120 use warnings;
  22         45  
  22         1582  
3              
4             package Test::BDD::Cucumber::Model::Result 0.87;
5              
6             =head1 NAME
7              
8             Test::BDD::Cucumber::Model::Result - Encapsulates a result state
9              
10             =head1 VERSION
11              
12             version 0.87
13              
14             =head1 DESCRIPTION
15              
16             Encapsulation of result state - whether that's for a step, scenario, or feature
17              
18             =cut
19              
20 22     22   152 use Moo;
  22         62  
  22         191  
21 22     22   9763 use Types::Standard qw( Enum Str );
  22         48  
  22         248  
22              
23             =head1 ATTRIBUTES
24              
25             =head2 result
26              
27             Enum of: C, C, C or C. C is used
28             if there was any TODO output from a test, and C for a test that
29             wasn't run, either due to no matching step, or because a previous step failed.
30              
31             =cut
32              
33             has 'result' => ( is => 'ro', isa => Enum[qw( passing failing pending undefined )], required => 1 );
34              
35             =head2 output
36              
37             The underlying test-output that contributed to a result.
38              
39             =cut
40              
41             has 'output' => ( is => 'ro', isa => Str, required => 1 );
42              
43             =head1 METHODS
44              
45             =head2 from_children
46              
47             Collates the Result objects you pass in, and returns one that encompasses all
48             of them.
49              
50             As they may be varied, it runs through them in order of C,
51             C, C and C - the first it finds is the overall
52             result. The empty set passes.
53              
54             =cut
55              
56             sub from_children {
57 32     32 1 289 my ( $class, @children ) = @_;
58              
59             # We'll be looking for the presence of just one of any of the
60             # short-circuiting statuses, but we need to keep a sum of all the output.
61             # Passing is the default state, so we cheat and say there was one of them.
62 32         139 my %results = ( passing => 1 );
63 32         69 my $output;
64              
65 32         95 for my $child (@children) {
66              
67             # Save the status of that child
68 412         890 $results{ $child->result }++;
69              
70             # Add its output
71 412         1171 $output .= $child->output . "\n";
72             }
73 32         93 $output .= "\n";
74              
75 32         94 for my $status (qw( failing undefined pending passing )) {
76 106 100       310 if ( $results{$status} ) {
77 32         1014 return $class->new(
78             {
79             result => $status,
80             output => $output
81             }
82             );
83             }
84             }
85             }
86              
87             1;