A Couple of Important Notices

Don’t forget to tun in to Andy Lester & Chad Fowler’s webcast today. It’s being presented free via O’Reilly.
Radical Career Success in a Down Economy


Anyone who’s in the Eau Claire area, we’re holding out monthy ECRuby User Group meeting on July 2. We’re very interested in recruiting new members who might be interested in meeting up with other Ruby users, or even just getting started with the language.
5:00PM at Dooley’s Pub (442 Water St., Eau Claire, WI)


Finally, Tj Holowaychuk of Vision Media has made significant additions to the JSpec library to allow for module hooks. This means that I should have full integration of the JSocka stubbing library working with Mocha syntax shortly. Stay tunes for updates!

No Comments

Screw.Unit, Smoke, JSpec and JSocka – Test Your Javascript!

A few weeks ago, I gave a presentation on Firefox extension development at the Chicago Code Camp down in Grayslake, Illinois. Among the presentations I attended was on titled “TDD in Javascript.” It occurred to me as I watched this presentation that not only was I as guilty as the rest of the audience of skimping out on writing tests for Javascript — but worse, I hadn’t even included a testing chapter in my outline for my Firefox extension book!

When I got back, I immediately shifted some chapters around to make some space for a chapter on testing and debugging. I let my editor know that I was refactoring a little bit, and promptly forgot all about it as I scrambled to get another chapter finished up for a deadline.

Later, however, I started messing around with Screw.Unit. I examined the Smoke framework that provides mocking and stubbing functionality for Screw.Unit specs, and started to try and draft up some basic tests for one of my extensions.

The resulting code looked something like this:

describe("TULIP Extension",function(){
  before(function(){
    fakeTulip = Smoke.Mock(Tulip);
  });
  describe("handleReadyStateChange",function(){
    describe("when request.readyState is the desired state",function(){
      it("should call the handleTransaction function with the request",function(){
        request = {readyState:DESIRED_STATE};
        fakeTulip.should_receive('handleTransaction').with(request).and_return(true);
        fakeTulip.handleReadyStateChange(request);
        fakeTulip.checkExpectations();
      });
    });
  });
});

I wasn’t a huge fan of this testing framework. For one thing, I didn’t like creating a mock object every time I wanted to stub out a particular function. For another, all of the nested function(){} calls left things looking extremely cluttered and unreadable. In the days of technologies like Cucumber, perhaps I’ve been spoiled into thinking that specs should be a bit more user-friendly.

Enter JSpec, a different style of Javascript testing framework. JSpec allows you to write your tests using Ruby-like syntax. When the specs get run, the Javascript gets precompiled into something that more closely resembles Screw.Unit code.

The only unfortunate thing was the stubbing framework. JSpec had a built-in spying framework, but no stubbing and mocking framework. It would be possible to use Smoke with JSpec, but Smoke has an additional failing — Often when we write our tests, we don’t actually have access to some of the instances we might like to stub. Sometimes instances are created by the methods we call, and it would require no small amount of code refactoring to allow us access to them.

JSpec follows Ruby syntax, so why not have a Mocha-like framework? I began working on my own mocking and stubbing framework that tries to parallel Mocha syntax for use with JSpec and other test frameworks. The project was a success.

JSocka (http://www.github.com/gisikw/jsocka) is a new stubbing and testing framework that allows for the following syntax:

JSocka("Person").expects("speak").with("Dignity").returns("function(){alert('I am the very model of a modern major general.')})

The framework supports stubbing and setting expectations on both class methods and instance methods, and allows checks for number of times called, what parameters were passed, and et cetera. With this mechanism, we can stub out any instance of a class, so that even if it’s not yet instantiated, we can stub out an object that would later be created in our tested class.

I was able to rewrite my test quite quickly using JSpec and JSocka:

describe ".handleReadyStateChange(request)"
  describe "when the request readyState is the desired state"
    it "should call the Tulip.handleTransaction method with the request"
      JSocka("Tulip").expects("handleTransaction")
      Tulip.handleReadyStateChange({readyState:Tulip.DESIRED_STATE})
      JSocka.checkExpectations().should.equal true
    end
  end
end

For those interested, the Github repository for this extension contains a full test suite (http://www.github.com/gisikw/tulip).

The bottom line is that there are great Javascript testing frameworks out there and available, and it’s really tragic that so many developers let this fall by the wayside. With the advancement of Test-Driven Development, many programmers are focusing on writing very good test for the application-side of things, which is wonderful. It’s important though never to forget the final scripting language that adorns almost all web applications.

I’ve written up a significant amount regarding testing applied to extension development for my Pragmatic Bookshelf book, but it’s important that developers everywhere consider these valuable tools and start evaluating how best to test.

The tools are there. Use ‘em!

2 Comments

Drag Me To Hell

Sam Raimi’s “Drag Me To Hell” opened with the old-fashioned Universal Studios reel, hinting at a good ol’ enjoyable classic horror film. Before the credits began, the film appeared ready to follow up on that promise. Unfortunately, after a some nice credits that mixed attribution and exposition, the film went decidedly downhill.

Alison Lohman plays a loan officer at a small bank, looking to make the leap to assistant manager. As she’s close to sealing the deal, an old gypsy woman asks for an extension on her mortgage. Trying to appease her boss, Lohman’s character refuses.

At this point, the story spirals into a sad predictable ghost story, as the gypsy curses Lohman, who then tries to get the curse removed, through a long process of eery wind-blowing, ominous gypsy music, and the ever-entertaining “I’m not crazy, they’re really out to get me!” scenes.

While it’s nice to be able to see Justin Long’s versatility as an actor — he plays opposite Lohman as the Psychology-teacher boyfriend — this alone cannot save the viewer from a long and dull experience of predictable tension, forced dialogue, and plotholes, finally wrapping up in a weak ending that Raimi gives away a good thirty minutes prior.

Spoiler Alert!

No Comments

Presentation at Chicago Code Camp

If you’re in the area, be sure to attend the Chicago Code Camp at Lake County College this Saturday. Personally, I’ll be giving a presentation on Firefox extension development. If you want to take a look, I’ve got the slides and code snippets available on this site.

1 Comment

Returning to Chess

Several years ago, when I was a youthful high school freshman, I started attending a chess club at Madison West High School, ran by FM Alex Betaneli. I recall it being an interesting experience, as Alex was a very enthusiastic and active teacher, but also one who had high expectations of his students.

I was very much on the low end of the chess board, and though I played in a tournament or two, I eventually stopped going, and moved on to a few million other hobbies. I still played the occasional game, but I certainly didn’t devote much time to the actual study of chess.

I find I miss it, and it’s something I feel like reviving a bit. I don’t consider myself able to go play tournaments at this point, but I’d like to spend some additional time studying the game, and trying to improve, so maybe one day I can go back and play again.

So, I’ve started playing online a bit, and I realized, I’ve completely forgotten just about all of the opening lines. I used to be relatively familiar with the Italian Game:

r1bqkbnr/pppp1ppp/2n5/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R b KQkq – 0 1r1bqkbnr/pppp1ppp/2n5/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R b KQkq – 0 1Italian Game: 1.e4 e5 2.Nf3 Nc6 3.Bc4.

This is a pretty standard opening, but in my experience, it’s lead to some pretty closed-off positions, and I don’t particularly enjoy the games that spawn from it. So, I’ve been taking a bit of interest in the Half-Danish:

rnbqkbnr/pppp1ppp/8/8/4P3/2N5/PP3PPP/R1BQKBNR b KGkg – 0 1rnbqkbnr/pppp1ppp/8/8/4P3/2N5/PP3PPP/R1BQKBNR b KGkg – 0 1Half-Danish: 1.e4 e5 2.d4 exd4 3.c3 dxc3 4.Nxc3.

This involves the sacrifice of a pawn in order to achieve a superior position for white. So far, I’ve been having a pretty good experience in evaluating it, though there are certainly some variations I’d like to get more familiar with, hence the need for chess database software.

I’m a linux user, and unfortunately, that’s a bit by necessity, as my hardware is starting to slowly go to dust. The only strong chess database software available for the linux operating system (for free, at least) is SCID. This software was maintained and updated until 2004, though it appears various other users have been making contributions to the program over time. It’s working out quite well so far, but the documentation leaves a little bit to be desired. I may end up trying to contribute some notes of my own to help make this software a bit more accessible. In the meantime, it’s going to be a fun experience getting back into the swing of chess.

No Comments

Maintaining an Active Web Presence

I originally had maintained a Wordpress blog that I was pretty excited about, which I updated on a fairly regular basis. However, as a Ruby on Rails developer, I decided it was my responsibility to use a Rails-based blogging platform. I ended up setting up Mephisto as my engine of choice for a while, but I discovered that I did not update nearly as frequently as I might have.

So, I’m back to Wordpress. In the last while, I’ve been having some interesting experiences. I’m really struggling to make it through my undergraduate degree, working hard on maintaining good work ethic and interest in independent projects, and in general, teetering back and forth about what I want to do with my future.

As such, these blog posts will likely be very sporatic, as I intend to post not just as a Ruby on Rails developer, but also as a musician, an author, a chess player, and any other interest I may possess. Enjoy the ride!

No Comments