我有一个类翻译器,它调用了类连接器。Connector类确实请求外部API,希望使用VCR记录此API操作,然后使用Connector类的存根实例,并在call Translator中返回API操作的VCR响应。
class Translator
def initialize
@obj = Connector.new().connect
end
def format
# use obj here for some logic
end
end
class Connector
def connect
# http request to external API
end
end
RSpec.describe Translator, type: :services do
before do
allow_any_instance_of(Connector).to receive(:connect).and_return(VCR recorded response)
end
endhttps://stackoverflow.com/questions/51280111
复制相似问题