# "can't convert Subclass\_..." when isolating an interface

**URL:** <https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707>\
**Category:** IronRuby\
**Created:** [August 4, 2010, 11:17am UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707 "2010-08-04T11:17:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 11:17am UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/1 "2010-08-04T11:17:06Z")

</div>

Hello all,  
I’ve been trying to use caricature to stub my services in my controllers  
tests, now when I try to test this code:  
public TestController(ITestService service)  
{  
\_service = service;  
}

when my interface is:  
public interface ITestService  
{  
string GetContent();  
}

like so:  
s = isolate ITestService  
s.when\_receiving(:get\_content).return(‘some content’)  
c = TestController.new s

I get the above mentioned error (see attachment)

Any ideas what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 9:57pm UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/2 "2010-08-04T21:57:07Z")

</div>

Hi Nieve,

I don’t see anything that looks wrong. Which version of IronRuby are  
you  
using?

Let me know and I’ll see if I can reproduce the problem. If I can, I’ll  
take a stab at debugging it.

Regards,

-Charles

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 10:10pm UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/3 "2010-08-04T22:10:05Z")

</div>

Hi Charles,  
First of all, thanks for the reply.

I’m currently on IronRuby 1.1

Now, I just doubled checked this, and this happens whether I call  
isolate the interface or the implementation. Also, I presume that’s  
something with my code since Ben H.'s Kona example (that uses the same  
code) works on my machine…

I can create a quick project and put it on github so it’ll be easier to  
reproduce.

cheers,  
~n

Charles S. wrote:

> Hi Nieve,
> 
> I don’t see anything that looks wrong. Which version of IronRuby are  
> you  
> using?
> 
> Let me know and I’ll see if I can reproduce the problem. If I can, I’ll  
> take a stab at debugging it.
> 
> Regards,
> 
> -Charles

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 10:29pm UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/4 "2010-08-04T22:29:19Z")

</div>

Hi Nieve,

Sure thing. Let me know when you put the sample project up on github  
and  
I’ll take a look at it.

-Charles

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 10:56pm UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/5 "2010-08-04T22:56:12Z")

</div>

Charles,  
you can take a look at it here:

> **[GitHub - nieve/IsolationTest: testing an isolate case in iron ruby](https://github.com/nieve/IsolationTest)**
>
> testing an isolate case in iron ruby. Contribute to nieve/IsolationTest development by creating an account on GitHub.

I just hope it’s not something completely obvious…

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 11:16pm UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/6 "2010-08-04T23:16:46Z")

</div>

Nieve,

Oh… my… goodness… I’ve never seen ANYONE make that mistake before!

Just kidding 😜  
I’ll take a look at it a little later, unless someone else beats me to  
it.  
😉

Cheers,  
-Charles

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 4, 2010, 11:42pm UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/7 "2010-08-04T23:42:31Z")

</div>

I just looked at your sample project

It’s best to require spec before caricature because caricature hooks  
into  
spec  
The IHomeRepository interface is empty. Try adding a method to that and  
see  
if it still occurs.

you can also add require ‘caricature/aspnet\_mvc’

## I don’t have a windows machine running atm but I’ll check tomorrow if this didn’t help you

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Author of IronRuby in Action ([IronRuby in Action - Ivan Porto Carrero and Adam Burmister | Manning](http://manning.com/carrero))  
Microsoft IronRuby/C# MVP

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 5, 2010, 12:06am UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/8 "2010-08-05T00:06:31Z")

</div>

try doing

ITestService.isolate

or

## isolation\_for ITestService

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Author of IronRuby in Action ([IronRuby in Action - Ivan Porto Carrero and Adam Burmister | Manning](http://manning.com/carrero))  
Microsoft IronRuby/C# MVP

---

<div class="post-metadata">

**Author:** ![nieve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@nieve](https://www.ruby-forum.com/u/nieve)\
**Post date:** [August 5, 2010, 8:53am UTC](https://www.ruby-forum.com/t/cant-convert-subclass-when-isolating-an-interface/192707/9 "2010-08-05T08:53:16Z")

</div>

@Ivan- Many many thanks!! that worked 🙂

I did also try to put require spec before caricature, but that didn’t  
help. I left it though like that, since it makes sense.

The one thing I still don’t get is how come in Ben’s Kona example the  
isolate Service works and on the same machine, my code doesn’t… am  
wondering what could possibly differ, would be interesting to know.

~n
