IronRuby Links of note 01

March 20th, 2008 Aaron Junod Posted in links of note, Source, Links, Samples, IronRuby No Comments »

For some reason I have been lax in promoting the interesting IronRuby links from around the internet. Here is a new list of links, and expect weekly posts like this in the future.

Martin Maly has a set of posts for building a language on the DLR. Really interesting stuff, and he walks our through the ToyScript language that ships with IronPython.

Ivan Porto Carrero posted an update on his upcoming book, IronRuby in Action. Ivan also posts about a good looking IDE theme for Ruby in Steel, and building IronRuby and Mono in Leopard.

Michaeldotnet had posted a nice IronRuby getting started post months ago. Since then, he moved his blog to here, and posted some great stuff like semi practical IronRuby, and details about the zlib library he is writing in pure ruby.

Paul Ferrill walks through a WPF app written in IronRuby.

MSDN Blogs has a long list of DLR sites and resources within Microsoft.

Steve Eichert posted about getting started with IronRuby. If you get caught by the same compile issue he did when compiling via rake, these threads on the mailing list are talking about it. 1, 2

Lastly an oldie that I had missed, Cory Fox posted about some of the internals of IronRuby and walks through some of how IronRuby compiles and runs under the covers.

AddThis Social Bookmark Button

Testing .net with IronRuby’s mini_rspec.rb

February 21st, 2008 Aaron Junod Posted in UnitTests, Samples, IronRuby 4 Comments »

The IronRuby team has uses a couple facilities to test their own implementation of the Ruby language. simple_test.rb which resembles a Test::Unit type of framework with less baked in, and minispec by Brian Ford of the RubySpec project. (Thanks Charles for pointing out my error, sorry Brian for the wrong attribution). Minispec and RubySpec allow ruby implementations to test their compatibility among a common set of of specs produced by the RubySpec team. This allows the IronRuby team to run the same specs against Ruby, as well as run them directly through rbx.exe, the IronRuby interpreter. Once you get and compile IronRuby, you can see they have also created rake tasks to run the specs in a few scenarios. Here is the output of rake -T | grep spec.

rake rspec # run specs using Ruby - params are: class [method(…

rake spec # run specs - params are: class [method(s)] [reporter]

rake spec2 # run specs using IronRuby and Ruby - params are: c…

rake specs # run Ruby spec suite

So running rake spec from the command line will run all of the IronRuby specs through rbx. If you would like to take a look at all of these, the mini_spec framework is in %IronRubyRoot%\tests\ironruby\specs and all of the specs are in %IronRubyRoot%\tests\ironruby\specs\core.

One of the use cases I see IronRuby excelling at is writing unit tests. I’m a huge fan of RhinoMocks and NUnit, and am able to get a ton done with these tools, but after looking at testing in Ruby I’m always jealous of the tools the test centric Ruby community has at their disposal. There is no lack of elegant testing frameworks, tools, and practices on this side of the fence. Hopefully a good portion of them, if not all of them, will eventually make it over to IronRuby, but for now you can use these mini frameworks to test your .net code.

Disclaimer time, IronRuby is not even an alpha yet. Relying on these frameworks to do anything more then oooo look at me I’m testing .net with IronRuby demonstrations and practice is not suggested.

So on to the code. Let’s assume you are building a system that requires a person, and this person has a first and a last name. Imagine you have an class that represents that person that looks something like, or exactly like :

Code (c)
  1.  
  2. public class Person
  3.   {
  4.     public string FirstName { get; set; }
  5.     public string LastName { get; set; }
  6.     public string FullName
  7.     {
  8.       get { return string.Format("{0} {1}", FirstName, LastName); }
  9.     }
  10.     public int Age { get; set;}
  11.     public int AgeInDays
  12.     {
  13.       get { return Age*365; }
  14.     }
  15.   }

This complicated code MUST be tested. Below is some IronRuby code that works today that will test the class above. It looks like :

Code (ruby)
  1.  
  2. require ‘C:\projects\IronRuby\trunk\tests\ironruby\Specs\spec_helper’
  3. require ‘c:\PathToMyDll\Person.dll
  4. Nsp = NameSpaceThatTheAboveClassIsIn
  5.  
  6. describe ‘Nsp::Person’ do
  7.  
  8.   before :each do
  9.     @person = Nsp::Person.new
  10.   end
  11.  
  12.   it "should concatenate name" do
  13.     @person.first_name = "Bill"
  14.     @person.last_name = "Smith"
  15.     @person.full_name.to_str.should == "Bill Smith"
  16.   end
  17.  
  18.   it "should be able to calculate age in days" do
  19.     @person.age = 1
  20.     @person.age_in_days.should == 365
  21.   end
  22. end

That works today. Being a big fan of the spec syntax, I think this test reads very well, much less clutter then in a typical xUnit test.

Walking through the test, notice that we first bring in and alias the external resources we will need. Then we dive into a describe block that sets the initial context of the test. The describe method will either take a type or a string, but did not seem to like taking a .net type yet. Then we have a before filter that will be run before each test, setting initial state for the contexts below. Then we have a number of it blocks where specific tests are performed. Notice that once we have a Person instance, we can address it’s variables via Ruby conventions. My C# class has a FirstName property, but I can use the first_name convention in IronRuby, smooth.

Also of note, notice I had to call .to_str on @person.full_name. This is due to the fact that IronRuby string != CLR Strings as of yet. A recent thread on the mailing list reminds us all that the team will be fixing this later, but calling to_str will work.

Will I be doing this at work? Not yet, but the idea of using Ruby test tools to test my .net things is very appealing to me. Less cruft, mocking and stubbing should be a lot easier, and tools like AutoTest will change how I do TDD in .net if things come together as I am imagining.

AddThis Social Bookmark Button

Calling Ruby from within .net

September 30th, 2007 Aaron Junod Posted in Source, Implementation, Samples, IronRuby No Comments »

Cory Foy posted a very in depth post explaining how to call Ruby from within .net. This post is much more then just code, it really digs deep into how IronRuby is working under the covers, very informative! Cory describes a bit on how the RubyEngine is working under the covers, and how the AST (abstract syntax tree) plays into the execution. Much like Cory, though, I was unaware that the ?? operator has been added to .net 3.0, and that’s great. (c#)?? == (ruby)||= Get it? :)

On a related note, Phil Haack also updated the wiki with a sample on executing Ruby in .net here.

AddThis Social Bookmark Button

Weekend update and links

July 30th, 2007 Aaron Junod Posted in Silverlight, Samples, IronRuby No Comments »

I spent the weekend trying to dive into Microsoft.Scripting, AKA the DLR, and between chasing my son and various trips to the store I was able to grok some of the framework. I hope to start posting more in depth content about how IronRuby is actually implemented on the DLR. I also spent some time with Silverlight and ended up throwing out a VM that was probably ok. A couple things I learned about silverlight over the weekend :

Don’t install 1.0 RC and 1.1 alpha, the 1.1 alpha is backwards compatible. (thanks Wilco).
The 1.0 SDK requires VS.net 2005, so don’t download it if you are trying to go Orcas only.
There were enough breaking changes between the past version and this version that not all silverlight pages may work right now if you’ve done the upgrade, so don’t throw out your VM because you can’t get Zero Gravity working :)
The DLR console is WAY cool.
Windows 2008 makes a perfectly good platform to development on once you turn on the “desktop experience” and turn off IE Enhanced Security.

Now the weekend links :
Mark (m2web) posts a Windows.Forms sample using Ironruby to create forms, and trap events.
A new IronRuby blog is up as well, and mentions IronMonkey, an effort to bring IronPython and IronRuby scripting to firefox.

AddThis Social Bookmark Button

Launch post round up

July 25th, 2007 Aaron Junod Posted in Samples, IronRuby No Comments »

Ironruby is out, and there are some noteworthy posts out there.

John Lam announces it’s availability, and provides a download link and build instructions. If you even want to call them instructions, simply download the zip, unzip, and run build.cmd from a visual studio command prompt. He also announces the final home of IronRuby will be on rubyforge, the defacto standard for hosting open source ruby projects. He also announces that IronRuby will be administered under a liberal Microsoft open source license, and community code contributions will be welcome.

Scott Guthrie provides some background into the DLR project, and then walks us through a initial hello world app using IronRuby which utilizes WPF. If you are like me you might just type all the code into a window read Scott’s whole post and download the zip file at the end, the wpf.rb is also required which simply sets up some variables and assembly bindings.

Scott Hanselman provided a meatier sample, in which he found some pre-alpha weirdness, which is more then expected. He outlines some initial typing issues, and also raises what could be a very interesting topic for the IronRuby team. In Ruby classes are Pascal cased (initial caps), but in .net there are no rules about capitalization within classes. For now he had to rename the class in his external DLL so IronRuby could address it, but I’m sure that’s something that will be addressed quickly. His meatier sample calls the Wesebe web services and displays the results in a WPF form.

Javier G. Lozano also provides a simple sample of trapping an event with sample c# and IronRuby code.

AddThis Social Bookmark Button