background preloader

Vows « Asynchronous BDD for Node

GivenWhenThen: Simple, Powerful Acceptance Testing for Node.js Over the last year or so, interest in and development for Node.js has accelerated dramatically. There is no shortage of excitement and promise in this burgeoning community and for many of the same reasons cited by others, about six months ago we decided it made sense to dive in ourselves. Coming from a committed testing background on multiple web frameworks, including Rails, we are strong adherents to BDD. Naturally the first thing we did when spinning up on the Node stack was look around for good BDD acceptance testing tools. Writing a Story Although you can also directly access the Selenium RemoteWebDriver that is under the covers, GivenWhenThen is primarily intended to provide a DSL for writing executable stories in the Dan North format. story 'Executing a Google search', """ As a human I want to perform a search So that I can access the world's information """, -> And then add one or more scenarios: Each scenario has “given“, “when“, and “then” steps. Steps Configuration For example:

moshen/node-googlemaps Coffeescript, Jasmine and Katas | Caffeine Industries Posted in code, Javascript, Language, Programming, Uncategorized on Saturday, March 10th, 2012 at 2:07 pm Hey-O! CoffeeScript is nice. It provides syntactic sugar and adds tremendous functionality to the web developers tool-chest. On long road trips I generally have a few hours to kill while the rest of the family is asleep. This trip I decided to load my Galaxy Nexus with a metric ton of CoffeeScript screen casts (just audio) and podcasts. Since I’ve returned home, I have decided to stick with CoffeeScript and add a few more. I’ve also become a believer in dedicated, deliberate practice. I used this code kata with CoffeeScript and Jasmine. Click the post image to see the passing tests! Here is my solution: The Spec’s in CoffeeScript The implementation in CoffeeScript:

yepnope.js | A Conditional Loader For Your Polyfills! Mongo Model Domain Model for MongoDB and Node.JS CoffeeScript and Fibers are optional. You can use Model with plain old JavaScript and Callbacks. class global.Post extends Model @collection 'posts' @embedded 'comments' class global.Comment extends Model Dynamic schema, flexible queries. post = new Post text: 'Zerg on Tarsonis!' Post.first(status: 'published') Post. find(status: 'published'). sort(createdAt: -1). limit(25). all() class global.Post extends Model @latest: -> @find(status: 'published'). post = Post.first() post.comments.push new Comment text: 'Sad news ...' post.save() post.delete() Post.delete status: 'draft' class global.Post extends Model comments: -> Comment.find postId: @_id class global.Comment extends Model post: -> Post.first _id: @postId post = Post.create text: 'Zerg found on Tarsonis!' post = Post.first() post.comments().limit(25).all() post.comments().count() before / after of create, update, validate and delete. Callbacks and Validations also works on Embedded Models

Things I wish I knew about MongoDB a year ago I’ve used MongoDB for over a year at scale at both Heyzap and Bugsnag and I’ve found it to be a very capable database. As with all databases, there are some gotchas, and here is a summary of the things I wish someone had told me earlier. Selective counts are slow even if indexed For example, when paginating a users feed of activity, you might see something like, In MongoDB this count can take orders of magnitude longer than you would expect. Inconsistent reads in replica sets When you start using replica sets to distribute your reads across a cluster, you can get yourself in a whole world of trouble. This is compounded if you have performance issues that cause the replication lag between a primary and its secondaries to increase to minutes or even hours in some cases. You can control whether a query is run on secondaries and also how many secondaries are replicated to during the insert, but this will affect performance and could block forever in some cases! Mongo’s BSON ID is awesome Profiler

Vows and CoffeeScript CoffeeScript is a really nice way to write JavaScript code. Combined with NodeJS you are empowered by a very fast platform to develop server-side applications. Of course, you want to test these apps as well. Vows is really great way to do this. ~ First off, make sure you have CoffeeScript and Vows installed. npm install -g coffee-script npm install -g vows Next up, in your product directory, create a directory named test. I'm not going to explain the intimate details of Vows here, suffice it to say that you calculate a value and store it in topic. The magic part is the last line, .export(module). When using coffee-script, you don't want to directly run you vows, but gather them all together, convert them to JavaScript and then have vows run them. With the test/division-test.coffee saved, try running vows from your console. Another great tip is vows -w. Happy testing! Yes, I know there are issues with Coderay parsing UTF-8 characters. Did you enjoy this post?

JS.Class v3.0 jsclass comes with a package manager that makes it really easy to load libraries into your application on demand on all jsclass’s supported platforms. You can tell it which file each module in your application lives in, and what other modules it depends on, and it takes care of resolving dependencies and loading your code for you. This means your application code only needs to specify which objects it needs, rather than which scripts to download in order to run. For example, say I want to do something with the Console module. I just need to require it, and supply a function to run once all the requisite code has loaded: JS.require('JS.Console', function(Console) { Console.puts('Hello, world!') The package system only loads what is needed to get the objects you want, and it makes sure that each file is only downloaded once. It is designed to be able to load any code from any domain, including from libraries that have their own package systems.

Underscore.js Alexander Luksidadi's Blog » ExpressJS without Jade? Use Underscore template! Many of you must have felt like a burden knowing that Express recommended you to learn another template language (Jade). Don’t worry, you can code all your templates on HTML using underscoreJS! Oh yay? Let’s take a look on how you implement that on your express app. First install express package, create your express app: $ npm install -g express $ express . Install your underscore package $ npm install -d underscore If you edit Now, all you need to do is, to comment out 1 line and register underscorejs: Now, go to routesindex.js : $ vi routes/index.js Change the template name from ‘index’ to ‘index.html’: Next, go to views directory and create layout.html And last, still in views directory, create another file called index.html And there you go.. you can write your HTMl code in peace =)

Related: