Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api test] Added preliminary step definitions and refined vows runner
- Loading branch information
Showing
5 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* vows.js: Methods for interacting with vows during test execution. | ||
* | ||
* (C) 2010 Charlie Robbins | ||
* MIT LICENSE | ||
* | ||
*/ | ||
|
||
var vows = require('vows'), | ||
assert = require('assert'), | ||
eyes = require('eyes'); | ||
|
||
// | ||
// Attempts to match against the pattern. If a match | ||
// is found it should then merge the topics together | ||
// and call the step generator with the merged topic | ||
// and any matches. | ||
// | ||
var mergingTopic = function (step, text, topics) { | ||
var match, topic = {}; | ||
if(!(match = step.pattern.match(text))) { | ||
return; | ||
} | ||
|
||
topics.forEach(function (item) { topic.merge(item) }); | ||
|
||
return function () { | ||
step.generator.call(this, topic, match.slice(1)); | ||
}; | ||
}; | ||
|
||
exports.findStep = function (text, steps) { | ||
|
||
}; | ||
|
||
exports.createVows = function (filename, features) { | ||
// For each set of features in a single file (i.e. module) | ||
// setup the vows suite to export or run | ||
var suite = vows.describe(filename); | ||
Object.keys(features).forEach(function (i) { | ||
// For each feature create a new batch | ||
var feature = features[i], | ||
batch = {}; | ||
|
||
feature.scenarios.forEach(function (scenario) { | ||
// For each scenario in the feature, add a context for that scenario | ||
// at the same level: top-level contexts that can be run concurrently. | ||
batch[scenario.name] = exports.scenarioVows(scenario); | ||
}); | ||
|
||
eyes.inspect(batch); | ||
|
||
// The the batch representing the feature to the suite | ||
suite.addBatch(batch); | ||
}); | ||
|
||
return suite; | ||
}; | ||
|
||
exports.scenarioVows = function (scenario) { | ||
// Create root context, and set current context to it. | ||
var context = {}, current = context, then = false; | ||
|
||
if (scenario.outline) { | ||
// If the scenario is a 'Scenario Outline' | ||
|
||
} | ||
else { | ||
// Otherwise if it is just a 'Scenario' | ||
scenario.breakdown.forEach(function (breakdown) { | ||
var breakdown = breakdown[Object.keys(breakdown).shift()], | ||
text = breakdown.join(' '); | ||
|
||
// Remark: i18n compatibility here | ||
if(breakdown[0] === 'THEN') { | ||
then = true; | ||
} | ||
|
||
if (!then) { | ||
// If we haven't seen 'then' we must make these nested contexts | ||
current[text] = { | ||
topic: text //exports.findStep(text, steps) | ||
}; | ||
|
||
current = current[text]; | ||
} | ||
else { | ||
// If we have passed a 'then' keyword, we can now add tests to this context | ||
current[text] = text //exports.findStep(text, steps); | ||
} | ||
}); | ||
} | ||
|
||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* steps.js: Wrapper functions for Kyuri step definitions. | ||
* | ||
* (C) 2010 Charlie Robbins | ||
* MIT LICENSE | ||
* | ||
*/ | ||
|
||
var steps = []; | ||
exports.Given = function (pattern, topicGenerator) { | ||
steps.push({ | ||
operator: 'Given', | ||
pattern: pattern, | ||
generator: topicGenerator | ||
}); | ||
}; | ||
|
||
exports.When = function (pattern, topicGenerator) { | ||
steps.push({ | ||
operator: 'When', | ||
pattern: pattern, | ||
generator: topicGenerator | ||
}); | ||
}; | ||
|
||
exports.Then = function (pattern, callbackGenerator) { | ||
steps.push({ | ||
operator: 'Given', | ||
pattern: pattern, | ||
generator: callbackGenerator | ||
}); | ||
}; | ||
|
||
exports.export = function (module) { | ||
module.exports = steps; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* lexer-test.js: More complex tests for the Kyuri lexer. | ||
* | ||
* (C) 2010 Charlie Robbins | ||
* MIT LICENSE | ||
* | ||
*/ | ||
|
||
require.paths.unshift(require('path').join(__dirname, '..', 'lib')); | ||
|
||
var kyuri = require('kyuri'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
vows = require('vows'), | ||
assert = require('assert'), | ||
eyes = require('eyes'); | ||
|
||
var readAllLines = function (filename) { | ||
return function () { | ||
fs.readFile(filename, encoding = 'ascii', this.callback); | ||
} | ||
}; | ||
|
||
vows.describe('kyuri/parser').addBatch({ | ||
"When using the Kyuri step definitions,": { | ||
"running vows created from simple.feature": { | ||
topic: readAllLines(path.join(__dirname, '..', 'examples', 'simple.feature')), | ||
"should return proper vows": function (err, data) { | ||
var text = data.toString(); | ||
assert.isNotNull(text); | ||
|
||
var suite = kyuri.runners.vows.createVows('simple.feature', kyuri.parse(data.toString()).ast); | ||
assert.equal(suite.batches.length, 1); | ||
} | ||
} | ||
} | ||
}).export(module); |