File Coverage

examples/calculator/features/step_definitions/calculator_steps.pl
Criterion Covered Total %
statement 211 211 100.0
branch n/a
condition n/a
subroutine 54 54 100.0
pod 0 1 0.0
total 265 266 99.6


line stmt bran cond sub pod time code
1             #!perl
2              
3 2     2   21 use strict;
  2         5  
  2         100  
4 2     2   11 use warnings;
  2         6  
  2         116  
5              
6 2     2   11 use Test::More;
  2         4  
  2         33  
7 2     2   788 use Test::BDD::Cucumber::StepFile;
  2         5  
  2         2905  
8              
9 2     2   515 use lib 'examples/calculator/lib/';
  2         857  
  2         17  
10              
11             Before sub {
12 2     2   1707 use_ok('Calculator');
  2     2   7  
  2     2   6  
  2     2   45  
  2     2   856  
  2     2   6  
  2     2   5  
  2     2   41  
  2     2   558  
  2     2   6  
  2     2   5  
  2     2   40  
  2     2   636  
  2     2   7  
  2     2   6  
  2     2   41  
  2     2   602  
  2     2   6  
  2     2   6  
  2     2   42  
  2     2   661  
  2     1   6  
  2     1   6  
  2     1   43  
  2     1   688  
  2     1   6  
  2     1   8  
  2     1   45  
  2     1   710  
  2     1   6  
  2     1   7  
  2     1   44  
  2     1   2267  
  2     1   5  
  2     1   6  
  2     1   69  
  2     1   1727  
  2     1   6  
  2     1   5  
  2     1   62  
  2     1   621  
  2     1   7  
  2     1   6  
  2     1   45  
  2     1   541  
  2     1   6  
  2     1   5  
  2     1   62  
  2         594  
  2         6  
  2         6  
  2         43  
  2         671  
  2         7  
  2         6  
  2         45  
  2         495  
  2         158  
  2         6  
  2         40  
  2         529  
  2         6  
  2         5  
  2         38  
  2         506  
  2         4  
  2         7  
  2         38  
  2         535  
  2         10  
  2         6  
  2         45  
  2         540  
  2         7  
  2         4  
  2         58  
  2         598  
  2         5  
  2         7  
  2         45  
  2         640  
  2         4  
  2         7  
  2         43  
  1         339  
  1         2  
  1         3  
  1         22  
  1         185  
  1         2  
  1         2  
  1         15  
  1         178  
  1         2  
  1         2  
  1         15  
  1         307  
  1         3  
  1         4  
  1         25  
  1         213  
  1         4  
  1         2  
  1         18  
  1         160  
  1         2  
  1         2  
  1         13  
  1         167  
  1         2  
  1         2  
  1         13  
  1         185  
  1         2  
  1         3  
  1         13  
  1         204  
  1         1  
  1         2  
  1         15  
  1         306  
  1         3  
  1         2  
  1         22  
  1         204  
  1         3  
  1         1  
  1         15  
  1         249  
  1         2  
  1         2  
  1         15  
  1         205  
  1         3  
  1         1  
  1         14  
  1         186  
  1         2  
  1         2  
  1         15  
  1         251  
  1         2  
  1         3  
  1         16  
  1         251  
  1         3  
  1         2  
  1         16  
  1         262  
  1         2  
  1         3  
  1         21  
  1         298  
  1         3  
  1         2  
  1         24  
  1         203  
  1         2  
  1         2  
  1         16  
  1         203  
  1         2  
  1         2  
  1         15  
  1         278  
  1         3  
  1         3  
  1         21  
  1         319  
  1         3  
  1         4  
  1         23  
  1         197  
  1         2  
  1         2  
  1         14  
  1         212  
  1         1  
  1         2  
  1         15  
  1         185  
  1         3  
  1         2  
  1         15  
  1         177  
  1         2  
  1         1  
  1         17  
  1         310  
  1         3  
  1         3  
  1         23  
13             };
14              
15             After sub {
16             my $c = shift;
17              
18             # a bit contrived, as garbage collection would clear it out
19             delete $c->stash->{'scenario'}->{'Calculator'};
20             ok( ( not exists $c->stash->{'scenario'}->{'Calculator'} ),
21             "Calculator cleaned up" );
22             };
23              
24             my %numbers_as_words = (
25             __THE_NUMBER_ONE__ => 1,
26             __THE_NUMBER_FOUR__ => 4,
27             __THE_NUMBER_FIVE__ => 5,
28             __THE_NUMBER_TEN__ => 10,
29             );
30              
31             sub map_word_to_number {
32 5     5 0 12 my $word = shift;
33              
34 5         34 ok( $word, "Passed in a word to map [$word]" );
35 5         2500 ok( exists $numbers_as_words{$word}, "Mapping found" );
36              
37 5         2496 return $numbers_as_words{$word};
38             }
39              
40             Transform qr/^(__THE_NUMBER_\w+__)$/, sub { map_word_to_number($1) };
41              
42             Transform qr/^table:number as word$/, sub {
43             my ( $c, $data ) = @_;
44              
45             for my $row ( @{$data} ) {
46             $row->{'number'} = map_word_to_number( $row->{'number as word'} );
47             }
48             };
49              
50             Given 'a new Calculator object', sub {
51             S->{'Calculator'} = Calculator->new();
52             };
53              
54             Given qr/^having pressed (.+)/, sub {
55             S->{'Calculator'}->press($_) for split( /(,| and) /, C->matches->[0] );
56             };
57              
58             Given qr/^having keyed (.+)/, sub {
59              
60             # Make this call the having pressed
61             my ($value) = @{ C->matches };
62             S->{'Calculator'}->key_in($value);
63             };
64              
65             Given 'having successfully performed the following calculations', sub {
66             my $calculator = S->{'Calculator'};
67              
68             for my $row ( @{ C->data } ) {
69             C->dispatch( 'Given', 'having keyed ' . $row->{'first'} );
70             C->dispatch( 'Given', 'having keyed ' . $row->{'operator'} );
71             C->dispatch( 'Given', 'having keyed ' . $row->{'second'} );
72             C->dispatch( 'Given', 'having pressed =' );
73              
74             is( $calculator->display, $row->{'result'},
75             $row->{'first'} . ' '
76             . $row->{'operator'} . ' '
77             . $row->{'second'} );
78             }
79             };
80              
81             Given 'having entered the following sequence', sub {
82             S->{'Calculator'}->key_in( C->data );
83             };
84              
85             Given 'having added these numbers', sub {
86             for my $row ( @{ C->data } ) {
87             S->{'Calculator'}->key_in( $row->{number} );
88             S->{'Calculator'}->key_in('+');
89             }
90             };
91              
92             Then qr/^the display should show (.+)/, sub {
93             my ($value) = @{ C->matches };
94             is( S->{'Calculator'}->display, $value, "Calculator display as expected" );
95             };