如何阻止 VCR 覆盖盒式磁带中的 erb
我们最近开始使用 VCR 在我们的 Cucumber 测试中存根请求。我们使用 cucumber 表来描述不同类型的请求,并使用 gherkin 将它们存储为变量。我们的盒式磁带文件都已重新设计以包含 erb,以便我们可以替换要测试的请求的值。
问题是,每当有新请求时,VCR 都会记录新请求,并覆盖(删除)磁带中的所有 erb,将其替换为该示例中插入的请求。每次我们运行值发生更改的请求(例如,我们从正在对话的 API 收到的时间戳值)时,所有 erb 都需要复制回卡带文件中。这很令人沮丧,因为测试一直在运行。
有谁知道为什么 VCR 在录制新回复时会去掉 erb ?有什么解决方法吗?有什么方法可以在插值之前保存模板吗?
We've recently started using VCR to stub requests in our cucumber tests. We're using cucumber tables to describe different kinds of requests, and storing them as variables with gherkin. Our cassette files have all been reworked to include erb, so that we can substitute in the values for the request we want to test.
The problem is that whenever there is a new request, VCR records the new requests and also overwrites (removes) all the erb from the cassette, replacing it with the request as interpolated for that example. Every time we run requests where a value has changed (say, the value of the timestamp we receive from the API we're talking to), all the erb needs to be copied back in to the cassette file. This is frustrating, since tests are run all the time.
Does anyone know why VCR strips the erb out when recording new responses? Any idea of a workaround? Is there any way to save back a template before it's interpolated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自动将对盒式磁带的手动更改与新录制的盒式磁带合并是一个难题,在我看来,最好留给专门设计用于处理文本文档历史记录并管理它们合并的工具(即源代码控制系统) 。 ERB 让它变得更加困难:虽然您可能只是使用 ERB 来插入变量,但可以使用任何有效的 ruby。 ERB 中可能存在循环、条件等。 VCR 没有办法自动合并这些东西。
一些建议:
:once
记录模式(最近的默认设置)可防止现有磁带被覆盖。
之类的字符串来代替密码。 VCR 在录制磁带时会自动插入占位符文本,并在播放时将其替换为正确的实际值。如果这些东西不能满足您的需求,我当然愿意接受如何改进 VCR 的想法。
Automatically merging your manual changes to the cassette with a newly recorded cassette is a difficult problem that, in my opinion, is best left to tools that are specifically designed to handle the history of text documents and manage merging them (i.e. your source control system). ERB makes it even more difficult: while you may just be using ERB to interpolate variables, any valid ruby can be used. There may be loops, conditionals and more in the ERB. There's no way for VCR to automatically merge this stuff.
A couple suggestions:
:once
record mode (the recent default) to prevent existing cassettes from being overriden.<PASSWORD>
to take the place of a password, for example. VCR automatically takes care of inserting the placeholder text when it records the cassette, and replacing it with the correct real value on playback.I'm certainly open to ideas for how to improve VCR if these things don't meet your needs.