【发布时间】:2014-09-24 18:54:54
【问题描述】:
我有这段代码要测试:
def error_from_exception(ex)
if ex.is_a?(ActiveRecord::RecordInvalid)
...
要进入 if 块,我需要传入正确的 ex 参数。
如何创建 ActiveRecord::RecordInvalid?
使用 rspec,我正在尝试做这样的事情:
context 'exception is ActiveRecord::RecordInvalid' do
it 'returns the validation error' do
begin
raise ActiveRecord::RecordInvalid
rescue Exception => ex
binding.pry
###
# From my pry session:
# $ ex
# $ <ArgumentError: wrong number of arguments (0 for 1)>
# $ ex.class
# $ ArgumentError < StandardError
###
end
end
end
如何找出库正在寻找的参数类型?
【问题讨论】:
标签: ruby-on-rails activerecord rspec