Skip to content

Commit

Permalink
Store step on step results (#57)
Browse files Browse the repository at this point in the history
- 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
jbpros committed Apr 13, 2012
1 parent 812e856 commit aa27ab1
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 153 deletions.
1 change: 1 addition & 0 deletions lib/cucumber/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
21 changes: 10 additions & 11 deletions lib/cucumber/runtime/failed_step_result.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 7 additions & 8 deletions lib/cucumber/runtime/pending_step_result.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 5 additions & 10 deletions lib/cucumber/runtime/skipped_step_result.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions lib/cucumber/runtime/step_result.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 7 additions & 8 deletions lib/cucumber/runtime/successful_step_result.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 5 additions & 10 deletions lib/cucumber/runtime/undefined_step_result.js
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 4 additions & 3 deletions lib/cucumber/support_code/step_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
30 changes: 12 additions & 18 deletions spec/cucumber/runtime/failed_step_result_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
28 changes: 11 additions & 17 deletions spec/cucumber/runtime/pending_step_result_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
33 changes: 10 additions & 23 deletions spec/cucumber/runtime/skipped_step_result_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
37 changes: 37 additions & 0 deletions spec/cucumber/runtime/step_result_spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
28 changes: 11 additions & 17 deletions spec/cucumber/runtime/successful_step_result_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Loading

0 comments on commit aa27ab1

Please sign in to comment.