When code surprises you in a good way

time to read 3 min | 587 words

[Note: This is another post where I just added over several hours as I added the finishing touches for Rhino Mocks.]

I found out something nice about Rhino Mocks, it allows you to specify ordered sequences of unordered method calls. Meaning that I can specify that calls A, B & C would occur in any order, and only after those three calls, the calls for D, E & F would occur (in that order, or in any order). I'm not very clear, but I'm working on an article that should explain it all, and expose all the nice things that Rhino Mocks 2.0 can do :-)

That is not something that I put it. I debugged it, and I thought that this was just a freak chance, but apperantly another feature I put it (adding IDisposable to verify mocks*) prevented it from being fully useful. I had to add three lines of code to handle the situation, and that was that. The reverse behaviour shouldn't be possible (I think, Rhino Mocks surprised me before tested it, as expected, it doesn't work)  so currently I don't think you can say "Do X then Y then Z, Do A then B the C, but I don't care if XYZ is first, or ABC". It wouldn't be too hard to add this, but I currently don't need it, if you think this would be useful, tell me and I'll add it.

Interestingly, I found that as I neared completion, I needed less and less code to do what I want, some thing just happened, without having to add any more code, and the rest was a matter of adding a derived class and a way to call it.

A lot of the effort was spend in making the code easier to read and write. In this, I am quite inspired by NMock2 and it's use of Matchers (what NMock & Rhino Mocks call constraints) and how easy it is to use. I'm currently moving NQA to use the new version** of Rhino Mocks. It's actually fun, and I added some nicer syntax options for recording expectations. The nicer thing is that I got rid of some warts that were there because the Rhino Mocks 1.0 used Remoting, and there were several places where that leaked through. {Having to inherit from MarshalByRef to get a proxy for a concrete class, can't do normal comparision, etc}.

I'm very glad that I spent a lot of time perfecting the error messages, I make purposefully a lot of mistakes trying to convert from one version to the other, and it's good to see how easy it is to solve them using Rhino Mocks. I'm finding my share of bugs in the tests. Things that work properly, but just because the code isn't checking them well enough, or version 1.0 allowed them to slip through, and the version 2.0 doesn't.

01:00 AM: I've finally moved all of NQA to use Rhino Mocks version 2.0, it's been very educating. I've a lot of info to write that article about. Four pages of just headnotes :-) I expect to be done with the article and documentation and be able to officially release it tomorrow.

* It actually makes sense, wait for the article.

** This is the second time already, this time I'm keeping the syntax, it's too much work.