Category Archives: caricature

A rant on a talk falling to pieces

Earlier this week I had the pleasure of doing a talk for the Belgian .NET user group.  During this talk I ran in to all kinds of problems. I’ve done presentations where I was royally underprepared and to avoid that this time I actually started prepping for this talk on time. I was done on time, was prepared had 5 backups of my presentation and samples. What did I learn from this, if you’re prepared other things will go wrong.
I’ll share the story of stuff that can go wrong.

Before starting the rant I have some links to share.

I have a device that I call internet on a stick, which is a vodafone usb 3G modem that I plug in to my system and it gets me on the internet (mistake 1). Since I assumed that that thing would continue to work I made most of my demos internet enabled (mistake 2). For example I have a demo where I go download pics from flickr and then show them with some animations with silverlight.
Before my presentation I changed the fonts, opened all the files I was going to talk about ran all the demos again to make sure they would work and everything went fine.
I unplug the USB device and go into the room to hook up the projector etc. The presentation starts and for the first hour everything went really well (from my perspective at least don’t know about the people attending).
We have a break and I plug the USB device in, at this point the vodafone program hangs (first time ever I swear). What’s more I can’t make it go away at all so I reboot my pc (this is still during the break).

Now I’m getting a little desperate because it still doesn’t work. With rebooting I also lost all my carefully opened files earlier (I’m showing code in about 3 different environments and 2 different OS’es).
So during the presentation I apologise and try to reboot once more while taking questions from the audience and hoping somebody will try to start a discussion with me. After rebooting I got a message saying my date was set to 2001 which I thought was peculiar but clicked it away.  I boot vmware fusion with windows 7 (this took fairly  long and is a little bit funky as the screen resolution changes a lot during this process).
Ok so far so good, by now I’ve already skipped the silverlight demo promising that it will be available as a download on my blog and will be moving on to the ironrubymvc sample. To prove I do actually use visual studio at times I wanted to open my demo project in visual studio. I open visual studio only for it to tell me that my trial has expired and I can either upgrade or close the application. Oooooookay this is completely weird because i get my software through my msdn subscription and I had been using it earlier that day.

Moral of the story: Either go vastly underprepared and wing it. Or don’t rely on the internet and always take at least 2 laptops that have identical configurations but I’m pretty sure those would or explode in my face or something will fall from the ceiling, building collapses or other mishaps.

Instead of having one demo go bad on me now I’m probably facing a reinstall of my mac because it lost a bunch of settings, for which I’m holding the vodafone responsible. At this moment I’m fairly certain that I should go less prepared and just wing it just out of fear for bigger disasters, people may die.

Getting started with Caricature and IronRuby

IronRuby 0.5 was released yesterday. You can download it on codeplex. This post will explain how you setup your ironruby environment to use it for testing existing CLR based assemblies.  We’ll touch installing gems using rake and most importantly writing a test for a CLR based class where we’ll mock out the dependencies.

Read more »

Caricature ready for beta

The last couple of days I’ve been getting Caricature to a more releasable state. The code got a thorough cleanup and refactor. Caricature now knows how to be a full mocking framework for Ruby classes and CLR classes that only interact with ruby objects. When I apply the 80/20 rule to caricature it’s definitely beta worthy.

Read more »

An update on caricature

Yesterday I explained about caricature but I didn’t have it fully tested yet. Today I’ve written a bunch of integration specs for all the platform combinations Caricature currently supports so you should be able to use Caricature also for plain ruby object mocking in addition to CLR interop mocking.

After having a very brief twitter discussion with Scott I decided it would be a good idea to change the name of the methods when\_told\_to and was\_told\_to? . In ruby objects receive messages so the wording now becomes when\_receiving and did\_receive? . I have a problem with the should naming because there is nothing conditional about it. Either you want the method to return something or you want it to return a default value for CLR value types or nil.  And if you’re asserting if a method it called that is deterministic; it is either called or not there is no gray area there.


ninja = ClrModels::Ninja.new 

@weapon.when_receiving(:attack).with(ninja).return(5) 

@ninja.attack(ninja, @weapon).should.equal 5 

@weapon.did_receive?(:attack).with(:any).should.be.successful 

Before I call it 1.0 I want to at least give ruby objects also the ability to isolate static and sealed methods as well as mocking ruby class methods.  So that for CLR to Ruby interaction you a get the full range of possibilities.

I have also set up a site on github that contains the API documentation for Caricature. When IronRuby 0.5 releases I’ll publish a blog post that will talk you through testing your CLR assembly with IronRuby, bacon and Caricature.

For now you can take a look here for example on how to use Caricature for isolating features.

IronRuby just got a mocking framework – kind of

As I mentioned in a previous post.  I started working on a small mocking framework. It has now progressed far enough to handle the most common mocking tasks.

Below I pasted the output of the integration tests for CLR interop.

when isolating CLR interfaces
- should work without expectations
- should work with an expectation with any arguments
- should work with an expectation getting different method call result
- should work for an assertion on a specific argument

when isolating CLR classes
- should work without expectations
- should work with an expectation for any arguments
- should work with an assertion for specific arguments
- should fail for an assertion with wrong arguments

when isolating CLR instances
- should work without expectations
- should work with an expectation for any arguments
- should fail for an assertion for specific arguments
- should allow to delegate the method call to the real instance (partial mock)

you will need bacon installed to run the specs. you should issue the command igem install bacon for that.

you can then install the caricature gem in ironruby by issueing

igem install caricature

To use it there are some examples in the file spec/integration_spec.rb


require 'rubygems'
require 'bacon'
require 'caricature'

ninja.when_told_to(:survive_attack_with).return(5) 

weapon.attack(ninja).should.equal 5 

ninja.was_told_to?(:survive_attack_with).with(:any).should.be.successful

There is a gotcha though, when you use it in a CLR class you’re bound to CLR rules and it only overrides the methods that are marked as virtual. We also can’t isolate static or sealed types at the moment.

I took the approach of doing away with the terminology of mocking and subbing and instead chose the much clearer Isolation. By default any method returns null or the default value of a value type. You can tell an isolation to return a specific value or raise an error etc.  Later on you can then assert if the method was actually called. 

This fits in better with the way you probably structure your tests.

I hope you like it.

You can find the source in my github account.

http://github.com/casualjim/caricature