1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
#!perl
use strict;
use warnings;
use utf8;
use Test::More;
use Test::BDD::Cucumber::Parser;
use Test::BDD::Cucumber::Executor;
use Test::BDD::Cucumber::Harness::Data;
# If you've taken the time to explicitly declare a Scenario Outline in any
# language, you need to have provided examples
my $feature = eval {
Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
# language: th
ความต้องการทางธุรกิจ: Test Feature
Conditions of satisfaction
เหตุการณ์:
กำหนดให้ a passing step called 'foo'
กำหนดให้ a passing step called '<name>'
ชุดของตัวอย่าง:
| name |
| 1 |
สรุปเหตุการณ์:
กำหนดให้ a passing step called 'bar'
กำหนดให้ a passing step called '<name>'
HEREDOC
);
};
my $error = $@;
ok( $error, "A parsing error was caught" );
like( $error, qr/Outline scenario expects/, "Error is about outline scenario" );
like( $error, qr/12\*/, "Error identifies correct start line" );
$@ = undef;
$feature = eval {
Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
Feature: Test scenario
Scenario Outline:
Given a passing step called '<name>'
Examples:
| name | value | more | columns |
| a-name | a-value | some | content |
Examples:
| name | value | more | columns |
| b-name | b-value | some | content |
HEREDOC
);
};
$error = $@;
ok( ! $error, "Two examples correctly parsed");
$feature =
Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
Feature: Test Feature
Conditions of satisfaction
Scenario:
Given I expect "<value>" to be equal to "an | escaped"
Examples:
| value |
| an \\| escaped |
HEREDOC
);
my $executor = Test::BDD::Cucumber::Executor->new();
my $harness = Test::BDD::Cucumber::Harness::Data->new();
my $tbl_value;
my $expectation;
$executor->add_steps(
[ Given => (qr/I expect "(.*)" to be equal to "(.*)"/, {},
sub {
$tbl_value = $1;
$expectation = $2;
}) ], );
$executor->execute($feature, $harness);
ok(defined $tbl_value, "table value defined");
ok(defined $expectation, "expectation defined");
is($tbl_value, $expectation, "escaped table value equals string value");
$feature =
Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
Feature: Test Feature
Conditions of satisfaction
Scenario:
Scenario definition
Given I expect "<value>" to be equal to "an | escaped"
Examples:
| value |
| an \\| escaped |
HEREDOC
);
$executor = Test::BDD::Cucumber::Executor->new();
$harness = Test::BDD::Cucumber::Harness::Data->new();
$executor->add_steps(
[ Given => (qr/I expect "(.*)" to be equal to "(.*)"/, {},
sub {
$tbl_value = $1;
$expectation = $2;
}) ], );
$executor->execute($feature, $harness);
ok(defined $tbl_value, "table value defined");
ok(defined $expectation, "expectation defined");
is($tbl_value, $expectation, "escaped table value equals string value");
$feature =
Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
Feature: Test Feature
Conditions of satisfaction
Scenario:
Given I expect
"""
Expected <value>
"""
Examples:
| value |
| the value |
HEREDOC
);
$executor = Test::BDD::Cucumber::Executor->new();
$harness = Test::BDD::Cucumber::Harness::Data->new();
$tbl_value = '';
$executor->add_steps(
[ Given => (qr/I expect/, {},
sub {
my $context = shift;
chomp ($tbl_value = $context->data);
}) ], );
$executor->execute($feature, $harness);
ok(defined $tbl_value, "table value defined");
is($tbl_value, "Expected the value", "expected value equals table value");
$feature =
Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
Feature: Test Feature
Conditions of satisfaction
Scenario:
Given I expect
| data |
| <value> |
Examples:
| value |
| the value |
HEREDOC
);
$executor = Test::BDD::Cucumber::Executor->new();
$harness = Test::BDD::Cucumber::Harness::Data->new();
$tbl_value = '';
$executor->add_steps(
[ Given => (qr/I expect/, {},
sub {
my $context = shift;
$tbl_value = $context->data->[0]->{data};
}) ], );
$executor->execute($feature, $harness);
ok(defined $tbl_value, "table value defined");
is($tbl_value, "the value", "expected value equals table value");
done_testing();
|