Handling Parameters with Caricature

I’m still finding my feet with RSpec, but early experiences are good.  I wish I could say the same for Cucumber.  Sadly, you can’t really use RSpec’s built-in mocking with the CLR, so we need an alternative.  Luckily Caricature takes the strain.  There’s not a great deal to say that isn’t covered by Ivan’s introductory articles, it’s that simple to use.  However, one thing I couldn’t figure out was how to return a value that was dependent on the inputs.  I ended up contacting Ivan, who was extremely helpful and even updated the gem to help me out.

Turns out the code I needed was:

@factory = Request::IRequestFactory.isolate 
@factory.when_receiving(:GetHeaders).returns { |x| HttpHeaders.new x }

(Note the new syntax with .isolate rather than Isolation.for)

One thing that I’m still not up to speed with in Ruby is API discovery.  All the documentation and even source code in the world isn’t as convenient as hitting auto-complete and seeing the help come up.  On the other hand, Caricature has extremely readable specs.  If I’d found this earlier I wouldn’t have had so many problems.  This, of course, one of the points of RSpec: tests you can actually read.

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s