gpt4 book ai didi

ruby-on-rails - rspec 测试中预计会出现错误

转载 作者:行者123 更新时间:2023-12-02 23:11:26 25 4
gpt4 key购买 nike

我试图预期 rspec 测试中出现错误。

lambda {Participant.create!({:user_id => three.id, :match_id => match.id, :team => 1})}.should raise_error StandardError

现在我只是使用 StandardError 来确保它正常工作。

1) StandardError in 'Participant should never allow more participants than players'. 
This game is already full. Cannot add another player.
/home/josiah/Projects/Set-Match/app/models/participant.rb:12:in `do_not_exceed_player_count_in_match'
./spec/models/participant_spec.rb:24:

它显然抛出了错误,但我的测试仍然失败。

想法?

最佳答案

有一段时间了,但至少在 RSpec 2.5 中,可以使用

expect {raise 'boom'}.to raise_error(RuntimeError, /boom/)

关于ruby-on-rails - rspec 测试中预计会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2359439/

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