Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

test::bdd::cucumber::manual::steps(3pm) [debian man page]

Test::BDD::Cucumber::Manual::Steps(3pm) 		User Contributed Perl Documentation		   Test::BDD::Cucumber::Manual::Steps(3pm)

NAME
Test::BDD::Cucumber::Manual::Steps - How to write Step Definitions VERSION
version 0.11 INTRODUCTION
The 'code' part of a Cucumber test-suite are the Step Definition files which match steps, and execute code based on them. This document aims to give you a quick overview of those. STARTING OFF
Most of your step files will want to start something like: #!perl use strict; use warnings; use Test::More; use Test::BDD::Cucumber::StepFile; use Method::Signatures; The fake shebang line gives some hints to syntax highlighters, and "use strict;" and "use warnings;" are hopefully fairly standard at this point. Most of my Step Definition files make use of Test::More, but you can use any Test::Builder based testing module. Your step will pass its pass or fail status back to its harness via Test::Builder - each step is run as if it were its own tiny test file, with its own localized Test::Builder object. Test::BDD::Cucumber::StepFile gives us the functions "Given()", "When()", "Then()" and "Step()". These pass the step definitions to the class loading the step definitions, and specify which Step Verb should be used - "Step()" matches any. Method::Signatures allows us to use a small amount of syntactic sugar for the step definitions, and gives us the "func()" keyword you'll see in a minute. STEP DEFINITIONS
Given qr/I have (d+)/, func ($c) { $c->stash->{'scenario'}->{'count'} += $1; } When "The count is an integer", func ($c) { $c->stash->{'scenario'}->{'count'} = int( $c->stash->{'scenario'}->{'count'} ); } Then qr/The count should be (d+)/, func ($c) { is( $c->stash->{'scenario'}->{'count'}, $c->matches->[0], "Count matches" ); } Each of the exported verb functions accept a regular expression (or a string that's used as one), and a coderef. The coderef is passed a single argument, the Test::BDD::Cucumber::StepContext object. To make this a little prettier, we use Method::Signatures's "func()" keyword so we're not continually typing: "sub { my $c = shift; ... ". We will evaluate the regex immediately before we execute the coderef, so you can use $1, $2, $etc, although these are also available via the StepContext. NEXT STEPS
How step files are loaded is discussed in Test::BDD::Cucumber::Manual::Architecture, but isn't of much interest. Of far more interest should be seeing what you have available in Test::BDD::Cucumber::StepContext... AUTHOR
Peter Sergeant "pete@clueball.com" LICENSE
Copyright 2011, Peter Sergeant; Licensed under the same terms as Perl perl v5.14.2 2012-05-20 Test::BDD::Cucumber::Manual::Steps(3pm)

Check Out this Related Man Page

Test::BDD::Cucumber::Executor(3pm)			User Contributed Perl Documentation			Test::BDD::Cucumber::Executor(3pm)

NAME
Test::BDD::Cucumber::Executor - Run through Feature and Harness objects VERSION
version 0.11 DESCRIPTION
The Executor runs through Features, matching up the Step Lines with Step Definitions, and reporting on progress through the passed-in harness. METHODS
steps add_steps The attributes "steps" is a hashref of arrayrefs, storing steps by their Verb. "add_steps()" takes step definitions of the item list form: ( [ Given => qr//, sub {} ], ), and populates "steps" with them. execute Execute accepts a feature object, a harness object, and an optional Test::BDD::Cucumber::TagSpec object and for each scenario in the feature which meets the tag requirements (or all of them, if you haven't specified one), runs "execute_scenario". execute_scenario Accepts a hashref of options, and executes each step in a scenario. Options: "feature" - A Test::BDD::Cucumber::Model::Feature object "feature_stash" - A hashref that should live the lifetime of feature execution "harness" - A Test::BDD::Cucumber::Harness subclass object "scenario" - A Test::BDD::Cucumber::Model::Scenario object "background_obj" - An optional Test::BDD::Cucumber::Model::Scenario object representing the Background "scenario_stash" - We'll create a new scenario stash unless you've posted one in. This is used exclusively for giving Background sections access to the same stash as the scenario they're running before. For each step, a Test::BDD::Cucumber::StepContext object is created, and passed to "dispatch()". Nothing is returned - everything is played back through the Harness interface. add_placeholders Accepts a text string and a hashref, and replaces " <placeholders" > with the values in the hashref, returning a string. dispatch Accepts a Test::BDD::Cucumber::StepContext object, and searches through the steps that have been added to the executor object, executing against the first matching one. You can also pass in a boolean 'short-circuit' flag if the Scenario's remaining steps should be skipped. skip_step Accepts a step-context, a result-type, and a textual reason, exercises the Harness's step start and step_done methods, and returns a skipped-test result. AUTHOR
Peter Sergeant "pete@clueball.com" LICENSE
Copyright 2011, Peter Sergeant; Licensed under the same terms as Perl perl v5.14.2 2012-05-20 Test::BDD::Cucumber::Executor(3pm)
Man Page