[英]RSpec/AnyInstance: Avoid stubbing using allow_any_instance_of problem
帮我。 我不明白如何解决它。 我尝试了很多变化......
describe '.perform' do
it 'correctly parse response' do
driver = described_class.new(dot_application, background_check_type, provider_setting).perform
expect(driver).to be_instance_of(BackgroundCheck)
expect(driver).to have_attributes(status: 'inprogress', background_check_type_id: 4)
end
context 'when exception when status is Error' do
before { allow_any_instance_of(described_class).to receive(:driver_iq_api).and_return('https://test/error') }
it 'returns error message' do
expect { described_class.new(dot_application, background_check_type, provider_setting).perform }.
to raise_error(RuntimeError)
end
end
end
错误:RSpec/AnyInstance:避免使用allow_any_instance_of 进行存根。 之前 { allow_any_instance_of(描述的类)。接收(:driver_iq_api)。and_return(' https://test/error ')}
你有你的一个非常具体的实例described_class
您可以存根:
context 'when exception when status is Error' do
let(:subject) do
described_class.new(dot_application, background_check_type, provider_setting)
end
before do
allow(subject).to receive(:driver_iq_api).and_return('https://test/error')
end
it 'returns error message' do
expect { subject.perform }.to raise_error(RuntimeError)
end
end
假设perform
引发错误,而不是初始化实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.