Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HowardvanRooijen/a3b390ae11487c31811f573f8904a643 to your computer and use it in GitHub Desktop.

Select an option

Save HowardvanRooijen/a3b390ae11487c31811f573f8904a643 to your computer and use it in GitHub Desktop.
// features/example/
example.jsmodule.exports = function ()
{
this.Given(/^I have entered (.*) into the calculator$/, function (value, callback)
{
if (!this.valueStack)
{
this.valueStack = [];
}
this.valueStack.push(Number(value));
callback();
});
this.Given(/^I press divide$/, function (callback)
{
if (!this.operatorStack)
{
this.operatorStack = [];
}
this.operatorStack.push("divide");
callback();
});
this.When(/^I press equal/, function (callback)
{
var operator = this.operatorStack.pop();
switch (operator)
{
case "divide":
var right = this.valueStack.pop();
var left = this.valueStack.pop();
this.result = left / right;
break;
}
callback();
});
this.Then(/^The result should be (.*) on the screen$/, function (result, callback)
{
if (this.result === Number(result))
{
callback();
}
else
{
callback(new Error("Expected " + result + " actual " + this.result));
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment