Permalink
Browse files

Store step on step results (#57)

- The parent step is now available on all types of step results
- Step results "inherit" from a base step result object (extraction refactoring)
  • Loading branch information...
1 parent 812e856 commit aa27ab1b81eaaee029da351a829c25a502d85fa3 @jbpros jbpros committed Apr 13, 2012
View
@@ -34,6 +34,7 @@ var Runtime = function(configuration) {
};
Runtime.START_MISSING_CALLBACK_ERROR = "Cucumber.Runtime.start() expects a callback";
Runtime.AstTreeWalker = require('./runtime/ast_tree_walker');
+Runtime.StepResult = require('./runtime/step_result');
Runtime.SuccessfulStepResult = require('./runtime/successful_step_result');
Runtime.PendingStepResult = require('./runtime/pending_step_result');
Runtime.FailedStepResult = require('./runtime/failed_step_result');
@@ -1,15 +1,14 @@
-var FailedStepResult = function(failureException) {
- var self = {
- isFailed: function isFailed() { return true; },
- isPending: function isPending() { return false; },
- isSkipped: function isSkipped() { return false; },
- isSuccessful: function isSuccessful() { return false; },
- isUndefined: function isUndefined() { return false; },
-
- getFailureException: function getFailureException() {
- return failureException;
- }
+var FailedStepResult = function(payload) {
+ var Cucumber = require('../../cucumber');
+
+ var self = Cucumber.Runtime.StepResult(payload);
+
+ self.isFailed = function isFailed() { return true; };
+
+ self.getFailureException = function getFailureException() {
+ return payload.failureException;
};
+
return self;
};
module.exports = FailedStepResult;
@@ -1,11 +1,10 @@
-var PendingStepResult = function() {
- var self = {
- isFailed: function isFailed() { return false; },
- isPending: function isPending() { return true; },
- isSkipped: function isSkipped() { return false; },
- isSuccessful: function isSuccessful() { return false; },
- isUndefined: function isUndefined() { return false; }
- };
+var PendingStepResult = function(payload) {
+ var Cucumber = require('../../cucumber');
+
+ var self = Cucumber.Runtime.StepResult(payload);
+
+ self.isPending = function isPending() { return true; };
+
return self;
};
module.exports = PendingStepResult;
@@ -1,15 +1,10 @@
var SkippedStepResult = function(payload) {
- var self = {
- isFailed: function isFailed() { return false; },
- isPending: function isPending() { return false; },
- isSkipped: function isSkipped() { return true; },
- isSuccessful: function isSuccessful() { return false; },
- isUndefined: function isUndefined() { return false; },
+ var Cucumber = require('../../cucumber');
+
+ var self = Cucumber.Runtime.StepResult(payload);
+
+ self.isSkipped = function isSkipped() { return true; };
- getStep: function getStep() {
- return payload['step'];
- }
- };
return self;
};
module.exports = SkippedStepResult;
@@ -0,0 +1,17 @@
+var StepResult = function (payload) {
+ var self = {
+ isFailed: function isFailed() { return false; },
+ isPending: function isPending() { return false; },
+ isSkipped: function isSkipped() { return false; },
+ isSuccessful: function isSuccessful() { return false; },
+ isUndefined: function isUndefined() { return false; },
+
+ getStep: function getStep() {
+ return payload.step;
+ }
+ };
+
+ return self;
+};
+
+module.exports = StepResult;
@@ -1,11 +1,10 @@
-var SuccessfulStepResult = function() {
- var self = {
- isFailed: function isFailed() { return false; },
- isPending: function isPending() { return false; },
- isSkipped: function isSkipped() { return false; },
- isSuccessful: function isSuccessful() { return true; },
- isUndefined: function isUndefined() { return false; }
- };
+var SuccessfulStepResult = function(payload) {
+ var Cucumber = require('../../cucumber');
+
+ var self = Cucumber.Runtime.StepResult(payload);
+
+ self.isSuccessful = function isSuccessful() { return true; };
+
return self;
};
module.exports = SuccessfulStepResult;
@@ -1,15 +1,10 @@
var UndefinedStepResult = function(payload) {
- var self = {
- isFailed: function isFailed() { return false; },
- isPending: function isPending() { return false; },
- isSkipped: function isSkipped() { return false; },
- isSuccessful: function isSuccessful() { return false; },
- isUndefined: function isUndefined() { return true; },
+ var Cucumber = require('../../cucumber');
+
+ var self = Cucumber.Runtime.StepResult(payload);
+
+ self.isUndefined = function isUndefined() { return true; };
- getStep: function getStep() {
- return payload['step'];
- }
- };
return self;
};
module.exports = UndefinedStepResult;
@@ -10,17 +10,18 @@ var StepDefinition = function(regexp, code) {
invoke: function invoke(step, world, callback) {
var codeCallback = function() {
- var successfulStepResult = Cucumber.Runtime.SuccessfulStepResult();
+ var successfulStepResult = Cucumber.Runtime.SuccessfulStepResult({step: step});
callback(successfulStepResult);
};
codeCallback.pending = function pending(reason) {
- var pendingStepResult = Cucumber.Runtime.PendingStepResult(reason);
+ var pendingStepResult = Cucumber.Runtime.PendingStepResult({step: step, pendingReason: reason});
callback(pendingStepResult);
};
codeCallback.fail = function fail(failureReason) {
- var failedStepResult = Cucumber.Runtime.FailedStepResult(failureReason || new Error(UNKNOWN_STEP_FAILURE_MESSAGE));
+ var failureException = failureReason || new Error(UNKNOWN_STEP_FAILURE_MESSAGE);
+ var failedStepResult = Cucumber.Runtime.FailedStepResult({step: step, failureException: failureException});
callback(failedStepResult);
};
@@ -2,36 +2,30 @@ require('../../support/spec_helper');
describe("Cucumber.Runtime.FailedStepResult", function() {
var Cucumber = requireLib('cucumber');
- var stepResult, failureException;
+ var failedStepResult, failureException, stepResult, step, payload;
beforeEach(function() {
+ stepResult = createSpy("base step result");
+ spyOn(Cucumber.Runtime, 'StepResult').andReturn(stepResult);
+ step = createSpy("step");
failureException = createSpy("failure exception");
- stepResult = Cucumber.Runtime.FailedStepResult(failureException);
+ payload = {step: step, failureException: failureException};
+ failedStepResult = Cucumber.Runtime.FailedStepResult(payload);
});
it("is failed", function() {
- expect(stepResult.isFailed()).toBeTruthy();
+ expect(failedStepResult.isFailed()).toBeTruthy();
});
- it("is not pending", function() {
- expect(stepResult.isPending()).toBeFalsy();
- });
-
- it("is not skipped", function() {
- expect(stepResult.isSkipped()).toBeFalsy();
- });
-
- it("is not successful", function () {
- expect(stepResult.isSuccessful()).toBeFalsy();
- });
-
- it("is not undefined", function() {
- expect(stepResult.isUndefined()).toBeFalsy();
+ describe("constructor", function() {
+ it("instantiates a step result", function() {
+ expect(Cucumber.Runtime.StepResult).toHaveBeenCalledWith(payload);
+ });
});
describe("getFailureException()", function() {
it("returns the exception passed to the constructor", function() {
- expect(stepResult.getFailureException()).toBe(failureException);
+ expect(failedStepResult.getFailureException()).toBe(failureException);
});
});
});
@@ -2,29 +2,23 @@ require('../../support/spec_helper');
describe("Cucumber.Runtime.PendingStepResult", function() {
var Cucumber = requireLib('cucumber');
- var stepResult;
+ var pendingStepResult, stepResult, step, payload;;
beforeEach(function() {
- stepResult = Cucumber.Runtime.PendingStepResult();
- });
-
- it("is not failed", function() {
- expect(stepResult.isFailed()).toBeFalsy();
+ pendingStepResult = createSpy("base step result");
+ spyOn(Cucumber.Runtime, 'StepResult').andReturn(pendingStepResult);
+ step = createSpy("step");
+ payload = {step: step};
+ pendingStepResult = Cucumber.Runtime.PendingStepResult(payload);
});
it("is pending", function() {
- expect(stepResult.isPending()).toBeTruthy();
- });
-
- it("is not skipped", function() {
- expect(stepResult.isSkipped()).toBeFalsy();
- });
-
- it("is not successful", function () {
- expect(stepResult.isSuccessful()).toBeFalsy();
+ expect(pendingStepResult.isPending()).toBeTruthy();
});
- it("is not undefined", function() {
- expect(stepResult.isUndefined()).toBeFalsy();
+ describe("constructor", function() {
+ it("instantiates a step result", function() {
+ expect(Cucumber.Runtime.StepResult).toHaveBeenCalledWith(payload);
+ });
});
});
@@ -2,36 +2,23 @@ require('../../support/spec_helper');
describe("Cucumber.Runtime.SkippedStepResult", function() {
var Cucumber = requireLib('cucumber');
- var stepResult, step;
+ var skippedStepResult, stepResult, step, payload;;
beforeEach(function() {
- step = createSpy("step");
- stepResult = Cucumber.Runtime.SkippedStepResult({step: step});
- });
-
- it("is not failed", function() {
- expect(stepResult.isFailed()).toBeFalsy();
- });
-
- it("is not pending", function() {
- expect(stepResult.isPending()).toBeFalsy();
+ skippedStepResult = createSpy("base step result");
+ spyOn(Cucumber.Runtime, 'StepResult').andReturn(skippedStepResult);
+ step = createSpy("step");
+ payload = {step: step};
+ skippedStepResult = Cucumber.Runtime.SkippedStepResult(payload);
});
it("is skipped", function() {
- expect(stepResult.isSkipped()).toBeTruthy();
- });
-
- it("is not successful", function () {
- expect(stepResult.isSuccessful()).toBeFalsy();
- });
-
- it("is not undefined", function() {
- expect(stepResult.isUndefined()).toBeFalsy();
+ expect(skippedStepResult.isSkipped()).toBeTruthy();
});
- describe("getStep()", function() {
- it("returns the step passed to the constructor", function() {
- expect(stepResult.getStep()).toBe(step);
+ describe("constructor", function() {
+ it("instantiates a step result", function() {
+ expect(Cucumber.Runtime.StepResult).toHaveBeenCalledWith(payload);
});
});
});
@@ -0,0 +1,37 @@
+require('../../support/spec_helper');
+
+describe("Cucumber.Runtime.StepResult", function() {
+ var Cucumber = requireLib('cucumber');
+ var stepResult, step;
+
+ beforeEach(function() {
+ step = createSpy("step");
+ stepResult = Cucumber.Runtime.StepResult({step: step});
+ });
+
+ it("is not failed", function() {
+ expect(stepResult.isFailed()).toBeFalsy();
+ });
+
+ it("is not pending", function() {
+ expect(stepResult.isPending()).toBeFalsy();
+ });
+
+ it("is not skipped", function() {
+ expect(stepResult.isSkipped()).toBeFalsy();
+ });
+
+ it("is not successful", function () {
+ expect(stepResult.isSuccessful()).toBeFalsy();
+ });
+
+ it("is not undefined", function() {
+ expect(stepResult.isUndefined()).toBeFalsy();
+ });
+
+ describe("getStep()", function() {
+ it("returns the step passed to the constructor", function() {
+ expect(stepResult.getStep()).toBe(step);
+ });
+ });
+});
@@ -2,29 +2,23 @@ require('../../support/spec_helper');
describe("Cucumber.Runtime.SuccessfulStepResult", function() {
var Cucumber = requireLib('cucumber');
- var stepResult;
+ var successfulStepResult, stepResult, step, payload;
beforeEach(function() {
- stepResult = Cucumber.Runtime.SuccessfulStepResult();
- });
-
- it("is not failed", function() {
- expect(stepResult.isFailed()).toBeFalsy();
- });
-
- it("is not pending", function() {
- expect(stepResult.isPending()).toBeFalsy();
- });
-
- it("is not skipped", function() {
- expect(stepResult.isSkipped()).toBeFalsy();
+ stepResult = createSpy("base step result");
+ spyOn(Cucumber.Runtime, 'StepResult').andReturn(stepResult);
+ step = createSpy("step");
+ payload = {step: step};
+ successfulStepResult = Cucumber.Runtime.SuccessfulStepResult(payload);
});
it("is successful", function () {
- expect(stepResult.isSuccessful()).toBeTruthy();
+ expect(successfulStepResult.isSuccessful()).toBeTruthy();
});
- it("is not undefined", function() {
- expect(stepResult.isUndefined()).toBeFalsy();
+ describe("constructor", function() {
+ it("instantiates a step result", function() {
+ expect(Cucumber.Runtime.StepResult).toHaveBeenCalledWith(payload);
+ });
});
});
Oops, something went wrong.

0 comments on commit aa27ab1

Please sign in to comment.