Fwd: "can't convert Subclass_..." when isolating an interface

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)
Microsoft IronRuby/C# MVP

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

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 likeIHomeRepository.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 callisolate’.
If you instead use IHomeRepository.isolate', orCaricature::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.
<[email protected]

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