blib/lib/Test/Story/Fixture.pm

filter: Statementstmt 59.8% 61 / 102 Branchbran 58.3% 21 / 36 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 68.4% 13 / 19 Podpod 33.3% 2 / 6 totaltotal 60.0% 108 / 180 CC 29 SCAR 19.5
CC
29
Cov
60%
_get_metavar
20.0
_squish_array
20.0
_recurse_parse_arguments
7.3
CRAP 7.0
« blib/lib/Test/Story/Fixture/Selenium.pm ↑ Summary blib/lib/Test/Story/File.pm »
1 package Test::Story::Fixture;
2 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
5 # This ensures the constructor from Moose::Object is
6 # preferred over the FITesque one... this is IMPORTANT!
7 9 extends(qw(Moose::Object Test::FITesque::Fixture));
8 }
9  
10 9 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 our @EXCLUDE_METHODS = qw(
12 config
13 selenium
14 testcase
15 ctxt
16 verbose
17 parse_method_string
18 disallowed_phrases
19 parse_arguments
20 );
21  
22 28 ▶sub BUILD {
Subroutine BUILD: called CC=6 SCAR=18.0
Pod undocumented
23 28 my $self = shift;
24 28 my ($params) = @_;
25 28 ▶ if (!$self->verbose || $params->{QUIET} || $ENV{QUIET_FIXTURES}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->verbose or $params->{"QUIET"} or $ENV{"QUIET_FIXTURES"}) 25 3 28
Condition66%4/6
not $self->verbose or $params->{"QUIET"} or $ENV{"QUIET_FIXTURES"}
l!l&&r!l&&!r
2503
not $self->verbose or $params->{"QUIET"}
l!l&&r!l&&!r
2503
MC/DC33%1/3
not $self->verbose or $params->{"QUIET"} or $ENV{"QUIET_FIXTURES"}
not $self->verbose $params->{"QUIET"} $ENV{"QUIET_FIXTURES"}
Truth table50%2/4
not(A) or B or C
A= not $self->verboseB= $params->{"QUIET"}C= $ENV{"QUIET_FIXTURES"}
ABCresult
1XX1
01X1
0011
0000
26 25 Test::Builder->new->no_diag(1);
27 }
28 28 ▶ diag sprintf(q{Using fixture class "%s"}, blessed($self))
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose > 1 2 26 28
29 if ($self->verbose > 1);
30 28 ▶ diag sprintf('START: "%s": %s', $self->testcase->filename, $self->testcase->id)
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 3 25 28
31 if ($self->verbose);
32 }
33  
34 28 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=3 SCAR=11.8
Pod undocumented
35 28 my $self = shift;
36 # fixture actions can clean up after themselves
37 28 ▶ while (my $coderef = shift @{ $self->_demolish_actions() }){
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = shift @{$self->_demolish_actions;}) 0 28 28
38 0 $self->$coderef();
39 0 $coderef = undef;
40 }
41 28 ▶ diag sprintf('FINISH: "%s": %s', $self->testcase->filename, $self->testcase->id)
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 3 25 28
42 if ($self->verbose);
43 }
44  
45 has '_demolish_actions' => (
46 is => 'ro',
47 isa => 'ArrayRef',
48 28 ▶ default => sub {[]},
Subroutine __ANON__: called CC=1 SCAR=0.0
49 9 );
50  
51 0 ▶sub _add_demolish_actions {
Subroutine _add_demolish_actions: not called CC=1 SCAR=6.9
52 0 my ($self, @actions) = @_;
53 0 push @{ $self->_demolish_actions() }, @actions;
54 }
55  
56 has 'config' => (
57 is => 'rw',
58 required => 1,
59 isa => 'HashRef',
60 28 ▶ default => sub { shift->testcase->config },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 9 lazy => 1,
62 );
63  
64 9 has 'testcase' => (
65 is => 'rw',
66 isa => 'Object'
67 );
68  
69 has 'ctxt' => (
70 is => 'rw',
71 required => 1,
72 isa => 'HashRef',
73 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 9 lazy => 1,
75 );
76  
77 has verbose => (
78 required => 1,
79 lazy => 1,
80 is => q{ro},
81 isa => q{Int},
82 28 ▶ default => sub { return shift->config->{verbose} },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 9 );
84  
85 # NB: this is a FITesque method, please do not edit.
86 384 ▶sub parse_method_string {
Subroutine parse_method_string: called CC=5 SCAR=17.6
Pod documented
87 384 my ($self, $method_string) = @_;
88 384 (my $method_name = $method_string) =~ s/\s+/_/g;
89  
90 # don't allow test cases to call private methods
91 384 ▶ if($method_name =~ m{^_}){
Branch: 1 branch
BranchTrueFalseTotal
if ($method_name =~ /^_/) 0 384 384
92 0 warn "Cannot call '$method_name' from test cases";
93 0 return undef;
94 }
95  
96 384 ▶ if (ref($self) and $self->verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->verbose > 1) 24 360 384
Condition100%3/3
ref $self and $self->verbose > 1
!ll&&!rl&&r
9626424
MC/DC100%2/2
ref $self and $self->verbose > 1
ref $self $self->verbose > 1
Truth table100%3/3
A and B
A= ref $selfB= $self->verbose > 1
ABresult
0X0
100
111
97 24 diag "Fixture method $method_name";
98 }
99  
100 # Don't allow testcases to talk about implementaion details
101 0 ▶ if(grep { $method_name =~ m{$_} } $self->disallowed_phrases()){
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$method_name =~ /$_/;} $self->disallowed_phrases) 0 384 384
102  
103 #
104 # Test cases should be completely oblivious to how things are done
105 # internally since they should be written from the perspective of the
106 # user. This is just a catchall to make sure that the developer really
107 # means "do something like the user would" instead of "hoke around the
108 # internals"
109 #
110 0 warn "'$method_name' refers to implementation details";
111 0 return undef;
112 }
113  
114 384 my $coderef = $self->can($method_name);
115 384 return $coderef;
116 }
117  
118 384 ▶sub disallowed_phrases {
Subroutine disallowed_phrases: called CC=1 SCAR=0.0
Pod undocumented
119 384 my ($self) = @_;
120 384 return qw();
121 }
122  
123 0 ▶sub _get_metavar {
Subroutine _get_metavar: not called CC=4 SCAR=30.0
124 0 my $self = shift;
125 0 my ($name) = @_;
126 0 my $config_ref = $self->config;
127  
128 0 my @path = split(/\./, $name);
129 0 foreach my $sub_name (@path) {
130 0 ▶ $config_ref = $config_ref->{$sub_name} or last;
Branch: 1 branch
BranchTrueFalseTotal
$config_ref = $config_ref->{$sub_name} or last 0 0 0
131 }
132 0 ▶ warn qq{Config reference "$name" does not point to a value}
Branch: 1 branch
BranchTrueFalseTotal
if ref $config_ref 0 0 0
133 if (ref($config_ref));
134 0 return $config_ref;
135 }
136  
137 80 ▶sub _parse_metavars {
Subroutine _parse_metavars: called CC=3 SCAR=11.8
138 80 my $self = shift;
139 80 my ($str) = @_;
140 80 ▶ $str ||= '';
Condition50%1/2
$str ||= ""
l!l
800
MC/DC0%0/1
$str ||= ""
$str
Truth table50%1/2
A
A= $str
Aresult
11
00
141  
142 80 my @keys = $str =~ /\$\(([^\)]+)\)/g;
143 80 foreach (@keys) {
144 0 my $value = $self->_get_metavar($_);
145 0 $str =~ s/\$\($_\)/$value/g;
146 }
147  
148 80 return $str;
149 }
150 60 ▶sub _recurse_parse_arguments {
Subroutine _recurse_parse_arguments: called CC=7 SCAR=19.9
151 60 my $self = shift;
152 60 my $arg = shift;
153 60 ▶ if (ref($arg) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 20 40 60
elsif (ref $arg eq 'ARRAY') { } 20 20 40
154 20 foreach my $key (keys %$arg) {
155 20 ▶ if (ref($arg->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg->{$key}) { } 0 20 20
156 0 $arg->{$key} = $self->_recurse_parse_arguments($arg->{$key});
157 } else {
158 20 $arg->{$key} = $self->_parse_metavars($arg->{$key});
159 }
160 }
161 } elsif (ref($arg) eq 'ARRAY') {
162 20 foreach my $idx (0 .. scalar(@$arg) - 1) {
163 40 ▶ if (ref($arg->[$idx])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg->[$idx]) { } 0 40 40
164 0 $arg->[$idx] = $self->_recurse_parse_arguments($arg->[$idx]);
165 } else {
166 40 $arg->[$idx] = $self->_parse_metavars($arg->[$idx]);
167 }
168 }
169 } else {
170 20 $arg = $self->_parse_metavars($arg);
171 }
172 60 return $arg;
173 }
174  
175 # NB: This is a FITesque required function
176 124 ▶sub parse_arguments {
Subroutine parse_arguments: called CC=3 SCAR=11.0
Pod documented
177 124 my $self = shift;
178 124 ▶ return @_ if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 28 96 124
179  
180 96 my @args = ();
181 96 my $recurse;
182  
183 96 foreach my $arg (@_) {
184 60 push @args, $self->_recurse_parse_arguments($arg);
185 }
186 96 return @args;
187 }
188  
189 0 ▶sub _squish_array {
Subroutine _squish_array: not called CC=4 SCAR=30.0
190 0 my $self = shift;
191 0 my ($arg) = @_;
192 0 my $array;
193 0 ▶ if (ref($arg) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
elsif (defined $arg) { } 0 0 0
194 0 $array = $arg;
195 } elsif (defined($arg)) {
196 0 $array = [$arg];
197 } else {
198 0 $array = [];
199 }
200 0 ▶ return wantarray ? @{ $array } : $array;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
201 }
202  
203 0 ▶sub _lowercase_args {
Subroutine _lowercase_args: not called CC=2 SCAR=17.9
204 0 my $self = shift;
205 0 my ($args) = @_;
206 0 foreach my $field (keys %$args) {
207 0 $args->{lc($field)} = delete $args->{$field};
208 }
209 }
210  
211 =head1 FIXTURE ACTIONS
212  
213 =cut
214  
215 =head2 todo fail
216  
217 todo fail: [ message ]
218  
219 Marks a place in the test case where you would like it to fail, flagging it as a TODO item.
220  
221 =cut
222  
223 0 ▶sub todo_fail {
Subroutine todo_fail: not called CC=1 SCAR=6.9
Pod undocumented
224 0 my $self = shift;
225 0 my ($arg) = @_;
226 TODO: {
227 0 local $TODO = "Marked as a failing TODO: $arg";
228 0 fail($arg);
229 }
230 }
231  
232 9 1;
233 __END__
« blib/lib/Test/Story/Fixture/Selenium.pm ↑ Summary blib/lib/Test/Story/File.pm »