我正在尝试编写测试。数据库应该引发异常,我想检查一下,引发异常。
expect { save_to_db(@params)}.to raise_exception(PG::Exception)
但是
RSpec::Expectations::ExpectationNotMetError: expected {:PG=>Exception} but nothing was raised
即使我得到
ERROR - 27/Feb/2020 10:52:19 PG::RaiseException: ERROR: Message ...
有什么提示吗? :)
编辑:
修正错别字,现在的结果是
RSpec::Expectations::ExpectationNotMetError: expected PG::RaiseException but nothing was raised
您在raise_exception(PG:Exception)
中有一个错别字-它必须是raise_exception(PG::Exception)
(请注意,双冒号而不是单冒号)。