Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add documentation about World to README

  • Loading branch information...
commit 9824fdfae504cf73f36ed2a3598e195511ebb2cf 1 parent 92d95b2
@jbpros jbpros authored
Showing with 22 additions and 2 deletions.
  1. +22 −2 README.md
View
24 README.md
@@ -122,18 +122,38 @@ Support files let you setup the environment in which steps will be run, and defi
// features/support/world.js
var zombie = require('zombie');
-var World = function(callback) {
+var World = function World(callback) {
this.browser = new zombie.Browser(); // this.browser will be available in step definitions
this.visit = function(url, callback) {
this.browser.visit(url, callback);
};
- callback(); // tell Cucumber we're finished
+ callback(); // tell Cucumber we're finished and to use 'this' as the world instance
};
exports.World = World;
```
+It is possible to tell Cucumber to use another object instance than the constructor:
+
+``` javascript
+// features/support/world.js
+
+var zombie = require('zombie');
+var WorldConstructor = function WorldConstructor(callback) {
+ this.browser = new zombie.Browser(); // this.browser will be available in step definitions
+
+ var world = {
+ visit: function(url, callback) {
+ this.browser.visit(url, callback);
+ }
+ };
+
+ callback(world); // tell Cucumber we're finished and to use our world object instead of 'this'
+};
+exports.World = WorldConstructor;
+```
+
#### Step Definitions
Step definitions are the glue between features written in Gherkin and the actual *SUT* (*system under test*). They are written in JavaScript.
Please sign in to comment.
Something went wrong with that request. Please try again.