我试图在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:
它显然引发了错误,但是我的测试仍然失败。
有什么想法吗?
最佳答案
您的语法看起来正确。要进行调试,请简化以确保您的规范编码正确。
it "should raise an error" do
lambda {raise "boom"}.should raise_error
end
然后添加更多细节,直到打破为止。
lambda {raise "boom"}.should raise_error(RuntimeError)
lambda {raise StandardError.new("boom")}.should raise_error(StandardError)
关于ruby-on-rails - 预期rspec测试中的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2359439/