【发布时间】:2015-11-13 10:26:50
【问题描述】:
我有一个处理某些 api 调用失败的方法。我为它写了测试:
it 'logs the error' do
expect(Rails.logger).to receive(:error).with(/Failed API call/i)
expect(Rails.logger).to receive(:error).with(/#{error_type}/)
expect(Rails.logger).to receive(:error).with(/#{server_error}/)
subject
end
但要使其正常工作,我需要进行 3 个 api 调用或将其拆分为 3 个测试用例。我不喜欢这两种解决方案。我认为最好的方法是将 3 个正则表达式组合成一个期望。
是否可以在一个测试用例中将多个正则表达式放在单个参数上?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 rspec shoulda