Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 473eed5c02ca0e5f0439e44c9102f68ffc713e17 @igorgue committed
3 .gitignore
@@ -0,0 +1,3 @@
+*.swp
+*.swo
+.DS_Store
16 Cakefile
@@ -0,0 +1,16 @@
+{spawn, exec} = require 'child_process'
+
+runCommand = (name, args...) ->
+ proc = spawn name, args
+ proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
+ proc.stdout.on 'data', (buffer) -> console.log buffer.toString()
+ proc.on 'exit', (status) -> process.exit(1) if status isnt 0
+
+task 'watch-sass', "Watch source files and build CSS", (options) ->
+ runCommand 'sass', ['--watch', 'public/css/sass:public/css']
+
+task 'watch-coffee', "Watch source files and build JS", (options) ->
+ runCommand 'coffee', '-wc', 'src', 'test'
+
+task 'compile-coffee', "Compile the coffee script files to JS", (options) ->
+ runCommand 'coffee', '-c', 'src', 'test'
30 README.md
@@ -0,0 +1,30 @@
+Vows Examples in CoffeeScript
+=============================
+
+I wrote this because I coudn't find it anywhere.
+
+Running
+-------
+
+Compile:
+
+ cake compile-coffee
+
+Or better yet in one terminal tab just run and leave it there:
+
+ cake watch-coffee
+
+Then in another terminal tab (or screen):
+
+ ☁ vowsjsexamples [master] ⚡ node test/division_by_zero.js
+ ···
+ ✓ OK » 3 honored (0.006s)
+
+And this one:
+
+ ☁ vowsjsexamples [master] ⚡ vows test/the_good_things_test.js
+ ····
+
+ ✓ OK » 4 honored (0.001s)
+
+And that's it... I'll add more examples (probably not from the website because I'm writing a full project with Vows and CoffeeScript.
14 src/the_good_things.coffee
@@ -0,0 +1,14 @@
+class Strawberry
+ color: '#ff0000'
+ isTasty: -> true
+
+class Banana
+ color: '#fff333'
+ peel: (callback) ->
+ process.nextTick ->
+ callback(null, new PeeledBanana)
+ peelSync: -> new PeeledBanana
+
+class PeeledBanana
+
+module.exports = {Strawberry, Banana, PeeledBanana}
33 src/the_good_things.js
@@ -0,0 +1,33 @@
+(function() {
+ var Banana, PeeledBanana, Strawberry;
+ Strawberry = (function() {
+ function Strawberry() {}
+ Strawberry.prototype.color = '#ff0000';
+ Strawberry.prototype.isTasty = function() {
+ return true;
+ };
+ return Strawberry;
+ })();
+ Banana = (function() {
+ function Banana() {}
+ Banana.prototype.color = '#fff333';
+ Banana.prototype.peel = function(callback) {
+ return process.nextTick(function() {
+ return callback(null, new PeeledBanana);
+ });
+ };
+ Banana.prototype.peelSync = function() {
+ return new PeeledBanana;
+ };
+ return Banana;
+ })();
+ PeeledBanana = (function() {
+ function PeeledBanana() {}
+ return PeeledBanana;
+ })();
+ module.exports = {
+ Strawberry: Strawberry,
+ Banana: Banana,
+ PeeledBanana: PeeledBanana
+ };
+}).call(this);
19 test/division_by_zero.coffee
@@ -0,0 +1,19 @@
+# division_by_zero.coffee
+
+vows = require 'vows'
+assert = require 'assert'
+
+# Create a test suite.
+vows.describe("Division by Zero").addBatch
+ 'when dividing a number by zero':
+ topic: -> 42 / 0
+ 'we get Infinity': (topic) ->
+ assert.equal(topic, Infinity)
+ 'but when dividing zero by zero':
+ topic: -> 0 / 0
+ 'we get a value which':
+ 'is not a number': (topic) ->
+ assert.isNaN topic
+ 'is not equal to itself': (topic) ->
+ assert.notEqual(topic, topic)
+.run()
28 test/division_by_zero.js
@@ -0,0 +1,28 @@
+(function() {
+ var assert, vows;
+ vows = require('vows');
+ assert = require('assert');
+ vows.describe("Division by Zero").addBatch({
+ 'when dividing a number by zero': {
+ topic: function() {
+ return 42 / 0;
+ },
+ 'we get Infinity': function(topic) {
+ return assert.equal(topic, Infinity);
+ }
+ },
+ 'but when dividing zero by zero': {
+ topic: function() {
+ return 0 / 0;
+ },
+ 'we get a value which': {
+ 'is not a number': function(topic) {
+ return assert.isNaN(topic);
+ },
+ 'is not equal to itself': function(topic) {
+ return assert.notEqual(topic, topic);
+ }
+ }
+ }
+ }).run();
+}).call(this);
30 test/the_good_things_test.coffee
@@ -0,0 +1,30 @@
+# Imports.
+vows = require 'vows'
+assert = require 'assert'
+
+theGoodThings = require '../src/the_good_things'
+
+Strawberry = theGoodThings.Strawberry
+Banana = theGoodThings.Banana
+PeeledBanana = theGoodThings.PeeledBanana
+
+# Specs.
+vows.describe("The Good Things").addBatch
+ 'A strawberry':
+ topic: new Strawberry
+ 'is red': (strawberry) ->
+ assert.equal(strawberry.color, '#ff0000')
+ 'and tasty': (strawberry) ->
+ assert.isTrue strawberry.isTasty()
+ 'A banana':
+ topic: new Banana
+ 'when peeled *synchronously*':
+ topic: (banana) -> banana.peelSync()
+ 'returns a `PeeledBanana`': (result) ->
+ assert.instanceOf(result, PeeledBanana)
+ 'when peeled *asynchronously*':
+ topic: (banana) ->
+ banana.peel @callback
+ 'results in a `PeeledBanana`': (error, result) ->
+ assert.instanceOf(result, PeeledBanana)
+.export(module)
39 test/the_good_things_test.js
@@ -0,0 +1,39 @@
+(function() {
+ var Banana, PeeledBanana, Strawberry, assert, theGoodThings, vows;
+ vows = require('vows');
+ assert = require('assert');
+ theGoodThings = require('../src/the_good_things');
+ Strawberry = theGoodThings.Strawberry;
+ Banana = theGoodThings.Banana;
+ PeeledBanana = theGoodThings.PeeledBanana;
+ vows.describe("The Good Things").addBatch({
+ 'A strawberry': {
+ topic: new Strawberry,
+ 'is red': function(strawberry) {
+ return assert.equal(strawberry.color, '#ff0000');
+ },
+ 'and tasty': function(strawberry) {
+ return assert.isTrue(strawberry.isTasty());
+ }
+ },
+ 'A banana': {
+ topic: new Banana,
+ 'when peeled *synchronously*': {
+ topic: function(banana) {
+ return banana.peelSync();
+ },
+ 'returns a `PeeledBanana`': function(result) {
+ return assert.instanceOf(result, PeeledBanana);
+ }
+ },
+ 'when peeled *asynchronously*': {
+ topic: function(banana) {
+ return banana.peel(this.callback);
+ },
+ 'results in a `PeeledBanana`': function(error, result) {
+ return assert.instanceOf(result, PeeledBanana);
+ }
+ }
+ }
+ })["export"](module);
+}).call(this);

0 comments on commit 473eed5

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