File Coverage

blib/lib/Test/Pcuke/Gherkin/Node/Background.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 6 66.6
condition n/a
subroutine 12 12 100.0
pod 1 8 12.5
total 49 58 84.4


line stmt bran cond sub pod time code
1             package Test::Pcuke::Gherkin::Node::Background;
2              
3 3     3   62402 use warnings;
  3         7  
  3         94  
4 3     3   15 use strict;
  3         5  
  3         90  
5              
6 3     3   16 use base 'Test::Pcuke::Gherkin::Node';
  3         5  
  3         2269  
7              
8             =head1 NAME
9              
10             Test::Cucumber::Background - background of the scenarios in a feature
11              
12             =head1 SYNOPSIS
13              
14             TODO synopsis
15              
16             use Test::Pcuke::Gherkin::Node::Background;
17              
18             my $background = Test::Pcuke::Gherkin::Node::Background->new();
19             # TODO code example
20              
21             =head1 METHODS
22              
23             =head2 new
24              
25             =cut
26              
27             sub new {
28 4     4 1 2058 my ($class, $args) = @_;
29            
30 4         24 my $self = $class->SUPER::new(
31             immutables => ['title'],
32             properties => ['steps'],
33             args => $args,
34             );
35            
36 4         13 $self->_clear_stats;
37            
38 4         7 return $self;
39             }
40              
41 3 100   3 0 23 sub title { $_[0]->_get_immutable('title') || q{} }
42 2     2 0 45 sub set_title { $_[0]->_set_immutable('title', $_[1]) }
43              
44             sub add_step {
45 2     2 0 603 my ($self, $step) = @_;
46 2         10 $self->_add_property('steps', $step);
47             }
48              
49 2 50   2 0 928 sub steps { $_[0]->_get_property('steps') || []; }
50              
51             sub execute {
52 2     2 0 7 my ($self) = @_;
53            
54 2         4 $self->_clear_stats;
55            
56 2         6 my $steps = $self->_get_property('steps');
57            
58 2         4 for ( @$steps ) {
59 4         17 $_->execute();
60 4         269 $self->collect_stats( $_ );
61             }
62             }
63              
64             sub collect_stats {
65 4     4 0 6 my ($self, $step) = @_;
66            
67 4         6 my $nsteps = $self->nsteps;
68 4         14 $nsteps->{ $step->status }++;
69 4         195 $self->_set_property('_nsteps', $nsteps);
70             }
71              
72 6     6   35 sub _clear_stats { $_[0]->_set_property('_nsteps', {fail=>0, pass=>0, undef=>0}) }
73              
74             sub nsteps {
75 6     6 0 17 my ($self, $status) = @_;
76 6         17 my $nsteps = $self->_get_property('_nsteps');
77            
78 6 50       23 return $status ?
79             $nsteps->{$status}
80             : $nsteps;
81             }
82              
83             1; # End of Test::Cucumber::Background
84             __END__