around
,我可以检查
example.exception
是否设置为预期值,但是我在文档中没有找到任何“重置”的任何地方,因此可以将测试标记为成功
RSpec.describe(Example, type: :interactor) do
around do |example|
example.run
expect(example.exception).to be_a(ValidateOutput::Error)
end
it "is included with metadata" do
output
end
end
试图期望发生错误只是为同一测试造成第二个错误:
RSpec.describe(Example, type: :interactor) do
around do |example|
expect do
example.run
end.to raise_error(ValidateOutput::Error)
end
it "is included with metadata" do
output
end
end
我怎么能告诉RSPEC,这应该通过,因为我期望错误?
在搜索并完成对本网站的询问进行正式查询的工作后,我找到了解决方案。
使用专用方法并分别测试此方法是第一步(因此您知道该方法按预期起作用)。
如果您想确保它被称为,那么只需期望该方法被调用self
:
RSpec.describe(Example, type: :interactor) do
it "executes validate_output! with matching metadata" do
expect(self).to receive(:validate_output!)
output
end
end