views:

85

answers:

1

My scenario consists of the following points.

  • I have a packaged software product I am developing in C#
  • Since it is a packaged product, the public interfaces of the assemblies need to be tightly controlled...
    • All assemblies are strong-named
    • Any classes that don't absolutely have to be "public" are "internal"
  • I want to write unit tests for those "internal" classes, since they are the bulk of the code

And finally.... I want to try writing the unit tests in Ruby.

Since the unit tests would be external to the assembly containing the code under test, the assemblies under test would each need to have an "InternalsVisibleTo" attribute specifying the name of the unit test assembly. Which of course would mean that the Ruby unit tests would have to compile down to a .NET assembly so they can be given access in this way.

Can this be done? If so, how? All I can find on the web about "compiling IronRuby" is about building the actual IronRuby runtime from source.

+2  A: 

The solution is very simple (and you don't even need to compile your IronRuby code to an assembly).

IronRuby interpreter (ir.exe) supports a command line switch -X:PrivateBinding (this is case sensitive, pay attention). When the interpreter is running in the private binding mode, you can call internal and even private members of .NET classes.

Therefore, to test your .NET class internal members, run your test code as follows (assuming the test code is in a file named "test_my_code.rb"):

ir -X:PrivateBinding test_my_code.rb
Shay Friedman