如何使用 RSpec 的 should_raise 有任何异常? [英] How to use RSpec's should_raise with any kind of exception?

查看:12
本文介绍了如何使用 RSpec 的 should_raise 有任何异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

some_method.should_raise <any kind of exception, I don't care>

我该怎么做?

some_method.should_raise exception

...不起作用.

推荐答案

expect { some_method }.to raise_error

RSpec 1 语法:

lambda { some_method }.should raise_error

请参阅文档(对于 RSpec1 语法)和 RSpec 2 文档了解更多信息.

See the documentation (for RSpec 1 syntax) and RSpec 2 documentation for more.

这篇关于如何使用 RSpec 的 should_raise 有任何异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆