当我必须在RSPEC中更改方法时,如何检测时间?
假设我有以下代码。
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中更改方法时,该如何检测时间?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您,则必须使您的规格更具动态性,并且还必须测试
else
语句:下次您添加新的
type
,然后忘记要更新round_type
方法,最后一个规格将失败。If I understood you correctly, you have to make your specs a bit more dynamic and you have to test the
else
statement as well:Next time you add a new
type
and forget to updateround_type
method, the last spec will fail.https://relishapp.com/rspec/rspec-expectations/v/3-11/docs/built-in-matchers/raise-error-matcher