gpt4 book ai didi

ruby - 如何编写 expect {}.to raise_error when rspec's syntax is configured with only should

转载 作者:数据小太阳 更新时间:2023-10-29 07:42:35 24 4
gpt4 key购买 nike

我在 rspec 上有这个配置:

config.expect_with :rspec do |c|
c.syntax = :should
end

它使 expect {}.to raise_error 无效,我怎么能用 should 语法编写这个错误引发测试?

最佳答案

我建议仅在最新的 RSpec expect { code() }.to raise_error 语法对您不可用时才使用它:

lambda { foo( :bad_param ) }.should raise_error

lambda { foo( :bad_param ) }.should raise_error( ArgumentError )

foo( :bad_param ) 替换为您希望断言失败的任何 Ruby 代码,并将 ArgumentError 替换为您期望失败引发的任何异常类。

关于ruby - 如何编写 expect {}.to raise_error when rspec's syntax is configured with only should,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15920743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com