📜 ⬆️ ⬇️

Keep your vows; Relationship with Node

Oaths can be beautiful. Alexis Sellier , who has gained fame for developing LESS (and less.js), is beginning to become an Open Source star, releasing Vows , a framework for developing on Node.JS, driven by asynchronous behavior.

image

If such a BDD specification we give to the input:
  1. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  2. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  3. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  4. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  5. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  6. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  7. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  8. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  9. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  10. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  11. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  12. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  13. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  14. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  15. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  16. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  17. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  18. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  19. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  20. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  21. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  22. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it
  23. // division-by-zero-test.js var vows = require ( 'vows' ) , assert = require ( 'assert' ) ; // Create a Test Suite vows. describe ( 'Division by Zero' ) . addBatch ( { 'when dividing a number by zero' : { topic : function ( ) { return 42 / 0 } , 'we get Infinity' : function ( topic ) { 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 ) { assert. isNaN ( topic ) ; } , 'is not equal to itself' : function ( topic ) { assert. notEqual ( topic , topic ) ; } } } } ) . run ( ) ; // Run it

')
Then at the output we get a perfectly readable report:
Exhaust

With macros, we end up with a convenient DSL syntax, for example:
  1. { 'GET /' : {
  2. topic : api. get ( '/' ) ,
  3. 'shoud respond with a 200 OK' : assertStatus ( 200 )
  4. } ,
  5. 'POST /' : {
  6. topic : api. post ( '/' ) ,
  7. 'shoud respond with a 405 Method not allowed' : assertStatus ( 405 )
  8. } ,
  9. 'GET / resources (no api-key)' : {
  10. topic : api. get ( '/ resources' ) ,
  11. 'shoud respond with a 403 Forbidden' : assertStatus ( 403 )
  12. } ,
  13. 'GET / resources? Apikey = af816e859c249fe'
  14. topic : api. get ( '/ resources? apikey = af816e859c249fe' ) ,
  15. 'shoud return a 200 OK' : assertStatus ( 200 ) ,
  16. 'should return a list of resources' : function ( res ) {
  17. assert. isArray ( res. body ) ;
  18. }
  19. }
  20. }
  21. // or even
  22. {
  23. 'GET /' : respondsWith ( 200 ) ,
  24. 'POST /' : respondsWith ( 405 ) ,
  25. 'GET / resources (no key)' : respondsWith ( 403 )
  26. }


The project site details the installation process, usage examples, etc. By the way, the site was made very decently, using HTML5 markup.

from the translator: The name of the article in English beats the name of the project - Vows (oaths).

Source: https://habr.com/ru/post/98671/


All Articles