[Ironruby-core] Mocking behavior between clr types

andrew Wilson a.wilson82 at gmail.com
Sun Jan 24 13:19:09 EST 2010


As I have been working more and more with testing C# via IronRuby & Rspec, I
have found myself wanting to use more and more of the rspec framework for
testing.  I have also found problems that I am not sure how to work through
yet.

For instance lets say I have two c# classes:

public class Foo
{
private Bar _bar;

public Foo(Bar someBar)
{
this._bar = someBar;
}

public int GetBarCount()
{
return this._bar.Count;
}

}


public class Bar
{
private int _count = 0;

public Count
{
get { return _count;}
}
}


in my spec test I want to do something like this:

b = Bar.new
b.stub!(:Count).and_return(400)

f = Foo.new(b)
f.GetBarCount(),should == 100

The problem is that because I am stubbing the Bar instance via the dlr, the
CLR call on f never sees the stub and just returns 0.

Is there any way to make this work?  I was wondering if I could maybe make
my Foo instance a proxy or mock itself and see if that would let the method
calls work... but I haven't had any luck :(

-A

-- 
When I wrote this, only God and I understood what I was doing.  Now, God
only knows - Karl Weierstrass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100124/8161c898/attachment.html>


More information about the Ironruby-core mailing list