0

Example of using ironRubys mini_rspec library

by klh 27. august 2008 09:55

This is a breakthrough for me, since it is my dream to test .Net code with RSpec through ironRuby.

The following Ruby code is testing a person class written i C# (I placed the dll in my temp library to make it more easy):

######################################################################################

require 'C:\ironruby\trunk\tests\ironruby\Specs\spec_helper'
require 'c:\temp\PersonLib.dll'
Nsp = PersonLib

describe "Person"  do
  it "should return fullname when given first and last name" do
  person = Nsp::Person.new
  person.first_name = "Bill"
  person.last_name = "Smith"
  "#{person.full_name}".should == "Bill Smith"
   end
   it "should return age in days when given age in years" do
     person = Nsp::Person.new
     person.age = 33
     person.AgeInDays.should == 12045
     end
end

######################################################################################

It did take me some time to figure out that the FullName property returning a string had to be placed within a string in order to work.

 

This is the output from the test:

 

image

This is the Person class in C#:

 

using System;
using System.Collections.Generic;
using System.Text;
namespace PersonLib
{
public class Person
{
private string firstName;
private string lastName; 
public string FullName
{
get { return string.Format("{0} {1}", FirstName, LastName); }
}
private int age;
public int AgeInDays
{
get { return Age * 365; }
}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
}
 
The code is very much inspired by:
http://rubydoes.net/2008/02/21/testing-net-with-ironrubys-mini_rspecrb/ 

                    kick it on DotNetKicks.com
                   

Tags:

Kommentarer

Tilføj kommentar


(Viser dit Gravatar icon)  

  Country flag

biuquote
  • Kommentar
  • Eksempel
Loading



Powered by BlogEngine.NET 1.4.5.0
Original Design by Laptop Geek, Adapted by onesoft