Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
s9tpepper committed Aug 3, 2012
1 parent 3126477 commit 3ecd496
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
*.iml
.DS_Store
node_modules
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# grunt-cucumber-js

A grunt.js task to run your cucumber.js feature suite.

## Getting Started
Install this grunt plugin next to your project's grunt.js gruntfile with: `npm install grunt-cucumber-js`

Then add this line to your project's `grunt.js` gruntfile:

```javascript
grunt.initConfig({
cucumberjs: {
features: "path/to/features",
steps: "path/to/step_definitions",
tags: "@dev"
}
});

grunt.loadNpmTasks('grunt-cucumber-js');

grunt.registerTask('default', 'cucumberjs');
```

## Bugs

Help us squash them by submitting an issue that describes how you encountered it; please be as specific as possible including operating system, node, grunt, and grunt-contrib versions.

## Release History

see [CHANGELOG](/s9tpepper/grunt-cucumber-js/blob/master/CHANGELOG).

## License
Copyright (c) 2012 "s9tpepper" Omar Gonzalez & contributors.
Licensed under the MIT license.
9 changes: 9 additions & 0 deletions features/Testing.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Testing
As a grunt-cucumber-js dev
I want a Testing.feature file
So that I can test the cucumber-js-task

Scenario: A test scenario
Given I have the number 1 and 3
When I add them together
Then I should have 4
27 changes: 27 additions & 0 deletions features/step_definitions/Testing_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Testing_steps() {
var firstNumber;
var secondNumber;
var sum = 0;

this.Given(/^I have the number (\d+) and (\d+)$/, function(arg1, arg2, callback) {
firstNumber = parseInt(arg1);
secondNumber = parseInt(arg2);
callback();
});

this.When(/^I add them together$/, function(callback) {
sum = firstNumber + secondNumber;
callback();
});

this.Then(/^I should have (\d+)$/, function(arg1, callback) {
var expectedSum = parseInt(arg1);
if (expectedSum !== sum) {
throw new Error("It doesn't add up! " + arg1 + " !== " + sum);
}
callback();
});

};

module.exports = Testing_steps;
37 changes: 37 additions & 0 deletions grunt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = function (grunt) {
'use strict';

grunt.initConfig({
lint: {
all: ['grunt.js', 'tasks/*.js']
},
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
node: true,
es5: true
},
globals: {}
},
cucumberjs: {
features: "features",
steps: "features/step_definitions"
}
});

grunt.loadNpmTasks('grunt-contrib');

grunt.loadTasks("tasks");

grunt.registerTask('default', 'lint cucumberjs');

};
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name" : "grunt-cucumber",
"description" : "Grunt task for running Cucumber.js",
"version" : "0.1.0",
"homepage" : "https://github.com/s9tpepper/grunt-cucumber-js",
"author" : {
"name" : "Omar Gonzalez",
"email" : "[email protected]",
"url" : "http://omar.likesflex.com"
},
"repository" : {
"type" : "git",
"url" : "git://github.com/s9tpepper/grunt-cucumber-js.git"
},
"bugs" : {
"url" : "https://github.com/s9tpepper/grunt-cucumber-js/issues"
},
"licenses" : [
{
"type" : "MIT",
"url" : "https://github.com/s9tpepper/grunt-cucumber-js/blob/master/LICENSE-MIT"
}
],
"main" : "grunt.js",
"bin" : "bin/grunt-cucumber",
"engines" : {
"node" : "*"
},
"scripts" : {
},
"dependencies" : {
},
"devDependencies" : {
"grunt" : "~0.3.9",
"grunt-contrib": "~0.1.4",
"cucumber": "~0.2.19"
},
"keywords" : [
"gruntplugin"
]
}
51 changes: 51 additions & 0 deletions tasks/cucumber-js-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = function (grunt) {

grunt.registerTask("cucumberjs", "Runs cucumber.js", function () {

var Cucumber = require('cucumber');

var features = grunt.config("cucumberjs.features") || 'features';
var steps = grunt.config("cucumberjs.steps") || 'features/step_definitions';
var tags = grunt.config("cucumberjs.tags") || '~@Pending';

var options = [ 'node',
'cucumber-js-task.js',
features,
'-r',
steps,
'-t',
tags ];

var cli = Cucumber.Cli(options);

var done = this.async();
cli.run(function(succeeded) {
var code = succeeded ? 0 : 1;
var exitFunction = function() {
if (code !== 0) {
process.exit(code);
} else {
done();
}
};

// --- exit after waiting for all pending output ---
var waitingIO = false;
process.stdout.on('drain', function() {
if (waitingIO) {
// the kernel buffer is now empty
exitFunction();
}
});
if (process.stdout.write("")) {
// no buffer left, exit now:
exitFunction();
} else {
// write() returned false, kernel buffer is not empty yet...
waitingIO = true;
}
});

});

};

0 comments on commit 3ecd496

Please sign in to comment.