I have seen both styles used widely: #1 lambda { raise "Boom" }.should raise_error
and #2 expect { raise "Boom" }.to raise_error
. I like expect..to more as it reads better and hides the creation of the proc.
I looked at rspec code and it seems expect..to is suggested, however I regularly come across libraries using lambda..should. Is expect..to newer and hence not "famous" yet?
expect
is used since rspec-2, previously lambda
had to be used.
RSpec "officially" recommends to use expect
and it is possible that they will decide to "obsolete" lambda syntax.
The lambda syntax is used in most of the libraries that started life in RSpec1 days. They just haven't yet migrated (and why would they if it is still supported).
So, do use expect
instead of lambda
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With