开发者

Which style,lambda..should or expect..to, is preferred for testing expectations in RSpec?

I have seen both styles used widely: #1 lambda {开发者_JS百科 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜