Thursday, May 08, 2008
In preparation for my upcoming Code Camp session on IronRuby I've been hacking around on the IronRuby source, as well as on Ruby programs that can run on IronRuby.  One of the core areas of interest for me concerning IronRuby is in writing specifications for my .NET applications using Ruby.  While I've been learning Ruby (the real kind) I've become very fond of the testing libraries they have available, most notably RSpec and mocha

Over the last two nights I've been writing some ruby code to test .NET classes written in C#.  With a few of the hacks I have locally, I've had some pretty good success.  The following set of specifications verify the behavior of an Account class I've written.

require "../../trunk/tests/ironruby/Util/simple_test.rb"
require "IronRubySamples"
include IronRubySamples

describe "Account" do
    describe "When depositing money into my account" do
        it "should increase my balance by the amount deposited" do
            account = Account.new(10)
            account.Deposit(10)
            account.Balance.should == 20
        end
    end
                               
    describe "When withdrawing money from my account" do
        it "should decrease my balance by the amount withdrawn" do
            account = Account.new(100)
            account.Withdraw(50)
            account.Balance.should == 50
        end
    end
                   
    describe "When withdrawing money from an account with insufficient funds" do
        it "should tell me I have insufficient funds" do
            account = Account.new(30)
            should_raise(InsufficentFundsException) { account.Withdraw(50) }
        end
    end
   
    describe "When making a withdraw that drops my balance below the minimum" do
        it "should reduce my account by the amount withdrawn + the low funds charge amount" do
            account = Account.new(55)
            account.Withdraw(50)
            account.Balance.should == 4
        end
    end
end

The next step in my quest to test .NET code with IronRuby required me to figure out how to mock out dependent objects.  I considered several different options.  My first thought was to try and use "simple mock", however, I quickly realized via Scott Bellware that while it worked well on IronRuby libraries it wouldn't fit my needs.  My next thought was to give Moq a try.  After downloading Moq, I attempted to run a spec that referenced Moq and created a Mock<T> instance as shown below:

require "../../trunk/tests/ironruby/Util/simple_test.rb"
require "IronRubySamples"
require "Moq"
include Moq
include IronRubySamples

describe "LoginController" do
    describe "When a user logs in" do
        it "should vallidate credentials with login service" do
            mock = Mock.of(ILoginService).new
            #do expects
           
            controller = LoginController.new(mock.Object)
            controller.Login("steve", "****")
        end
    end
end

When running this via ir.exe I got an error that "Moq.Mock is not a generic type".  After poking around a bit I discovered this was due to a bug in IronRuby.  Currently IronRuby has problems when there is a generic and non generic type of the same name within a referenced assembly.  In order to work around this, I first tried to figure out what needed to be modified in IronRuby, however, that wasn't very fruitful so I decided to modify the source for Moq to get around my problem.  After renaming the static Mock class in Moq to MockRetriever, and hacking around another bug in IronRuby related to creating generic types where the type argument is an interface, I was finally able to get IronRuby to create the Mock<ILoginService> type:

mock = Mock.of(ILoginService).new

Unfortunately, this led to me to another roadblock.  When setting up expectations in Moq you do so with lambda expressions such as:

// C#
var mock = new Mock<ILoginService>();
mock.Expect(s => s.Login("steve", "****"));

While IronRuby has blocks and lambda's it doesn't have a way to express the above (at least that I know).  I'm going to dig around in the IronRuby source a bit to see if any ideas pop into my head, but at this point I'm not very hopeful. 

 |  | 
Friday, May 09, 2008 1:09:46 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Sunday, April 20, 2008
As I continue on my quest to get more information about IronRuby, I figured it was worth figuring out what needs to happen in order to contribute code back into the project.  The source code for IronRuby is synced with RubyForge every so often, and patches to the source code can be submitted on the RubyForge project here.  Before making any contributions to IronRuby a contributor agreement must be electronically signed.  John Lam's post to the IronRuby mailing list can be found here, and the actual agreement is available at: http://www.ironruby.net/contributor.pdf

The agreement appears to be pretty staight forward, the main point worth attention is that you grant Microsoft all rights to the contribution.
For good and valuable consideration (including without limitation the opportunity to contribute to the Project), receipt and sufficiency of which is hereby acknowledged, Assignor hereby assigns and agrees to assign to Microsoft its entire right, title,
and interest (including all intellectual property rights) in the Contributions.

Microsoft then licenses the contribution back to you to do with it as you wish.
Microsoft grants You a non-exclusive license under the rights assigned to Microsoft in Section 3 to use, reproduce, modify, license or otherwise distribute, and exploit the Contribution as You see fit.

If you're interested in contributing you need to send an email to ssiadmin at microsoft.com requesting to be added as a contributor to the IronRuby project.  I sent an email this morning so I'm not sure what happens next, but I'm assuming the electronic signing of the contributor agreement will be the next step.

Sunday, April 20, 2008 12:31:37 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, April 19, 2008
I've been digging around IronRuby a bit lately, checking out the source, the specs, and writing very minimal code into rbx to see if it works as expected.  Over the next couple weeks I'm going to try and dig a little deeper into IronRuby in an attempt to get a better feel for where it is, what I might be able to use it for, as well as to experiment with some ideas I've had over the last couple months. 

When I first downloaded IronRuby I did so on my Mac in hopes that I'd be able to cruise around the source in TextMate, compile with Mono, and avoid having to fire up a VM whenever I wanted to experiment.  My initial attempts, albiet not very focused, were a failure.  Fortunately within the last week or two I came across Seo Sanghyeon's IronRuby on Mono How to.

The first step is to download and install Mono 1.9.  Once you have Mono installed you need checkout the IronRuby source from RubyForge and then download and apply this patch that Seo created.  Finally run: rake compile mono=1 and assuming everything goes well you'll be greeted with another command prompt which you can use to fire up rbx (aka IronRuby's irb) and begin experimenting.
svn co http://ironruby.rubyforge.org/svn/trunk ironruby
cd ironruby
patch -p0 < patch-mono-r93
rake compile mono=1
mono build/mono_debug/rbx.exe

Saturday, April 19, 2008 1:56:03 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, March 26, 2008
A couple nights ago I was up reading blogs and browsing the web.  I had made my way through all my unread items and was contemplating hitting the sack when I decided to do one more "r" within google reader to see if anything new was available.  Surprisingly one new item appeared.  The one new item was from Jean-Paul Boodhoo, and was entitled "The Dream Giver".

After reading JP's post I figured I'd drop him a comment since I like reading, and I like free stuff.  As I went to bed I figured I had a strong chance of being one of the first three to contact him since I'm pretty sure I was reading his post while his mouse button was still pressed on the "post" button.  As I thought about it some more, I realized that I'd actually prefer NOT to win since I would have picked up the book anyway, and I figured there might be some others who responded who wouldn't purchase the book if they didn't win a copy from JP.  Not surprisingly the next day I received a Amazon Gift Certificate from JP to cover the cost of the book.

When I got home that night I mentioned the above to my wife, and told her that I felt bad accepting the gift certificate from JP given the circumstances.  She said I should accept his charity, so that's just what I did.

Over the last two days I made my way through The Dream Giver by Bruce Wilkinson.  The book starts with a parable about an Ordinary guy living in a Familiar place who realizes he has a Big Dream.  As this Ordinary guy thinks about his Big Dream he realizes that he doesn't want to ignore it any longer.  Thus begins his journey.  

As I read The Dream Giver I started to think a lot about my dreams.  As life goes by we often lose sight of our dreams, and get caught up in the comforts of life.  The Dream Giver has me thinking about my dreams again.  I found the story of Ordinary following his dream, as well as the encouraging words and advice offered by the author inspiring.  Life is full of obstacles, roadblocks, naysayers, and will provide you with endless reasons not to follow your dreams.  The Dream Giver offers hope, encouragement, and guidance.  Following a dream isn't easy. You can't do it alone.  However, the journey can make you stronger, happier, and more fulfilled.

Are you ready to begin your journey?

Following in JP's footsteps....the first 3 people to email me with interest in this book will receive an amazon gift certificate in the amount required to purchase the book.

Note: you can email me by clicking on the little envelope in the right hand navigation of my site.

Sorry they are all gone!

Thursday, March 27, 2008 2:03:14 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [2]  |  Trackback
We've been using Rhino Mocks as our mocking framework for the last year and have had some good success with it.  Previously, we were writing our mocks by hand, which was a major pain in the ass.  While Rhino Mocks offers a lot of great features and has aided our testing efforts in many ways, it has also caused us some pain.  I've recently been hearing a lot of "buzz" about Moq, a new mocking framework developed by kzu.  This morning I read Daniel's "Why do we need another .NET mocking framework" post and I'm convinced that I need to give Moq a try.  A lot of the points in his article ring true to me, and make me wonder if I would prefer Moq over Rhino Mocks.  The interesting thing with trying a new mocking framework when you're involved in a large project that has already made a considerable investment in another mocking framework (Rhino Mocks) is how you go about trying it, and what you do if you prefer it to what we're currently using.  Ah the joys of software development.

I found the following links on the Moq google code homepage interesting:

 | 
Wednesday, March 26, 2008 12:58:54 PM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, March 19, 2008
Tonight I was...well....I actually don't remember what I was doing, but somehow I ended up on 22books.com.  For those of you unfamiliar with 22books.com here's a little snippet from the homepage:
22books is dedicated to the creating, sharing, and viewing of book lists. Start out by browsing some of the featured lists to the left and then open a free account and start creating lists of your own.

I created a couple books lists on 22books that contain many of my favorite books on software development.  The lists have a lot of overlap but I broke them up as follows:


All time Favorite Software books

Agile Books

.NET Books

Architecture / Design

Ruby and Rails
I think 22books.com has the potential to become a really great place to share books lists.  I really enjoy reading and have relied on many of the books in the above lists to help me progress as a software developer.  I'll probably spend a little more time refining the above lists and adding books that I didn't think of during my first pass. 

Thursday, March 20, 2008 2:34:46 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [5]  |  Trackback
 Tuesday, March 18, 2008
Tonight I was chatting a bit with a co-worker about IronPython and IronRuby and decided to have a look at IronRuby.  Getting started is supposed to be pretty easy.

1. Checkout the IronRuby source from RubyForge

svn co svn://rubyforge.org/var/svn/ironruby

2. Install Ruby via the Ruby 1-click installer: http://rubyforge.org/projects/rubyinstaller/
3. Open a Visual Studio Command Prompt
4. Install the pathname2 gem by running the following from the command line:

gem install pathname2

5. Compile IronRuby by running:

rake compile

Unfortunately when running "rake compile" I get the following errors.

C:\Development\ironruby\trunk>rake compile
(in C:/Development/ironruby/trunk)
Read in 17 resources from "C:\Development\ironruby\trunk\src\microsoft.scripting
\Math\MathResources.resx"
Writing resource file...  Done.
Read in 49 resources from "C:\Development\ironruby\trunk\src\microsoft.scripting
\Resources.resx"
Writing resource file...  Done.
rake aborted!
Command failed with status (0): [csc /nologo /noconfig /nowarn:1591,1701,17...]
C:/Development/ironruby/trunk/rakefile:197:in `exec'
(See full trace by running task with --trace)

I did a little digging around to see if I could find out what was causing the above problem but didn't uncover anything.  In hopes of making some progress and seeing ruby running on top of the CLR, I decided to try and compile using the IronRuby VS.NET solution file. Compiling IronRuby using the VS.NET solution file built everything into the \bin\debug folder.  Once that was done I was able to run rbx.exe and do a little experimentation.  rbx didn't behave like I expected and seemed to be acting pretty flaky but I was able to put in some simple Ruby expressions and see the results I expected.  Now that I have the source downloaded and compiled I'm going to dig into things a bit more to see where things stand. 

Some resources that I came across that might be useful to others include:

 |  | 
Wednesday, March 19, 2008 2:44:25 AM (Eastern Daylight Time, UTC-04:00)  #    Disclaimer  |  Comments [0]  |  Trackback