13

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?

or9ob
  • 2,313
  • 4
  • 25
  • 45

1 Answers1

14

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.

Dmytrii Nagirniak
  • 23,696
  • 13
  • 75
  • 130