[Ironruby-core] Mocking behavior between clr types
Ivan Porto Carrero
ivan at flanders.co.nz
Wed Jan 27 04:17:53 EST 2010
Well this is going to be a very interesting problem to solve when I'm done
with the edits on my book.
ICorProfilerCallback2 is windows only
Mono.Cecil requires steps before running the app
On the mono IRC channel I'm told that there is no other way to do it in
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Author of IronRuby in Action (http://manning.com/carrero)
On Wed, Jan 27, 2010 at 6:58 AM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote:
> yes typemock uses the CLR profiling API and is a paid product. I don't know
> if typemock runs on Mono either, couldn't find it on their website.
> For me running on mono is one of the base requirements of my mocker,
> because I'm too often on my mac or linux machines to neglect that.
> That being said 99% of your tests will not need to mock a static method,
> and if you know about the limitation you can work around it if you're in
> control of the code.
> I've looked into this now and I can't find the ICorProfilerCallback2
> interface in Mono on my mac. Mono allows you to write a profiler too though
> but AFAICT that has to be written in C, which I don't know, and it would
> also require to start mono with a different set of parameters.
> So I guess the way forward is mono.cecil, but I don't like the approach I
> need to take at all:
> Backup the assemblies in the bin
> before running the tests instrument every assembly in the bin folder with
> all the static method calls wrapped inside a before and after hook. These
> hooks call out to caricature and provide the mocking behavior.
> Save the modified assembly in the bin
> run the test.
> if there is an error or an interrupt or exit, restore assemblies from
> backup and this can go wrong easily.
> It also means I have to make it a requirement to require caricature before
> requiring any of your application code in the test_helper or spec_helper
> If somebody has a better solution by all means share, or better yet put it
> in and send me a pull request
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Blog: http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
> On Wed, Jan 27, 2010 at 4:50 AM, Miguel Madero <me at miguelmadero.com>wrote:
>> TypeMock is doing thing slightly different that allows you to intercept
>> essentially calls to any member (static, sealed types, non-virtuals, etc).
>> It take sa different approach than Rhino and Moq, I'm not sure if something
>> similar could be done using Ruby, I'm just dropping the idea here....
>> On Mon, Jan 25, 2010 at 7:34 AM, Ivan Porto Carrero <ivan at flanders.co.nz>wrote:
>>> You don't need to do anything as drastic as disassemble dlls though :).
>>> There are several solutions and I think the cleanest one is to use the
>>> CLR profiling API. Another avenue I could take is to use Mono.Cecil but I
>>> don't like the idea of the IL rewriting stuff. heck even postsharp would
>>> probably do the trick.
>>> I need to look into the CLR profiling API to make the rest of the stuff
>>> happening as that is the cleanest solution IMO. The limitation only exists
>>> if you're mocking CLR classes for use in other CLR classes. If you're going
>>> to use it in ruby code you can do whatever you want.
>>> My mocker does most of what Moq and Rhino.Mocks do, except that it
>>> doesn't use LCG or expression trees but just the reflection API once per
>>> type. from there on out it uses ruby to do its job.
>>> What I need to add but don't know if they are really necessary are call
>>> count constraints.
>>> And I also want to make the RSpec integration a little bit better so that
>>> you can enlist an expectation for verification too.
>>> The docs are a bit outdated too, best is to look into
>>> spec/bacon/integration that's where I test out the new features or syntax
>>> I have a chapter in my book that explains the use of Caricature with
>>> RSpec which will be in the update at the end of january. Contact me off list
>>> if you want a discount :)
>>> Met vriendelijke groeten - Best regards - Salutations
>>> Ivan Porto Carrero
>>> Blog: http://flanders.co.nz
>>> Twitter: http://twitter.com/casualjim
>>> Author of IronRuby in Action (http://manning.com/carrero)
>>> On Sun, Jan 24, 2010 at 8:16 PM, andrew Wilson <a.wilson82 at gmail.com>wrote:
>>>> Seems like a what I was looking for, however according to the
>>>> documentation it says it can only mock virtuals and non-static though.
>>>> I don't want that restriction :( One of the advantages I was hoping to
>>>> leverage was the ability to re-write methods that I wouldn't otherwise be
>>>> able to.
>>>> When I wrote this, only God and I understood what I was doing. Now, God
>>>> only knows - Karl Weierstrass
>>>> Ironruby-core mailing list
>>>> Ironruby-core at rubyforge.org
>>> Ironruby-core mailing list
>>> Ironruby-core at rubyforge.org
>> Miguel A. Madero Reyes
>> www.miguelmadero.com (blog)
>> me at miguelmadero.com
>> Ironruby-core mailing list
>> Ironruby-core at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironruby-core