Typical Noise

Alex Arnell

Coffee fueled terminal junky. A Software Developer with a strong passion for good software design and an unquenchable thirst for learning.

Showing all posts tagged "Javascript"

Long awaited project page arrives

Well, I finally got rid of my laziness. Well, at least for most of the weekend. The lame Inheritance.js project page has finally been updated. There is now some real content there, not just some lame page saying there is "more to come in just a little while". Head on over to pick up the javascript file and see the latest explanation of what Inheritance.js can do for you.

What''s in store for the future? Well, I''ve decided that I want to devote a portion of my free time, no matter how little there is, to working on open source software. I feel that I have a lot more I could contribute to the community of developers out there. I have my eyes on a few specific projects that I would like to get involved with, but we shall see if that works out. In terms of what the future holds for Inheritance.js, well I plan to get some sort of issue tracking system up in place. I don''t expect there to be many issues, but inevitably there will be. An issue tracking system would also be a great place for people to post suggestions for improvements and other ideas regarding the enhancement of this library. So stay tuned over the next little while for another update in that regard.

As a side note, I have submitted Inheritance.js as one of Prototype''s "best built-with-Prototype third-party libraries". With any luck, hopefully you''ll see Inheritance.js on the official Prototype list when it comes out.

Prototype Patch Re-submitted

Well I finally got off my high horse and made some time to build out a collection of unit tests for my inheritance library. I took the latest code along will all the newly written unit tests and bundled them into a nice patch for prototype. I re-attached them to my original patch so hopefully it will be included in a future version.

Now that I have your attention, I thought I'd spend a bit of time to discuss some code I discovered while building out this latest set of unit tests. While looking through the scriptaculous unit testing suite I found a neat little entry at the bottom of unittest.js. I'm not sure when it was added, so if this is really old news I apologize for being behind the times.

At the bottom of unittest.js there is an experimental BDD implementation in the works. This is neat, I've seen BDD (Behavior Driven Development) frameworks in Java as well as Ruby and now there's an implementation for JavaScript.

So what does all this mean? Well, it means you can write your unit tests like a product specification. Using an example from RSpec, we can write the following test suite that reads like a specification:

var stack;

Test.context("An empty stack", {

  setup: function() {
    stack = new Stack();
  },

  "should be empty": function() {
    assertReturnsTrue('empty', stack)
  },

  "should no longer be empty after 'push'": function(){
    stack.push("anything");
    assertReturnsFalse('empty', stack)
  },

  "should complain when sent 'peek'": function(){
    assertRaise('StackUnderflowError',
      function(){stack.peek()});
  },

  "should complain when sent 'pop'": function(){
    assertRaise('StackUnderflowError',
      function(){stack.pop()});
  }

});

Now, in true BDD fashion, we should actually write our Stack implementation. Our test suite not only acts like the specification but allows us to programatically ensure that the Stack implementation we do end up writing meets that specification as well.