Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish Cucumber.js example (fixes #8)
The example test suite is now in `examples/cucumber`. Run it like so: make cucumber.js
- Loading branch information
Lon Ingram
committed
Aug 30, 2012
1 parent
ea2ef55
commit 41fd5b9
Showing
13 changed files
with
230 additions
and
163 deletions.
There are no files selected for viewing
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
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,20 @@ | ||
Feature: Navigation | ||
As a SpookyJS user | ||
I would like to use the navigation API | ||
|
||
Scenario: Back | ||
Given I go to "/1.html" | ||
And I go to "/2.html" | ||
And I go to "/3.html" | ||
When I go back | ||
Then I should be on "2\.html" | ||
And run | ||
|
||
Scenario: Forward | ||
Given I go to "/1.html" | ||
And I go to "/2.html" | ||
And I go to "/3.html" | ||
And I go back | ||
When I go forward | ||
Then I should be on "3\.html" | ||
And run |
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,38 @@ | ||
module.exports = function () { | ||
this.World = require('../support/world.js').World; | ||
|
||
function go(url, callback) { | ||
this.spooky.thenOpen(this.baseUrl + url); | ||
callback(); | ||
} | ||
|
||
function goBack(callback) { | ||
this.spooky.back(); | ||
callback(); | ||
} | ||
|
||
function goForward(callback) { | ||
this.spooky.forward(); | ||
callback(); | ||
} | ||
|
||
this.Given('I go to "$url"', go); | ||
this.When('I go to "$url"', go); | ||
|
||
this.Given('I go back', goBack); | ||
this.When('I go back', goBack); | ||
|
||
this.Given('I go forward', goForward); | ||
this.When('I go forward', goForward); | ||
|
||
this.Then('I should be on "$url"', function shouldBeOn(url, callback) { | ||
this.spooky.then([{ | ||
url: url | ||
}, function () { | ||
this.echo(this.getCurrentUrl()); | ||
this.test.assertUrlMatch(new RegExp(url)); | ||
}]); | ||
callback(); | ||
}); | ||
}; | ||
|
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,23 @@ | ||
module.exports = function () { | ||
this.World = require('../support/world.js').World; | ||
|
||
this.Then('run', function (callback) { | ||
var world = this; | ||
|
||
this.spooky.then(function () { | ||
this.emit('tests.complete', this.test.testResults); | ||
}); | ||
|
||
this.spooky.once('tests.complete', (function (results) { | ||
if (results.failed) { | ||
callback.fail(results.failures.map(function (failure) { | ||
return 'Failed: ' + failure.message; | ||
}).join('\n')); | ||
} else { | ||
callback(); | ||
} | ||
}).bind(this)); | ||
|
||
this.spooky.run(); | ||
}); | ||
}; |
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,82 @@ | ||
var util = require('util'); | ||
var Spooky = require('../../../../lib/spooky'); | ||
|
||
var World = function World(callback) { | ||
var spooky; | ||
var world = this; | ||
|
||
this.baseUrl = 'http://localhost:' + process.env.TEST_PORT; | ||
|
||
try { | ||
spooky = world.spooky = new Spooky({ | ||
casper: { | ||
verbose: true, | ||
logLevel: 'debug' | ||
}, | ||
child: { | ||
port: 8081, | ||
spooky_lib: './node_modules', | ||
script: './lib/bootstrap.js' | ||
} | ||
}, onCreated); | ||
} catch (e) { | ||
console.dir(e) | ||
console.trace('Spooky.listen failed'); | ||
} | ||
|
||
//spooky.debug = true; | ||
|
||
// track errors | ||
spooky.errors = []; | ||
spooky.on('error', function (error) { | ||
error = error.data ? error.data : error; | ||
spooky.errors.push(error); | ||
if (spooky.debug) { | ||
console.error('spooky error', util.inspect(error)); | ||
} | ||
}); | ||
|
||
spooky.console = []; | ||
spooky.on('console', function (line) { | ||
spooky.console.push(line); | ||
if (spooky.debug) { | ||
console.log(line); | ||
} | ||
}); | ||
|
||
spooky.on('log', function (entry) { | ||
if (!spooky.debug) { return; } | ||
var message = entry.message; | ||
var event = (message.event || '').toLowerCase(); | ||
|
||
if (event === 'request') { | ||
console.log('%s: %s %s', | ||
spooky.options.port, message.method, message.request.url); | ||
console.log(' Headers: %s', | ||
util.inspect(message.request.headers)); | ||
console.log(' Payload: %s', | ||
util.inspect(JSON.parse(message.request.post))); | ||
} else if (event === 'response') { | ||
console.log('%s: %s %s', | ||
spooky.options.port, message.code, | ||
util.inspect(JSON.parse(message.body))); | ||
} else { | ||
console.log(spooky.options.port + ':'); | ||
console.dir(entry); | ||
} | ||
}); | ||
|
||
function onCreated(err, error, response) { | ||
if (err) { | ||
throw err; | ||
} else if (error) { | ||
console.dir(error); | ||
throw new Error('Failed to initialize context.spooky: ' + | ||
error.code + ' - ' + error.message); | ||
} | ||
|
||
callback(world); | ||
} | ||
}; | ||
|
||
module.exports.World = World; |
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,38 @@ | ||
module.exports = function () { | ||
var expect = require('expect.js'); | ||
this.World = require('../support/world.js').World; | ||
|
||
this.Given('I go to "$path"', function (path, callback) { | ||
this.spooky.thenOpen(this.testUrl + path); | ||
callback(); | ||
}); | ||
|
||
this.Given('I go back', function (callback) { | ||
this.spooky.back(); | ||
callback(); | ||
}); | ||
|
||
this.Given('I go forward', function (callback) { | ||
this.spooky.forward(); | ||
callback(); | ||
}); | ||
|
||
this.When('I go back', function (callback) { | ||
this.spooky.back(); | ||
callback(); | ||
}); | ||
|
||
this.When('I go forward', function (callback) { | ||
this.spooky.forward(); | ||
callback(); | ||
}); | ||
|
||
this.Then('I should be on "$path"', function (path, callback) { | ||
this.spooky.then([{ | ||
url: this.testUrl + path | ||
}, function () { | ||
this.test.assert(this.getCurrentUrl() === url); | ||
}]); | ||
callback(); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.