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
- Jason King
Problem is that there are many things in the RFC that you specifically don’t want to accept as valid...
- Bryan Ray
@Mikel Excellent post. I’ve often had a hard time getting away from fixtures, because I like the added benefit you...
- marcus
it seems like he removed the pages, what a lost … :-( happen to have the pages saved offline ,...
- Mikel
Heya Zach,
That’s great to hear!
Thanks for updating the comments too! Much appreciated that you are letting others know...
- Zach Dennis
Mikel,
Ever since I posted my long winded comment I’ve been much more proactive in using inline helpers over before...
- grahame
He really nailed it. That is so true. Overly cautious on the first and “underly” cautious on the second.
That’s...
Leave a Reply