line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Pcuke::Gherkin::Node::Step; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
212679
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
104
|
|
4
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
101
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
18
|
use base 'Test::Pcuke::Gherkin::Node'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
784
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
214
|
|
9
|
3
|
|
|
3
|
|
612
|
use Test::Pcuke::Gherkin::Executor::Status; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3183
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Test::Pcuke::Gherkin::Node::Step - Step of the scenario of the feature |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module is used internally by L |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 new $conf |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Creates new step. $conf is a hashref that may contain |
24
|
|
|
|
|
|
|
the settings for the object. Without $conf the corresponding properties are |
25
|
|
|
|
|
|
|
unset. The keys of hashref are |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item type |
30
|
|
|
|
|
|
|
Type of the step: 'Given', 'when', 'then', 'and', 'but', '*' |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=item title |
33
|
|
|
|
|
|
|
Title of the step (probably without the type) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item text |
36
|
|
|
|
|
|
|
Multiline text associated with the step |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item table |
39
|
|
|
|
|
|
|
Table associated with the step |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item executor |
42
|
|
|
|
|
|
|
Executor object, see L |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=back |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
26
|
|
|
26
|
1
|
3823
|
my ($self, $args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
26
|
|
|
|
|
152
|
my $new_step = $self->SUPER::new( |
52
|
|
|
|
|
|
|
immutables => [qw{type title text table executor}], |
53
|
|
|
|
|
|
|
args => $args, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
26
|
|
|
|
|
72
|
return $new_step; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 type |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns the type of the step |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
2
|
1
|
22
|
sub type { $_[0]->_get_immutable('type') || q{}; } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 set_type $type |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Sets the type of the step. Type is an immutable property |
71
|
|
|
|
|
|
|
and may be set only once. Trying to set it more than once |
72
|
|
|
|
|
|
|
is a fatal error |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub set_type { |
77
|
3
|
|
|
3
|
1
|
1454
|
my ($self, $type) = @_; |
78
|
3
|
|
|
|
|
10
|
$self->_set_immutable('type', $self->_normalize_type($type)); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# TODO I18n ???? |
82
|
|
|
|
|
|
|
sub _normalize_type { |
83
|
3
|
|
|
3
|
|
4
|
my ($self, $type) = @_; |
84
|
3
|
|
|
|
|
8
|
$type = uc $type; |
85
|
18
|
|
|
|
|
63
|
confess q{The type of the step must be one of 'GIVEN',WHEN','THEN','AND', 'BUT', '*'} |
86
|
3
|
100
|
|
|
|
6
|
unless grep { $_ eq $type } qw{GIVEN WHEN THEN AND BUT *}; |
87
|
2
|
|
|
|
|
17
|
return $type; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 title |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Returns the title of the step. If the step is parametrized, |
94
|
|
|
|
|
|
|
i.e. the original title contails placeholders in angle brackets |
95
|
|
|
|
|
|
|
(Scenario Outline steps), they are replaced with the step parameters |
96
|
|
|
|
|
|
|
if those are set. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub title { |
101
|
4
|
|
|
4
|
1
|
12
|
my $self = shift; |
102
|
4
|
|
|
|
|
12
|
my $title = $self->_get_immutable('title'); |
103
|
|
|
|
|
|
|
|
104
|
4
|
100
|
|
|
|
13
|
return q{} unless $title; |
105
|
|
|
|
|
|
|
|
106
|
3
|
|
|
|
|
15
|
my $params = $self->_get_property('_step_parameters'); |
107
|
|
|
|
|
|
|
|
108
|
3
|
100
|
|
|
|
13
|
return $title unless $params; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
4
|
foreach my $p (keys %$params) { |
111
|
1
|
|
|
|
|
2
|
my $v = $params->{$p}; |
112
|
1
|
|
|
|
|
20
|
$title =~ s/<$p>/"$v"/g; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
6
|
return $title; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 set_title $title |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Sets the title. Title is an immutable property. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
2
|
1
|
39
|
sub set_title { $_[0]->_set_immutable('title', $_[1]); } |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 set_text |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Sets the text. Text is an immutable property |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub set_text { |
133
|
1
|
|
|
1
|
1
|
42
|
my ($self, $text) = @_; |
134
|
1
|
|
|
|
|
7
|
$self->_set_immutable('text', $text); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns the text associated with the step. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
4
|
|
|
4
|
1
|
706
|
sub text { $_[0]->_get_immutable('text') } |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the table associated with the step |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
3
|
|
|
3
|
1
|
18
|
sub table { $_[0]->_get_immutable('table') } |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 set_table |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns the tyable associated with the text |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub set_table { |
160
|
3
|
|
|
3
|
1
|
30
|
my($self, $table) = @_; |
161
|
3
|
|
|
|
|
15
|
$self->_set_immutable('table', $table ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 set_params $hash |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Sets the step parameters which are used to replace the |
167
|
|
|
|
|
|
|
placeholders in the title if any. For example, |
168
|
|
|
|
|
|
|
if the title is 'm = ' the hash is {m => 'MMM'} |
169
|
|
|
|
|
|
|
then the title() returns 'm = "MMM"' |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Note: this method is used in execute() and probably |
172
|
|
|
|
|
|
|
should be private. Don't use it %-) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub set_params { |
177
|
2
|
|
|
2
|
1
|
8
|
my ($self, $hash) = @_; |
178
|
2
|
50
|
|
|
|
8
|
confess "parameters must be a hash!" |
179
|
|
|
|
|
|
|
unless ref $hash eq 'HASH'; |
180
|
|
|
|
|
|
|
|
181
|
2
|
|
|
|
|
9
|
$self->_set_property('_step_parameters', $hash ); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 ubset_params |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Unsets params that are set by set_params. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Must be private, don't use |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub unset_params { |
193
|
1
|
|
|
1
|
0
|
3
|
my ($self) = @_; |
194
|
1
|
|
|
|
|
4
|
$self->_set_property('_step_parameters', undef); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 param_names |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
returns the names of the placeholders in the title |
200
|
|
|
|
|
|
|
If title is ' = ' then returns ['m', 'n'] |
201
|
|
|
|
|
|
|
or ['n', 'm'] |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Must be private? |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub param_names { |
208
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
209
|
2
|
|
|
|
|
7
|
my %params = map { $_ => 1 } ( $self->_get_immutable('title') =~ /<([^>]+)>/g ); |
|
4
|
|
|
|
|
12
|
|
210
|
2
|
|
|
|
|
21
|
return [ keys %params ]; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 executor |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Returns the executor object. See L |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
13
|
|
|
13
|
1
|
34
|
sub executor { $_[0]->_get_immutable('executor') } |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 execute |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Executes the step. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub execute { |
228
|
12
|
|
|
12
|
1
|
45
|
my ($self) = @_; |
229
|
|
|
|
|
|
|
|
230
|
12
|
|
|
|
|
24
|
my $result = $self->executor->execute( $self ); |
231
|
|
|
|
|
|
|
|
232
|
12
|
|
|
|
|
645
|
$self->_set_result($result); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub _set_result { |
237
|
12
|
|
|
12
|
|
29
|
my ($self, $result) = @_; |
238
|
|
|
|
|
|
|
|
239
|
12
|
100
|
|
|
|
31
|
$result = $self->_make_result_object($result) |
240
|
|
|
|
|
|
|
unless ref $result; |
241
|
|
|
|
|
|
|
|
242
|
12
|
|
|
|
|
40
|
$self->_set_property('_result', $result); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub _make_result_object { |
246
|
11
|
|
|
11
|
|
15
|
my ($self, $result) = @_; |
247
|
|
|
|
|
|
|
|
248
|
11
|
|
|
|
|
14
|
my $normalized = 'undef'; |
249
|
|
|
|
|
|
|
|
250
|
11
|
100
|
|
|
|
20
|
if ( defined $result ) { |
251
|
10
|
100
|
100
|
|
|
47
|
$normalized = 'pass' |
252
|
|
|
|
|
|
|
if $result =~ /pass/ || $result; |
253
|
10
|
100
|
100
|
|
|
42
|
$normalized = 'fail' |
254
|
|
|
|
|
|
|
if $result =~ /fail/ || ! $result; |
255
|
10
|
100
|
|
|
|
23
|
$normalized = 'undef' |
256
|
|
|
|
|
|
|
if $result =~ /undef/; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
11
|
|
|
|
|
38
|
return Test::Pcuke::Gherkin::Executor::Status->new($normalized); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head2 result |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Returns a result object. If the executor returns a string, then |
265
|
|
|
|
|
|
|
L object is created |
266
|
|
|
|
|
|
|
with the normalized status which is one of 'pass', 'undef', or 'fail' |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
12
|
|
|
12
|
1
|
31
|
sub result { $_[0]->_get_property('_result') } |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 status |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Returns the status of the sexecuted step. The result object that is returned |
275
|
|
|
|
|
|
|
by executor->execute is asked for that. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub status { |
280
|
12
|
|
|
12
|
1
|
555
|
my ($self) = @_; |
281
|
12
|
|
50
|
|
|
24
|
return $self->result->status || 'undef'; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
1; # End of Test::Pcuke::Gherkin::Node::Step |
286
|
|
|
|
|
|
|
__END__ |