Add `World` #26

Closed
jbpros opened this Issue Sep 5, 2011 · 1 comment

Comments

Projects
None yet
2 participants
Owner

jbpros commented Sep 5, 2011

See https://github.com/cucumber/cucumber/wiki/A-Whole-New-World and #2 (comment)

var assert = require('assert');

var defineSteps = function() {
  // `this` is set to an object supplying Given, When, Then and the World constructor.

  this.World = function World() { this.cukes = 0; }; // this is optional, would default to
                                                     // an empty constructor; kinda similar to
                                                     // cucumber-ruby's Object instance
  this.World.prototype.cukeUp = function() { this.cukes++; };

  this.When(/^I cuke up$/, function(callback) { 
    // `this` is set to the World object
    this.cukeUp();
    callback();
  });

  this.Then(/^I should have (\d+) cukes in my belly$/, function(expectedCukes, callback) { 
    // `this` is set to the World object
    assert.equal(this.cukes, expectedCukes);
    callback();
  });
};
module.exports = defineSteps;

Comments and suggestions are welcome!

@ghost ghost assigned jbpros Sep 5, 2011

Contributor

fernandoacorreia commented Sep 5, 2011

looks good to me

@jbpros jbpros closed this in e096ece Oct 12, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment