File Coverage

blib/lib/Test/BDD/Cucumber/Model/Scenario.pm
Criterion Covered Total %
statement 18 18 100.0
branch 7 10 70.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 30 33 90.9


line stmt bran cond sub pod time code
1             package Test::BDD::Cucumber::Model::Scenario;
2             $Test::BDD::Cucumber::Model::Scenario::VERSION = '0.84';
3 19     19   104875 use Moo;
  19         11487  
  19         147  
4 19     19   8075 use Types::Standard qw( Str ArrayRef HashRef Bool InstanceOf );
  19         76068  
  19         145  
5              
6 19     19   19909 use Carp;
  19         44  
  19         8572  
7              
8             =head1 NAME
9              
10             Test::BDD::Cucumber::Model::Scenario - Model to represent a scenario
11              
12             =head1 VERSION
13              
14             version 0.84
15              
16             =head1 DESCRIPTION
17              
18             Model to represent a scenario
19              
20             =head1 ATTRIBUTES
21              
22             =head2 name
23              
24             The text after the C keyword
25              
26             =cut
27              
28             has 'name' => ( is => 'rw', isa => Str );
29              
30             =head2 description
31              
32             The text between the Scenario line and the first step line
33              
34             =cut
35              
36             has 'description' => (
37             is => 'rw',
38             isa => ArrayRef[InstanceOf['Test::BDD::Cucumber::Model::Line']],
39             default => sub { [] },
40             );
41              
42             =head2 steps
43              
44             The associated L objects
45              
46             =cut
47              
48             has 'steps' => (
49             is => 'rw',
50             isa => ArrayRef[InstanceOf['Test::BDD::Cucumber::Model::Step']],
51             default => sub { [] }
52             );
53              
54             =head2 data [deprecated]
55              
56             In case the scenario has associated datasets, returns the first one,
57             unless it has tags associated (which wasn't supported until v0.63 of
58             this module), in which case this method will die with an incompatibility
59             error.
60              
61             This (since v0.65 read-only) accessor will be removed upon release of v1.0.
62              
63             =cut
64              
65             my $data_warn_count = 0;
66              
67             sub data {
68             # "pseudo" accessor
69 10     10 1 4139 my $self = shift;
70 10 100       99 warn 'Scenario "data" accessor is deprecated since 0.65'
71             unless $data_warn_count++; # warn once
72 10 50       29 croak 'Scenario "data" accessor is read-only since 0.65' if @_;
73              
74 10 100       17 return [] unless @{$self->datasets};
  10         164  
75              
76             croak q{Scenario "data" accessor incompatible with multiple Examples}
77 2 50       23 if @{$self->datasets} > 1;
  2         47  
78             # Datasets without tags re-use the tags of the scenario
79 2 50       63 croak q{Scenario "data" accessor incompatible with Examples tags}
80             if $self->datasets->[0]->tags != $self->tags;
81              
82 2         151 return $self->datasets->[0]->data;
83             }
84              
85             =head2 datasets
86              
87             The dataset(s) associated with a scenario.
88              
89             =cut
90              
91             has 'datasets' => (
92             is => 'rw',
93             isa => ArrayRef[InstanceOf['Test::BDD::Cucumber::Model::Dataset']],
94             default => sub { [] }
95             );
96              
97             =head2 background
98              
99             Boolean flag to mark whether this was the background section
100              
101             =cut
102              
103             has 'background' => ( is => 'rw', isa => Bool, default => 0 );
104              
105             =head2 keyword
106              
107             =head2 keyword_original
108              
109             The keyword used in the input file (C) and its specification
110             equivalent (C) used to start this scenario. (I.e. C,
111             C and C.)
112              
113             =cut
114              
115             has 'keyword' => ( is => 'rw', isa => Str );
116             has 'keyword_original' => ( is => 'rw', isa => Str );
117              
118              
119             =head2 line
120              
121             A L object corresponding to the line where
122             the C keyword is.
123              
124             =cut
125              
126             has 'line' => ( is => 'rw', isa => InstanceOf['Test::BDD::Cucumber::Model::Line'] );
127              
128             =head2 tags
129              
130             Tags that the scenario has been tagged with, and has inherited from its
131             feature.
132              
133             =cut
134              
135             has 'tags' => ( is => 'rw', isa => ArrayRef[Str], default => sub { [] } );
136              
137             =head1 AUTHOR
138              
139             Peter Sergeant C
140              
141             =head1 LICENSE
142              
143             Copyright 2019-2023, Erik Huelsmann
144             Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl
145              
146             =cut
147              
148             1;