【发布时间】:2022-06-26 14:56:03
【问题描述】:
假设我有以下代码。
class Answer
enum type: %i[text checkbox image]
def round_type
case answer.type
when text, checkbox
:text
when image
:multimedia
else
raise 'Unknown type'
end
end
end
require 'rails_helper'
RSpec.describe Answer, type: :model do
describe '#round_type' do
context 'when type is text' do
it 'returns text' do
# omitted
end
end
context 'when type is checkbox' do
it 'returns text' do
end
end
context 'when type is image' do
it 'returns multimedia' do
end
end
end
end
然后我将视频类型添加到枚举中。当类型为视频时,我希望该方法返回多媒体。
但是 round_type 方法和测试代码不支持视频类型。所以当我在生产中遇到错误时,我最终会意识到这一点。
我想知道我必须在错误发生之前更改方法。
所以,这是我的问题:当我必须更改 rspec 中的方法时,如何检测时间?
【问题讨论】:
标签: ruby-on-rails unit-testing testing rspec