When it comes to testing, IronRuby brings with it innovative Ruby testing frameworks that can change the way .NET developers test code by making the process simpler, faster, and more interesting than before.
For example, the RSpec testing framework provides a domain-specific language for unit tests. The following RSpec code tests a .NET method:
describe System::Collections::Stack, "Count" do it "returns 0 for empty stack" do stack = System::Collections::Stack.new stack.Count.should == 0 end end
Cucumber is a testing framework that follows Behavior Driven Development (BDD) principles. The idea behind the framework is simple but ingenious -- let project managers write the specifications for a feature, but require them to follow formatting guidelines. Developers, in turn, write code that interprets the specification document. Cucumber then combines these two and the specifications are executed as tests. For example, the following sample is a specification document that tests the .NET String class. Note the Given-When-Then format: Given describes the prerequisites, When describes the action, and Then describes the expected result:
Feature: Verify that System.String is working Scenario: Test Trim method Given I have a string that contains " IronRuby " When I execute the Trim method Then I should receive "IronRuby" as the result
The code that interprets the spec uses regular expressions and has three matching methods the developer should implement -- Given, When and Then:
Given /I have a string that contains "(.*)"/ do |str| @str = System::String.new(str) end When /I execute the Trim method/ do @result = @str.Trim end Then /I should receive "(.*)" as the result/ do |actual| @result.to_s.should == actual.to_s end
When the spec document and the code are ready, Cucumber is run via the command line to execute the tests. You get the following output:
Feature: Verify that System.String is working Scenario: Test Trim method Given I have a string that contains " IronRuby " When I execute the Trim method Then I should receive "IronRuby" as the result 1 scenario (1 passed) 3 steps (3 passed) 0m0.572s
Silverlight provides a rich GUI forWeb applications, much like Adobe Flash. Until Version 2, developing Silverlight apps could be done solely by .NET static languages like C#. Since Silverlight 2 includes the DLR, it allows writing Silverlight apps in dynamic languages like IronRuby.
The Silverlight and DLR bundle brings great things to both Ruby and .NET programmers. Ruby developers get a rich Internet application framework they can use in their language, and .NET developers can use the dynamic capabilities of Ruby, such as the ability to create a REPL (Read-Evaluate-Print-Loop) window.
Ruby On Rails
Ruby on Rails is an MVC-driven framework widely used to develop Web applications for big sites like Twitter, Yellow Pages, Hulu, and others. IronRuby lets .NET developers use their C#/VB.NET codebase and still take advantage of the Ruby on Rails framework. Furthermore, since the.NET framework is integrated with Microsoft's Internet Information Services, IronRuby becomes the top choice for running Ruby on Rails apps on IIS.
In sum, making Ruby part of the .NET Framework via IronRuby, offers enormous benefits to .NET developers, just as bridging .NET and IronRuby benefits Ruby developers. As soon as both developer camps understand the potential in this, we'll see IronRuby projects erupting everywhere. It's as simple as that.