File Coverage

lib/Test/Chai/Core/Assertions/Decrease.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Test::Chai::Core::Assertions::Decrease;
2 2     2   10 use strict;
  2         4  
  2         51  
3 2     2   11 use warnings;
  2         4  
  2         47  
4 2     2   10 use utf8;
  2         4  
  2         12  
5              
6 2     2   50 use Exporter qw/import/;
  2         3  
  2         121  
7             our @EXPORT_OK = qw/assert_decrease/;
8              
9 2     2   10 use Test::Chai::Util::Flag qw/flag/;
  2         3  
  2         409  
10              
11             sub assert_decrease {
12 3     3 0 5 my ($self, $object, $prop, $msg) = @_;
13              
14 3 50       9 flag($self, 'message', $msg) if defined $msg;
15 3         7 my $fn = flag($self, 'object');
16              
17 3         13 ref($self)->new($object, $msg)->to->have->property($prop);
18 3         17 ref($self)->new($fn)->is->a('CodeRef');
19              
20 3         13 my $initial = $object->{$prop};
21 3         10 $fn->();
22              
23             return $self->assert(
24 3         23 $object->{$prop} - $initial < 0,
25             'expected .' . $prop . ' to decrease',
26             'expected .' . $prop . ' to not decrease'
27             );
28             }
29              
30             1;