Skip to content

Commit

Permalink
Spec broadcastUserFunction()
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Jun 7, 2011
1 parent b669e01 commit 3e69e98
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 75 deletions.
74 changes: 52 additions & 22 deletions lib/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ Cucumber.Ast.TreeWalker = function(features, supportCodeLibrary, listeners) {
},

visitFeatures: function visitFeatures(features, callback) {
self.broadcastMessagesAroundUserFunction(
self.broadcastUserFunction(
Cucumber.Ast.TreeWalker.FEATURES_MESSAGE,
function(callback) { features.acceptVisitor(self, callback); },
callback
);
},

visitFeature: function visitFeature(feature, callback) {
self.broadcastMessagesAroundUserFunction(
self.broadcastUserFunction(
Cucumber.Ast.TreeWalker.FEATURE_MESSAGE,
feature,
function(callback) { feature.acceptVisitor(self, callback); },
Expand All @@ -254,7 +254,7 @@ Cucumber.Ast.TreeWalker = function(features, supportCodeLibrary, listeners) {
},

visitScenario: function visitScenario(scenario, callback) {
self.broadcastMessagesAroundUserFunction(
self.broadcastUserFunction(
Cucumber.Ast.TreeWalker.SCENARIO_MESSAGE,
scenario,
function(callback) { scenario.acceptVisitor(self, callback); },
Expand All @@ -263,7 +263,7 @@ Cucumber.Ast.TreeWalker = function(features, supportCodeLibrary, listeners) {
},

visitStep: function visitStep(step, callback) {
self.broadcastMessagesAroundUserFunction(
self.broadcastUserFunction(
Cucumber.Ast.TreeWalker.STEP_MESSAGE,
step,
function(callback) { step.acceptVisitor(self, callback); },
Expand All @@ -279,24 +279,54 @@ Cucumber.Ast.TreeWalker = function(features, supportCodeLibrary, listeners) {
);
},

broadcastMessagesAroundUserFunction: function broadcastMessagesAroundUserFunction() {
var message = arguments[0];
var parameters = [];
if (arguments.length > 2) {
for(var i = 1; i < arguments.length - 1; i++) {
parameters.push(arguments[i]);
};
};
var userFunction = arguments[arguments.length - 1];
var beforeMessage = Cucumber.Ast.TreeWalker.BEFORE_MESSAGE_PREFIX + message;
var afterMessage = Cucumber.Ast.TreeWalker.AFTER_MESSAGE_PREFIX + message;
var beforeParameters = [beforeMessage].concat(parameters);
var afterParameters = [afterMessage].concat(parameters);

self.broadcastMessage.apply(this, beforeParameters);
userFunction();
self.broadcastMessage.apply(this, [afterMessage].concat(parameters));
},
broadcastUserFunction: function broadcastUserFunction() {
var payload = self.extractMessagePayloadFromArguments(arguments);
var userFunction = self.extractUserFunctionFromArguments(arguments);
var callback = self.extractCallbackFromArguments(arguments);
var callUserFunction = self.wrapUserFunctionAndAfterMessageBroadcast(userFunction, payload, callback);
self.broadcastBeforeMessage(payload, callUserFunction);

// self.broadcastBeforeMessage(
// messageParameters,
// function() {
// userFunction(
// function() {
// self.broadcastAfterMessage(messageParameters, callback);
// };
// );
// }
// );

// var message = arguments[0];
// var parameters = [];
// if (arguments.length > 3) {
// for(var i = 1; i < arguments.length - 2; i++) {
// parameters.push(arguments[i]);
// };
// };
// var userFunction = arguments[arguments.length - 2];
// var callback = arguments[arguments.length - 1];
// var beforeMessage = Cucumber.Ast.TreeWalker.BEFORE_MESSAGE_PREFIX + message;
// var afterMessage = Cucumber.Ast.TreeWalker.AFTER_MESSAGE_PREFIX + message;
// var afterParameters = [afterMessage].concat(parameters);
// afterParameters.push(callback);
// var beforeParameters = [beforeMessage].concat(parameters);
// beforeParameters.push(userFunctionCaller);
// function userFunctionCaller(callback) {
// userFunction(afterMessageBroadcastCaller);
// }
// function afterMessageBroadcastCaller(callback) {
// self.broadcastMessage.apply(this, afterParameters);
// };

// self.broadcastMessage.apply(this, beforeParameters);
},

extractMessagePayloadFromArguments: TODO("extractMessagePayloadFromArguments()"),
extractUserFunctionFromArguments: TODO("extractUserFunctionFromArguments()"),
extractCallbackFromArguments: TODO("extractCallbackFromArguments()"),
wrapUserFunctionAndAfterMessageBroadcast: TODO("wrapUserFunctionAndAfterMessageBroadcast()"),
broadcastBeforeMessage: TODO("broadcastBeforeMessage()"),

broadcastMessage: function broadcastMessage() {
var message = arguments[0];
Expand Down
Loading

0 comments on commit 3e69e98

Please sign in to comment.