kesor / p5-cucumber
- Source
- Commits
- Network (3)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Thu Mar 19 06:03:08 -0700 2009 | |
| |
README.textile | Wed Mar 18 15:57:08 -0700 2009 | |
| |
example/ | Thu Mar 19 05:56:09 -0700 2009 | |
| |
lib/ | Thu Mar 19 07:44:02 -0700 2009 | |
| |
p5-cucumber.pl | Thu Mar 19 07:44:02 -0700 2009 | |
| |
parser/ | Thu Mar 19 07:44:02 -0700 2009 |
README.textile
Perl 5 Cucumber
This is a minimal implementation of Cucumber in Perl5
To learn about Cucumber take a look at:
http://wiki.gihub.com/aslakhellesoy/cucumber
Example:
Story
Feature: Dealing with mushrooms
In order to test the effect of evil poisonous mushrooms
As an evil scientist
I want to test effects of eating mushrooms on little children
Scenario: Mushrooms are bad for you, they kill boys
Given a live boy in a forest
When he ate a mushroom
Then he was a dead boy in a forest
Scenario: Mushrooms are bad for girls too
Given a live girl in a forest
When she ate a mushroom
Then she was a dead girl in a forest
Code
Given qr/(.*) in (.*)/, sub {
my ($description,$location) = @_;
$state{human} = $description;
$state{location} = $location;
};
When qr/s?he ate (.*)/, sub {
my $item = shift;
if ($item eq 'a mushroom') {
$state{human} =~ s/live/dead/;
}
};
Then qr/s?he was (.*) in (.*)/, sub {
my ($description,$location) = @_;
is($state{human},$description,$description);
is($state{location},$location,$location);
};
Execution output
$ perl p5-cucumber.pl
Feature: Dealing with mushrooms
In order to test the effect of evil poisonous mushrooms
As an evil scientist
I want to test effects of eating mushrooms on little children
Scenario: Mushrooms are bad for you, they kill boys
Given a live boy in a forest
When he ate a mushroom
Then he was a dead boy in a forest
ok 1 - a dead boy
ok 2 - a forest
Scenario: Mushrooms are bad for girls too
Given a live girl in a forest
When she ate a mushroom
Then she was a dead girl in the sea
ok 3 - a dead girl
not ok 4 - the sea
# Failed test 'the sea'
# at ./p5-cucumber.pl line 82.
# got: 'a forest'
# expected: 'the sea'
1..4
# Looks like you failed 1 test of 4.
(exitcode is 1 for failure)
And when we fix the story:
$ perl p5-cucumber.pl
Feature: Dealing with mushrooms
In order to test the effect of evil poisonous mushrooms
As an evil scientist
I want to test effects of eating mushrooms on little children
Scenario: Mushrooms are bad for you, they kill boys
Given a live boy in a forest
When he ate a mushroom
Then he was a dead boy in a forest
ok 1 - a dead boy
ok 2 - a forest
Scenario: Mushrooms are bad for girls too
Given a live girl in a forest
When she ate a mushroom
Then she was a dead girl in a forest
ok 3 - a dead girl
ok 4 - a forest
1..4
(exitcode is 0 for success)
Thanks
Great thank you for the perl-il and perl-qa mailing lists
for helping me with some high level perl concepts that make
this code so beautiful like it is.
Another huge thank you to the people in #perl @freenode.net
who helped me with sticky dereferencing and scalar/list
problems.
