Why use lambda in RSpec?
November 15th, 2007
RSpec allows you to write nice readable tests… and some little tricks make it even nicer! And I don’t know about you, but the word lambda is (1) ugly, (2) means basically bugger all and (3) is hard to pronounce late at night… so lets replace it!
How about this for a spec:
1 2 3 |
doing {
@my_object.function
}.should raise_error(ArgumentError, "Unknown tag type") |
Nice and readable..
Of course, it is functionally the same as:
1 2 3 |
lambda {
@my_object.function
}.should raise_error(ArgumentError, "Unknown tag type") |
But MUCH easier to read!
To get it to work in rails, put the following line of code into your spec_helper.rb file.
alias :doing :lambda |
Simple heh?
blogLater
Mikel
Recent Articles
Latest comments
- Dan Manges
+1. If you’re doing the same thing a few times, it’s not a problem to duplicate it. If you’re doing...
- Zach Dennis
David, I’m a little surprised by your response, seeing as you’re an advocate of outside-in development. How can you blackbox...
- Mikel
@david…
OOoooooooooooo…..............
Who’s ya daddy?!
Nice.
- David Chelimsky
I’m kind of with Mikel on this one from a philosophical stance – black box testing is less brittle.
But...
- David Chelimsky
Mikel – have you seen the ObjectDaddy library at http://github.com/flogic/object_daddy? It solves the same problem you’re solving here in a...
Leave a Reply