Why use lambda in RSpec?

2007-11-14 14:16:30 +0000

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