Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6fc78c6d5748bfb07180924e7c6c2b22d855084a @jbpros jbpros committed May 27, 2011
@@ -0,0 +1,4 @@
+.DS_Store
+node_modules
+*~
+.#*
22 LICENSE
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2011 Julien Biezemans
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
+# Cucumber.js
+
+Cucumber brought (natively) to your JavaScript stack.
+
+It can run basic fatures inside both Node.js and web browsers.
+
+It still needs a lot of work. Only a few feature elements are supported at the moment.
+
+## Prerequesites
+
+* Node.js 0.4.8 (tested on 0.4.7 too)
+* npm 1.0.6
+
+### Works on
+
+* Node.js 0.4.7, 0.4.8, 0.5.0-pre
+* Google Chrome 13.0.772.0 (dev)
+* Firefox 4.0.1
+* Safari 5.0.5
+
+And probably lots of other browsers.
+
+## Play with it!
+
+ $ open example/index.html
+
+## Setup for using in Node.js and running tests
+
+The only dependency of cucumber.js is Gherkin:
+
+ $ npm link
+
+## Run tests
+
+Specs:
+
+ $ cd spec
+ $ ../node_modules/.bin/jasmine-node .
+
+Features (yes, cucumber.js is eating itself):
+
+ $ node cucumber.js features/basic.feature
@@ -0,0 +1,22 @@
+var fs = require('fs');
+var Cucumber = require('./lib/cucumber');
+var supportCode = require('./features/step_definitions/cucumber_steps');
+var cucumber = Cucumber(fs.readFileSync(process.ARGV[2]), supportCode);
+var simpleListener = Cucumber.Debug.SimpleAstListener({logToConsole: true});
+cucumber.attachListener(simpleListener);
+cucumber.start(function() {
+ /*
+ Some "after" messages from the tree walker are still not processed when
+ the callback is triggered. It means that post-processing might still
+ be on hold on listeners. This is due to
+ Cucumber.TreeWalker.broadcastMessagesBeforeAndAfterFunction() using no
+ callback and expecting the passed function to handle the possible
+ callback.
+
+ Fixing this is easy: broadcastMessagesBeforeAndAfterFunction() would
+ need a callback and run it AFTER broadcasting "after" messages.
+
+ Uncomment the following line to see that behaviour:
+ */
+ // console.log("Done. But too soon, some dudes haven't finished doing their stuff just yet.");
+});
@@ -0,0 +1,20 @@
+html, body {
+ margin:1em;
+ min-height:100%;
+ font-family:helvetica, arial, freesans, clean, sans-serif;
+ font-size:.95em;
+}
+
+#feature, #step-definitions, #output, #errors {
+ width:700px;
+ font-family:'Bitstream Vera Sans Mono', Courier, monospace;
+ font-size:1em;
+}
+
+#feature, #step-definitions, #output {
+ height:12em;
+}
+
+#errors {
+ color: #a30;
+}
@@ -0,0 +1,46 @@
+function runFeature() {
+ var supportCode;
+ var output = $('#output');
+ var errors = $('#errors');
+ var errorsContainer = $('#errors-container');
+ var featureSource = $('#feature').val();
+ eval('supportCode = function() {' + $('#step-definitions').val() + '};');
+ var cucumber = Cucumber(featureSource, supportCode);
+ var simpleListener = Cucumber.Debug.SimpleAstListener({logToFunction: function(message) {
+ output.val(output.val() + message + "\n");
+ }});
+ cucumber.attachListener(simpleListener);
+ output.val('');
+ errors.text('');
+ errorsContainer.hide();
+ try {
+ cucumber.start(function() {
+ /*
+ Some "after" messages from the tree walker are still not processed when
+ the callback is triggered. It means that post-processing might still
+ be on hold on listeners. This is due to
+ Cucumber.TreeWalker.broadcastMessagesBeforeAndAfterFunction() using no
+ callback and expecting the passed function to handle the possible
+ callback.
+
+ Fixing this is easy: broadcastMessagesBeforeAndAfterFunction() would
+ need a callback and run it AFTER broadcasting "after" messages.
+
+ Uncomment the following line to see that behaviour:
+ */
+ //console.log("Done. But too soon, some dudes haven't finished doing their stuff just yet.");
+ });
+ } catch(err) {
+ errorsContainer.show();
+ var errMessage = err.message || err;
+ var buffer = (errors.text() == '' ? errMessage : errors.text() + "\n\n" + errMessage);
+ errors.text(buffer);
+ throw err;
+ };
+};
+
+$(function() {
+ Gherkin = { Lexer: function() { return Lexer; } };
+ $('#run-feature').click(runFeature);
+ $('#errors-container').hide();
+});
@@ -0,0 +1,52 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ <title>Cucumber.js</title>
+ <link href="example.css" rel="stylesheet" type="text/css"/>
+ <script type="text/javascript" src="vendor/jquery-1.6.1.min.js"></script>
+ <script type="text/javascript" src="vendor/gherkin.en.js"></script>
+ <script type="text/javascript" src="../lib/cucumber.js"></script>
+ <script type="text/javascript" src="example.js"></script>
+ </head>
+ <body>
+ <h1>Cucumber.js</h1>
+ <h2>Feature source</h2>
+ <textarea id="feature">Feature: Simple maths
+ In order to do maths
+ As a developer
+ I want to increment variables
+
+ Scenario: Increment variable once
+ Given a variable set to 1
+ When I increment the variable by 1
+ Then the variable should contain 2</textarea>
+ <h2>Step definitions</h2>
+ <textarea id="step-definitions">var variable;
+
+Given(/a variable set to (\d+)/, function(number, callback) {
+ variable = parseInt(number);
+ callback();
+});
+
+When(/I increment the variable by (\d+)/, function(number, callback) {
+ variable += parseInt(number);
+ callback();
+});
+
+Then(/the variable should contain (\d+)/, function(number, callback) {
+ if (variable != parseInt(number))
+ throw('Variable should contain '+number+' but it contains '+variable+'.');
+ callback();
+});</textarea>
+
+ <h2>Output</h2>
+ <p><button id="run-feature">Run feature</button></p>
+ <textarea readonly="readonly" id="output"></textarea>
+ <div id="errors-container">
+ <h3>Errors</h3>
+ <pre id="errors"></pre>
+ </div>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 6fc78c6

Please sign in to comment.