Executing Ruby unit test through C# with IronRuby

90 Views Asked by At

I want to execute Ruby unit tests (classes that inherit from Test::Unit::TestCase) with IronRuby. I tried to execute the complete file with

C# code:

var engine = Ruby.CreateEngine();
engine.Runtime.IO.RedirectToConsole();
engine.ExecuteFile("example.rb");

example.rb:

require 'test/unit'

puts 'test'

class ExampleTests < Test::Unit::TestCase 
 def test_pass
  puts 'test pass'
  assert_equal(1, 1, 'Test should work') 
 end 

 def test_fail 
  puts 'test fail'
  assert_equal(2, 0, 'Test should fail')
 end 
end 

But this did not run the unit test. This outputs only "test". I was expecting the same behaviour that I would get if I would run "ruby example.rb". Am I doing something wrong?

Context: I have a C++ library that is tested with jruby over JNI. We need the JNI interface only for jruby and we cannot debug the library with jruby. Therefore the idea was to replace jruby with IronRuby to get rid of the JNI interface. We have a C# Wrapper around the C++ library and that is where IronRuby comes into the game: I need a ruby class that can call the wrapper (same was done with jruby to call the JNI interface). It is possible to debug the C# wrapper so it should work with IronRuby too. I want to execute every test and get the results (it is enough to know which one passed and which one failed)

I need the behaviour of executing the file because I don't know the names of the classes or functions and the autorunner of the ruby tests finds all tests in a file. I am not an expert with ruby. Please help me to run the unit tests.

Thank you for your help.

0

There are 0 best solutions below