0
我想要做類似的方法調用測試:使用RSpec Rails的測試異常
call_to_method_1 param1
這種方法可以提高例如:
raise msg1 if ...
raise msg2 if ...
我的問題是如何與測試例外的msg1,msg2與RSpec的異常消息。
我想要做類似的方法調用測試:使用RSpec Rails的測試異常
call_to_method_1 param1
這種方法可以提高例如:
raise msg1 if ...
raise msg2 if ...
我的問題是如何與測試例外的msg1,msg2與RSpec的異常消息。
describe SomeClass do
let(:some_object) { described_class.new }
it 'should raise an exception' do
some_object.some_method('param').should raise_error(ExceptionClass, "exception_message")
end
end
如果raise "message"
那麼ExceptionClass
將是RuntimeClass
實例。
IMO最好提出特定類型的異常,而不是依靠消息。
謝謝。它將raise信息傳遞給raise_error的最後一個參數。不過,我已經編輯了你的答案,完全符合要求。 –