Archive for May, 2009

21MayGetting 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.

Continue reading ‘Getting started with Caricature and IronRuby’

19MayCaricature 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.

Continue reading ‘Caricature ready for beta’

15MayAn 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.

14MayIronRuby 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

11MayJoined the lounge network

Today I received my invitation to the Lounge network. I just finished changing my homepage to include their ads in my side bar.
My reasons for joining the ad network are that on one hand I’ve been an ad-sense member for a really long time and although I’ve had ads on multiple sites it never actually made me any money. Eventually I gave up on putting those ads on my blog. So I’m not really doing it to make any money of this blog, but if it takes a small bite out of my hosting bill I’ll be a happy man :) .

The ads that are run by the lounge are .net centric and are a much better fit to the audience of this blog. It even may be helpful to somebody at times. 

Let’s see how this works out.

03MayMocking for IronRuby

As you may or may not know I’m in the process of building IronRubyMvc. At one point I did write a bunch of tests in for the code I had at that point. However that test code was written in C# with xunit and moq.  I wasn’t too happy about that so I deferred writing tests to a later date when I could use a Ruby library to write them.

That time has come, I can use bacon and it’s acceptable performance wise now, not stellar but workable. So when I started to port some of my previously written tests to bacon I ran into a road block. Mocking isn’t as straightforward as my optimistic self was expecting. This lead me to think about what exactly does a mocking framework do?

Continue reading ‘Mocking for IronRuby’

02MayUsing IronRuby with RubyMine

RubyMine was released earlier this week. I’ve used rubymine in the past and was very impressed with the IDE, so much that I’m silently hoping the guys from Jetbrains would do a C# IDE too. I’d probably buy that one as well, but for now I’ll settle for Resharper with Visual studio.

By default Rubymine won’t accept IronRuby as a ruby SDK, but I asked for help in the twitterverse and got it (http://twitter.com/iRomeo/statuses/1677867948).

settings_rubymine

Just symlinking didn’t really work because the ruby.exe listens to –version for getting its version number.  IronRuby on the other hand listens to –v to get its version number.  The solution to that is to create a batch file that will translate the –version  modifier to –v.

So instead of symlinking the ir.exe to a name that starts with ruby I created a batch file called ruby_iron.cmd with the following content.

@echo off
set IR_CMD="%~dp0ir.exe"
if "%1"=="--version" ( GOTO RUBY_VERSION )
GOTO RUBY
:RUBY_VERSION
%IR_CMD% -v
goto QUIT
:RUBY
%IR_CMD%
:QUIT

With that ruby_iron.cmd file in place you can just add IronRuby as an SDK in RubyMine.

Enjoy :)


Recent Flickrs

    Blogroll

    Recent Listening

    Scrobbler