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

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

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [August 4, 2010, 11:43pm UTC](https://www.ruby-forum.com/t/fwd-cant-convert-subclass-when-isolating-an-interface/192753/1 "2010-08-04T23:43:06Z")

</div>

try doing

ITestService.isolate

or

## isolation\_for ITestService

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

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [August 5, 2010, 4:48am UTC](https://www.ruby-forum.com/t/fwd-cant-convert-subclass-when-isolating-an-interface/192753/2 "2010-08-05T04:48:02Z")

</div>

It looks like the generated isolation isn’t implementing  
IHomeRepository:

irb(main):032:0\> repo = isolate  
FakeMvcProject::Controllers::IHomeRepository  
=\> #\<Object805c8b559a854b9ca0269e9b1d7f7643:0x0000482\>  
irb(main):033:0\> repo.GetType.get\_interfaces  
=\> [System.ComponentModel.ICustomTypeDescriptor,  
IronRuby.Runtime.Calls.IRubyDynamicMetaObjectProvider,  
System.Dynamic.IDynamicMetaObjectProvider,  
IronRuby.Runtime.IRubyObject,  
IronRuby.Runtime.IRubyObjectState,  
IronRuby.Runtime.IDuplicable,  
System.Runtime.Serialization.ISerializable]

I also tried this (notice that IHomeRepository _is_ listed):

irb(main):034:0\> class Foo  
irb(main):035:1\> include IHomeRepository  
irb(main):036:1\> end  
=\> Foo  
irb(main):037:0\> Foo.new.GetType.get\_interfaces  
=\> [IronRuby.Runtime.IRubyObject,  
IronRuby.Runtime.IRubyObjectState,  
System.Runtime.Serialization.ISerializable,  
IronRuby.Runtime.Calls.IRubyDynamicMetaObjectProvider,  
System.Dynamic.IDynamicMetaObjectProvider,  
System.ComponentModel.ICustomTypeDescriptor,  
IronRuby.Compiler.Generation.IRubyType,  
FakeMvcProject.Controllers.IHomeRepository]

It looks like this might be a problem with Caricature (perhaps only when  
running IR 1.1?).

-Charles

---

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [August 5, 2010, 5:13am UTC](https://www.ruby-forum.com/t/fwd-cant-convert-subclass-when-isolating-an-interface/192753/3 "2010-08-05T05:13:48Z")

</div>

Aha! I’ve figured it out.

Here’s the `isolate’ method (from lib/caricature/core\_ext/object.rb):

def isolate(name=nil, recorder = Caricature::MethodCallRecorder.new,  
expectations = Caricature::Expectations.new, &block)  
iso = Caricature::Isolation.for(self, recorder, expectations)  
return iso unless name  
if block  
if block.arity \> 0  
@expectation = iso.when\_receiving(name, &block)  
else  
@expectation = iso.when\_receiving(name)  
instance\_eval &block  
end  
end  
iso  
end

The important line to note is the following:  
iso = Caricature::Isolation.for(self, recorder, expectations)

This `isolate' method let's you do stuff like`IHomeRepository.isolate’.

The TypeError you are experiencing is due to the fact that you are  
isolating  
whatever the implicit `self' happens to be at the time you call`isolate’.  
If you instead use `IHomeRepository.isolate', or`Caricature::Isolation.for  
IHomeRepository’, it should work just fine.

Perhaps Caricature could be tweaked a little so that making this mistake  
is  
more obvious (I was stumped too ;P).

Cheers,  
-Charles

On Wed, Aug 4, 2010 at 9:47 PM, Charles S.  
\<removed\_email\_address@domain.invalid
