How to use RSpec's should_raise with any kind of exception?

后端 未结 5 2082
太阳男子
太阳男子 2020-12-07 08:46

I\'d like to do something like this:

some_method.should_raise 

How should I do this?

         


        
5条回答
  •  情书的邮戳
    2020-12-07 09:03

    Instead of lambda, use expect to:

       expect { some_method }.to raise_error
    

    This is applies for more recent versions of rspec, i.e. rspec 2.0 and up.

    See the doco for more.

提交回复
热议问题