我试图预期 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/