Mocks and Stubs are one of the areas in which many developers new to testing fail to grasp. Sure i know they are fake objects which can be used for my tests, but how do they work, how can i use them? I’ve had people come up to me and ask for an early copy of just the mocks chapter of Testing Rails. Unfortunately it’s not been written yet, i’m still sifting through the various papers on the subject to make sure that i understand it before i try and explain it to other people.
Luckily people don’t have to wait for the rough cut to come out, James Mead who wrote Mocha has a nice summary slide deck on An Introduction to Mock Objects in Ruby. It’s got a heavy Mocha focus, but it’s good for everybody who wants a quick summary of the topic.
For people wondering about which mock library to use in ruby, there’s Flexmock which was written by Jim Weirich and then there is Mocha. Flexmock is the library which rails uses, and it’s been around for quite a while. It works well but the interface is a little clunky. Mocha is magical, it does things for you with a nice mocking DSL (domain specific language), and all that jazz which makes ruby so sexy.
So until i finish my chapter on mocks, check out James’ slides.
3 Comments, Comment or Ping
Reply to “Mocks in Ruby”