My First IronRuby Unit Test Spec For ASP.NET MVC, mvc, code, tdd 0 comments suggest edit

Way down the road, it would be nice to be able to build ASP.NET MVC applications using a DLR language such as IronRuby. However, enabling DLR language support isn’t free.

There are going to be places in our design that are specific to statically typed languages (such as Attribute based filters) that just wouldn’t work (or would be too unnatural) with a dynamic language.

Ideally we can minimize those cases, and for the ones we can’t, we need to make sure the extensibility of the framework allows for extending the system in such a way that we can provide a DLR friendly version of that feature.

How do we identify and minimize such hot spots? Design reviews help, but only goes so far. There is nothing like executing code to highlight issues. So in collaboration with some of the DLR team members, I’ve been exploring the minispec framework used to test IronRuby and wrote my first testspec tonight. Check it out. (NOTE: line breaks added in the require statements so it fits within the width of my blog)

require File.dirname(__FILE__) + '/../../spec_helper'
require 'System.Web.Abstractions
, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
require 'System.Web.Routing
, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
require 'System.Web.Mvc
, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

describe "Route#<<" do
  it "can create RouteCollection which is empty" do
    rc =
    rc.count.should == 0
  it "can add route to RouteCollection" do
    rc =
    r = "", nil
    rc.add "route-name", r
    rc.count.should == 1


And here is the result so far.


Yay! Two passing tests.

Yeah, the tests are really really simple so far, but hey, this is just my first step. I need to get familiar with the minispec framework. Not only that, but I haven’t written any Ruby code in a long while. Fortunately I do have a copy of The Ruby Way on my shelf, which should help.

I probably have much higher priority items on my plate that I could be working on, but sometimes you have to treat yourself to a little fun. Besides, I am doing this on my own time right now. :)


Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



7 responses

  1. Avatar for Rob Conery
    Rob Conery April 9th, 2008

    Nice stuff Phil! It will be fun to work with Ruby as the DLR comes together - it's nice to see you staking your claim as the Ruby expert (since you work for MS and all :p:p:p:p:p).
    Har har just jokin - good stuff. Now get to sleep!

  2. Avatar for Haacked
    Haacked April 9th, 2008

    I'd like to go on record as saying I'm an expert at absolutely nothing. Maybe I'm an expert scratching my ass. I'm pretty competent at that.

  3. Avatar for Peter Morris
    Peter Morris April 9th, 2008

    I love the MS MVC web approach. However, I really wish the controllers could have been completely decoupled from HTTP so that the same controllers could have been used in local WinForm apps, websites, and remote server apps.

  4. Avatar for jschementi
    jschementi April 9th, 2008

    Awesome, great to see you got this working! Higher priority, pssshhh ... what could be better than ... well ... anything Ruby =)

  5. Avatar for jonnii
    jonnii April 9th, 2008

    Ruby doesn't support attributes, but there are certainly alternative ways to representing filters. For example in rails you do:
    before_filter :require_authentication, :on => :show
    I think perhaps something similar could be done mvc, which could either decorate the appropriate methods with the attributes or set up an interceptor on the appropriate method calls.

  6. Avatar for engtech
    engtech April 9th, 2008

    How is IronRuby for Windows GUI development?
    I really like Shoes in concept, but the idea of deploying a Shoes app... not so much.

  7. Avatar for Kevin Radcliffe
    Kevin Radcliffe April 10th, 2008

    This is a great example to get us thinking about what IronRuby brings to the table (right now as well as future developments). Starting with tests like these is a great way to let us get our feet wet. Looking forward to more examples like this if you have the time.
    Thanks for the post.