Skip to content
Browse files

[api test] Added preliminary step definitions and refined vows runner

  • Loading branch information...
1 parent 908103d commit 4e415421c26c272a106b0c5500a494fd4ac49854 @indexzero indexzero committed Sep 9, 2010
Showing with 179 additions and 1 deletion.
  1. 0 examples/vows-steps.js
  2. +11 −1 lib/kyuri.js
  3. +95 −0 lib/kyuri/runners/vows.js
  4. +36 −0 lib/kyuri/steps.js
  5. +37 −0 test/vows-runner-test.js
View
0 examples/vows-steps.js
No changes.
View
12 lib/kyuri.js
@@ -10,10 +10,20 @@ require.paths.unshift(__dirname);
var kyuri = exports;
-kyuri.version = '0.0.1';
+//
+// Export core methods
+//
+kyuri.version = '0.1.0';
kyuri.compile = require('kyuri/core').compile;
kyuri.parse = require('kyuri/core').parse;
kyuri.tokens = require('kyuri/core').tokens;
kyuri.nodes = require('kyuri/core').nodes;
kyuri.setLanguage = require('kyuri/core').setLanguage;
kyuri.i18n = require('kyuri/core').i18n;
+kyuri.Steps = require('kyuri/steps');
+
+//
+// Export runners
+//
+kyuri.runners = {};
+kyuri.runners.vows = require('kyuri/runners/vows');
View
95 lib/kyuri/runners/vows.js
@@ -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;
+};
View
36 lib/kyuri/steps.js
@@ -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;
+};
View
37 test/vows-runner-test.js
@@ -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);

0 comments on commit 4e41542

Please sign in to comment.
Something went wrong with that request. Please try again.