Nieve Gr
2010-Aug-04 09:17 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
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? Attachments: http://www.ruby-forum.com/attachment/4902/error.jpg -- Posted via http://www.ruby-forum.com/.
Charles Strahan
2010-Aug-04 19:45 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
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 On Wed, Aug 4, 2010 at 4:17 AM, Nieve Gr <lists at ruby-forum.com> wrote:> 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? > > Attachments: > http://www.ruby-forum.com/attachment/4902/error.jpg > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/79235b30/attachment.html>
Nieve G.
2010-Aug-04 20:10 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
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 Hall''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 Strahan 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-- Posted via http://www.ruby-forum.com/.
Charles Strahan
2010-Aug-04 20:27 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
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 On Wed, Aug 4, 2010 at 3:10 PM, Nieve G. <lists at ruby-forum.com> wrote:> 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 Hall''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 Strahan 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/93df055a/attachment.html>
Nieve G.
2010-Aug-04 20:56 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
Charles, you can take a look at it here: http://github.com/nieve/IsolationTest I just hope it''s not something completely obvious... -- Posted via http://www.ruby-forum.com/.
Charles Strahan
2010-Aug-04 21:09 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
Nieve, Oh... my... goodness... I''ve never seen ANYONE make that mistake before! Just kidding ;P I''ll take a look at it a little later, unless someone else beats me to it. ;) Cheers, -Charles On Wed, Aug 4, 2010 at 3:56 PM, Nieve G. <lists at ruby-forum.com> wrote:> Charles, > you can take a look at it here: > http://github.com/nieve/IsolationTest > > I just hope it''s not something completely obvious... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/291fd78f/attachment.html>
Ivan Porto Carrero
2010-Aug-04 21:34 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
try doing ITestService.isolate or isolation_for ITestService --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Author of IronRuby in Action (http://manning.com/carrero) Microsoft IronRuby/C# MVP On Wed, Aug 4, 2010 at 10:56 PM, Nieve G. <lists at ruby-forum.com> wrote:> Charles, > you can take a look at it here: > http://github.com/nieve/IsolationTest > > I just hope it''s not something completely obvious... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/695b2dab/attachment-0001.html>
Ivan Porto Carrero
2010-Aug-04 21:39 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
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 Carrero Author of IronRuby in Action (http://manning.com/carrero) Microsoft IronRuby/C# MVP On Wed, Aug 4, 2010 at 10:56 PM, Nieve G. <lists at ruby-forum.com> wrote:> Charles, > you can take a look at it here: > http://github.com/nieve/IsolationTest > > I just hope it''s not something completely obvious... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/d53cc10c/attachment.html>
Ivan Porto Carrero
2010-Aug-04 21:40 UTC
[Ironruby-core] 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 Carrero Author of IronRuby in Action (http://manning.com/carrero) Microsoft IronRuby/C# MVP On Wed, Aug 4, 2010 at 10:56 PM, Nieve G. <lists at ruby-forum.com> wrote:> Charles, > you can take a look at it here: > http://github.com/nieve/IsolationTest > > I just hope it''s not something completely obvious... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/fb288c8d/attachment.html>
Ivan Porto Carrero
2010-Aug-04 21:40 UTC
[Ironruby-core] Fwd: "can''t convert Subclass_..." when isolating an interface
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 Carrero Author of IronRuby in Action (http://manning.com/carrero) Microsoft IronRuby/C# MVP On Wed, Aug 4, 2010 at 10:56 PM, Nieve G. <lists at ruby-forum.com> wrote:> Charles, > you can take a look at it here: > http://github.com/nieve/IsolationTest > > I just hope it''s not something completely obvious... > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/14793dfe/attachment.html>
Charles Strahan
2010-Aug-05 02:47 UTC
[Ironruby-core] Fwd: "can''t convert Subclass_..." when isolating an interface
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 On Wed, Aug 4, 2010 at 4:40 PM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote:> > > try doing > > ITestService.isolate > > or > > isolation_for ITestService > --- > Met vriendelijke groeten - Best regards - Salutations > Ivan Porto Carrero > Author of IronRuby in Action (http://manning.com/carrero) > Microsoft IronRuby/C# MVP > > > > On Wed, Aug 4, 2010 at 10:56 PM, Nieve G. <lists at ruby-forum.com> wrote: > >> Charles, >> you can take a look at it here: >> http://github.com/nieve/IsolationTest >> >> I just hope it''s not something completely obvious... >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/b9e847f1/attachment.html>
Charles Strahan
2010-Aug-05 03:09 UTC
[Ironruby-core] Fwd: "can''t convert Subclass_..." when isolating an interface
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 Strahan <charles.c.strahan at gmail.com> wrote:> 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 > > > > On Wed, Aug 4, 2010 at 4:40 PM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote: > >> >> >> try doing >> >> ITestService.isolate >> >> or >> >> isolation_for ITestService >> --- >> Met vriendelijke groeten - Best regards - Salutations >> Ivan Porto Carrero >> Author of IronRuby in Action (http://manning.com/carrero) >> Microsoft IronRuby/C# MVP >> >> >> >> On Wed, Aug 4, 2010 at 10:56 PM, Nieve G. <lists at ruby-forum.com> wrote: >> >>> Charles, >>> you can take a look at it here: >>> http://github.com/nieve/IsolationTest >>> >>> I just hope it''s not something completely obvious... >>> -- >>> Posted via http://www.ruby-forum.com/. >>> _______________________________________________ >>> Ironruby-core mailing list >>> Ironruby-core at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/ironruby-core >>> >> >> >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100804/e5852b78/attachment-0001.html>
Nieve G.
2010-Aug-05 06:53 UTC
[Ironruby-core] "can''t convert Subclass_..." when isolating an interface
@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 -- Posted via http://www.ruby-forum.com/.