Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼


Dynamic Language Plus .NET


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

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)
When /I execute the Trim method/ do
  @result = @str.Trim
Then /I should receive "(.*)" as the result/ do |actual|
  @result.to_s.should == actual.to_s

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)


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.

Microsoft's Gestalt project took Silverlight in a different direction, letting developers interact with the browser in Silverlight-supported languages, rather than in JavaScript. Gestalt allows adding <script> tags that contain IronRuby code (IronPython and XAML are supported as well), replacing JavaScript with Ruby for client-side scripting.

To use it, include a JavaScript file named dlr.js, then write Ruby code inside <script language="ruby"> tags. For example, the following HTML page contains a textbox and a button: Once the user writes his or her name and clicks "Congrat!", a Ruby script shows an alert with a welcome message and adds the message to a <div> element on the page:

        <script src="dlr.js" type="text/javascript"></script>  
  <input type="text" id="full_name"/>
  <input id="say_hello" type="button" value="Congrat!" />
  <br />
  <div id="txt" style="font-size:100px; color:green"></div>
  <script language="ruby">
    document.say_hello.click {
      msg = "Hello #{document.full_name.value}"
      window.alert msg
      document.txt.innerHTML = msg

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.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.