Skip to content

Commit

Permalink
Version 0.0.2:
Browse files Browse the repository at this point in the history
* Support for generating files in CoffeeScript format
* Fixed the steps file to raise an error properly
* Fixed the dependency loading so that you don't have to install dependencies at the application level.
* The url is now set to localhost:3000 by default (same as SocketStream default app url).
  • Loading branch information
paulbjensen committed Aug 23, 2012
1 parent d5a9705 commit 550fb84
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 56 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ To seed your SocketStream application with the files and folders required for us
ss-cucumber init


You'll want to edit the support/world.js and replace INSERT_URL_HERE with the url at which your Socketstream application loads (i.e. http://localhost:3000).

You'll notice a socketstream_steps.js file in the step_definitions directory. This provides a list of step definitions to use with your application out of the box. You can create feature files that use these steps to drive the selenium browser.

If you haven't got cucumber.js installed already:
Expand All @@ -42,6 +40,14 @@ Step definitions available

There will be more added over time. This is just a start for now. If you have any that you'd like to see, send me a message, or feel free to fork this branch and make a pull request.

CoffeeScript support
---

If you want your world.js and socketstream_steps.js files in CoffeeScript format instead, simply pass this option:

cd [socketstream app directory]
ss-cucumber init -c

License & Credits
---

Expand Down
5 changes: 3 additions & 2 deletions bin/ss-cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ var program = require('commander');
var ssCucumber = require('../lib/ss-cucumber.js');

program
.version('0.0.1')
.version('0.0.2')
.usage('init')
.option('-c, --coffee', 'Provide world and step_definition files in CoffeeScript format')
.parse(process.argv);

if (program.args[0] == "init") {
ssCucumber.init(process.env["PWD"], function(){
ssCucumber.init(process.env["PWD"], program.coffee, function(){
console.log("Your SocketStream app is now setup to use Cucumber.");
});
};
33 changes: 33 additions & 0 deletions copy/socketstream_steps.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
wrap = (funk, cb) ->
funk.end (err) ->
if !err?
cb()
else
cb.fail err

module.exports = ->

@World = require("../support/world").World

@Given /^I am on the homepage$/, (callback) ->
wrap @browser.chain.session().open('/'), callback

@Given /^I follow "([^"]*)"$/, (link, callback) ->
wrap @browser.chain.click("link=#{link}"), callback

@When /^I fill in "([^"]*)" with "([^"]*)"$/, (field, value, callback) ->
wrap @browser.chain
.fireEvent("//input[@name=\"#{field}\"]",'focus')
.type("//input[@name=\"#{field}\"]", value)
.fireEvent("//input[@name=\"#{field}\"]",'keyup')
.fireEvent("//input[@name=\"#{field}\"]",'blur')
, callback

@When /^I press "([^"]*)"$/, (name, callback) ->
wrap @browser.chain
.fireEvent("//button[text()=\"#{name}\"]",'focus')
.click("//button[text()=\"#{name}\"]")
, callback

@Then /^I should see "([^"]*)"$/, (content, callback) ->
wrap @browser.chain.assertTextPresent(content), callback
19 changes: 10 additions & 9 deletions copy/socketstream_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var wrap = function (funk, cb) {
if (err == null || err == undefined){
cb();
} else {
cb.fail(throw(err));
cb.fail(err);
};
});
};
Expand All @@ -17,22 +17,23 @@ module.exports = function (){
});

this.Given(/^I follow "([^"]*)"$/, function (link, callback) {
wrap(this.browser.chain.click("link=#{link}"), callback);
wrap(this.browser.chain.click("link=" + link), callback);
})

this.When(/^I fill in "([^"]*)" with "([^"]*)"$/, function (field, value, callback) {
wrap(this.browser.chain
.fireEvent("//input[@name=\"#{field}\"]",'focus')
.type("//input[@name=\"#{field}\"]", value)
.fireEvent("//input[@name=\"#{field}\"]",'keyup')
.fireEvent("//input[@name=\"#{field}\"]",'blur')
, callback);
.fireEvent("//input[@name=\"" + field + "\"]",'focus')
.type("//input[@name=\"" + field + "\"]", value)
.fireEvent("//input[@name=\"" + field + "\"]",'keyup')
.fireEvent("//input[@name=\"" + field + "\"]",'blur')
, callback
);
});

this.When(/^I press "([^"]*)"$/, function (name, callback){
wrap(this.browser.chain
.fireEvent("//button[text()=\"#{name}\"]",'focus')
.click("//button[text()=\"#{name}\"]")
.fireEvent("//button[text()=\"" + name + "\"]",'focus')
.click("//button[text()=\"" + name + "\"]")
, callback);
});

Expand Down
18 changes: 18 additions & 0 deletions copy/world.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
process.env["SS_ENV"] = "cucumber"
selenium = require '../../node_modules/ss-cucumber/node_modules/selenium-launcher'
soda = require '../../node_modules/ss-cucumber/node_modules/soda'
app = require '../../app'

World = (callback) ->

selenium (err,selenium) ->
@browser = soda.createClient
host: selenium.host
port: selenium.port
url: "http://localhost:3000"
browser: "firefox"

callback {@browser}
process.on 'exit', -> selenium.kill()

exports.World = World
12 changes: 6 additions & 6 deletions copy/world.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
process.env["SS_ENV"] = "cucumber";
var selenium = require('../../node_modules/ss-cucumber/node_modules/selenium-launcher');
var soda = require('../../node_modules/ss-cucumber/node_modules/soda');
var app = require('../../app');

var World = function(callback){

process.env["SS_ENV"] = "cucumber";
var selenium = require('selenium-launcher');
var soda = require('soda');
var app = require('../../app');

selenium(function(err,selenium){
this.browser = soda.createClient({
host: selenium.host,
port: selenium.port,
url: "INSERT_URL_HERE",
url: "http://localhost:3000",
browser: "firefox"
});
callback({browser: this.browser});
Expand Down
3 changes: 1 addition & 2 deletions docs/ss-cucumber.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<!DOCTYPE html> <html> <head> <title>ss-cucumber.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> ss-cucumber.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>This sets up a SocketStream application to contain
the necessary folders and files for using Cucumber.</p> </td> <td class="code"> <div class="highlight"><pre>undefined</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>This runs Cucumber against the set of features inside
of the features folder.</p> </td> <td class="code"> <div class="highlight"><pre>undefined</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
the necessary folders and files for using Cucumber.</p> </td> <td class="code"> <div class="highlight"><pre>undefined</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
21 changes: 8 additions & 13 deletions lib/ss-cucumber.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Paul Jensen <[email protected]> (http://paulbjensen.co.uk)",
"name": "ss-cucumber",
"description": "Cucumber.js integration for SocketStream",
"version": "0.0.1",
"version": "0.0.2",
"homepage": "https://github.com/paulbjensen/ss-cucumber",
"repository": {
"type": "git",
Expand All @@ -11,7 +11,7 @@
"dependencies": {
"cucumber" : "latest",
"soda" : "latest",
"selenium-launcher" : "git://github.com/paulbjensen/nodejs-selenium-launcher.git",
"selenium-launcher" : "latest",
"commander" : "latest"
},
"devDependencies": {
Expand All @@ -21,7 +21,6 @@
"socketstream" : "= 0.3.0RC2",
"rimraf" : "latest"
},
"optionalDependencies": {},
"main": "./lib/ss-cucumber",
"engines": {
"node": ">=0.6.0"
Expand Down
23 changes: 10 additions & 13 deletions src/ss-cucumber.coffee
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
fs = require "fs"
world_js = fs.readFileSync "#{__dirname}/../copy/world.js", 'utf8'
step_file = fs.readFileSync "#{__dirname}/../copy/socketstream_steps.js", 'utf8'
fs = require "fs"

module.exports =

# This sets up a SocketStream application to contain
# the necessary folders and files for using Cucumber.
#
init: (path, callback) ->
init: (path, coffee, callback) ->

file_extension = if coffee then "coffee" else "js"
world = fs.readFileSync "#{__dirname}/../copy/world.#{file_extension}", 'utf8'
step_file = fs.readFileSync "#{__dirname}/../copy/socketstream_steps.#{file_extension}", 'utf8'

fs.mkdir "#{path}/features", (err) ->
throw err if err?
fs.mkdir "#{path}/features/support", (err) ->
throw err if err?
fs.mkdir "#{path}/features/step_definitions", (err) ->
throw err if err?
fs.writeFile "#{path}/features/support/world.js", world_js, (err) ->
fs.writeFile "#{path}/features/support/world.#{file_extension}", world, (err) ->
throw err if err?
fs.writeFile "#{path}/features/step_definitions/socketstream_steps.js", step_file, (err) ->
fs.writeFile "#{path}/features/step_definitions/socketstream_steps.#{file_extension}", step_file, (err) ->
throw err if err?
callback() if callback?

# This runs Cucumber against the set of features inside
# of the features folder.
#
run: (callback) ->
callback() if callback?
callback() if callback?
38 changes: 32 additions & 6 deletions test/ss-cucumber_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe "ss-cucumber", ->
path = __dirname.replace("/test",'/'+appName)
fs.exists path, (exists) ->
if exists?
ssCucumber.init __dirname.replace("/test",'/'+appName), ->
ssCucumber.init __dirname.replace("/test",'/'+appName), false, ->
done()
, 1

Expand Down Expand Up @@ -49,9 +49,6 @@ describe "ss-cucumber", ->
assert copiedFile == originalFile
done()

# NOTE - maybe we just call 'app', and that's all we need to do?
it "should identify if the main Socketstream app file exists, and what file type it is"

it "should create a socketstream_steps.js file inside of the step_definitions folder", (done) ->
file = "#{__dirname.replace('/test','/'+appName)}/features/step_definitions/socketstream_steps.js"
fs.exists file, (exists) ->
Expand All @@ -60,7 +57,36 @@ describe "ss-cucumber", ->
assert copiedFile == originalFile
done()

describe "#init with coffee option", ->

before (done) ->
ssGenerator.generate args: ["n", appName]
setTimeout ->
path = __dirname.replace("/test",'/'+appName)
fs.exists path, (exists) ->
if exists?
ssCucumber.init __dirname.replace("/test",'/'+appName), true, ->
done()
, 1

after (done) ->
rimraf appName, (err) ->
throw(new Error(err)) if err?
done()

describe "#run", ->
it "should create a world.coffee file inside of the support folder", (done) ->
file = "#{__dirname.replace('/test','/'+appName)}/features/support/world.coffee"
fs.exists file, (exists) ->
assert exists
fs.readFile file, 'utf8', (err, copiedFile) ->
fs.readFile "#{__dirname}/../copy/world.coffee", 'utf8', (err, originalFile) ->
assert copiedFile == originalFile
done()

it "should run Cucumber against the set of features inside of the features folder"
it "should create a socketstream_steps.coffee file inside of the step_definitions folder", (done) ->
file = "#{__dirname.replace('/test','/'+appName)}/features/step_definitions/socketstream_steps.coffee"
fs.exists file, (exists) ->
fs.readFile file, 'utf8', (err, copiedFile) ->
fs.readFile "#{__dirname}/../copy/socketstream_steps.coffee", 'utf8', (err, originalFile) ->
assert copiedFile == originalFile
done()

0 comments on commit 550fb84

Please sign in to comment.