Getting started with IronRuby and c# issues

Hi IronRuby mailing list,

Inspired by a talk by Ben H. on testing c# with Ruby I thought I’d
give it
a go but
I’m frustratingly stuck at the first hurdle. I’ve emailed Ben but as
I’ve
not had an immediate response I thought I’d open it to you good people.

Any way. I thought I’d start off simple and follow Dom Green’s blog.
domgreen.com/2010/02/07/pumping-iron-ruby-net-testing/

He’s set a class in c# with a simple property (here’s mine)

namespace IronRubyAndCSharp
{
public class Person
{
public string FirstName { get; set; }

    public Person(string name)
    {
        FirstName = name;
    }
}

}

and tested it like so

require “test/unit”
require “…/IronRuby/bin/debug/IronRubyAndCSharp.dll”

class PersonTest < Test::Unit::TestCase
include IronRubyAndCSharp
def test_create_person_called_john
john = Person.new(“John”)
assert_not_nil(john)
assert_equal(“John”,Person.FirstName)
end
end

RubyMine(RM) has no problem with the require of the dll but it does have
a
problem recognising the namespace “IronRubyAndCSharp”
and the Person class (squiggly lines ahoy).

When I run the tests in RM I get

NoMethodError: undefined method FirstName' for IronRubyAndCSharp::Person:Class C:/Users/John/Documents/IronRuby/Tests/Person_test.rb:14:intest_create_person_called_john’
:0:in send' :0:ineach’
C:/Program Files (x86)/IronRuby
0.9.4.0/Lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in
run_suite' :0:ineach’
C:\Program Files (x86)\JetBrains\RubyMine
2.0.1\rb\testing\patch\testunit/test/unit/ui/testrunnermediator.rb:36:in
run_suite' testrunner.rb:213:instart_mediator’
C:\Program Files (x86)\JetBrains\RubyMine
2.0.1\rb\testing\patch\testunit/test/unit/ui/teamcity/testrunner.rb:191:in
start' testrunnerutilities.rb:28:inrun’
C:/Program Files (x86)/IronRuby
0.9.4.0/Lib/ruby/1.8/test/unit/autorunner.rb:216:in run' C:/Program Files (x86)/IronRuby 0.9.4.0/Lib/ruby/1.8/test/unit/autorunner.rb:12:inrun’

Just in case RubyMine was at fault I dropped out to good old ir.exe

C:\Users\John\Documents\IronRuby\Tests>ir Person_test.rb --name
test_create_pers
on_called_john
Loaded suite Person_test
Started
E
Finished in 0.041992 seconds.

  1. Error:
    test_create_person_called_john(PersonTest):
    NoMethodError: undefined method FirstName' for IronRubyAndCSharp::Person:Class Person_test.rb:14:intest_create_person_called_john’
    :0:in send' :0:ineach’
    :0:in each' testrunner.rb:66:instart_mediator’
    testrunnerutilities.rb:28:in `run’

1 tests, 1 assertions, 0 failures, 1 errors

I’ve stuck my code up on github
http://github.com/johnnonolan/IronRubyAndCSharp if you feel that was
inclined.

Any pointers, help or whatever much appreciated.

PlzSendMeTehCodez

John(no)

ironruby will have ‘rubified’ the Person class’s FirstName method to
first_name and I think you mean to assert against the john instance of
Person (rather than the Person class).

Otherwise it looks pretty close.

Try:

require “test/unit”
require “…/IronRuby/bin/debug/IronRubyAndCSharp.dll”

class PersonTest < Test::Unit::TestCase
include IronRubyAndCSharp
def test_create_person_called_john
john = Person.new(“John”)
assert_not_nil(john)
assert_equal(“John”,john.first_name)
end
end

On Sat, Feb 20, 2010 at 9:16 PM, John N. [email protected]
wrote:

Hi IronRuby mailing list,
Inspired by a talk by Ben H. on testing c# with Ruby I thought I’d give
it
public string FirstName { get; set; }
include IronRubyAndCSharp
NoMethodError: undefined method FirstName' for IronRubyAndCSharp::Person:Class C:/Users/John/Documents/IronRuby/Tests/Person_test.rb:14:intest_create_person_called_john’
:0:in send' :0:ineach’
C:/Program Files
(x86)/IronRuby
0.9.4.0/Lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in
run_suite' (x86)/IronRuby 0.9.4.0/Lib/ruby/1.8/test/unit/autorunner.rb:216:inrun’

  1. Error:
    I’ve stuck my code up on
    github http://github.com/johnnonolan/IronRubyAndCSharp if you feel that
    was

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs