我的规格会在主分支中通过。如果我创建一个新的分支,并修改一些与订阅完全不相关的代码,它们将失败,并显示以下消息。我能让它们通过的唯一方法就是把我的vcr.rb改成:record => :new_episodes。
如果我保留该选项,那么几乎每次运行我的规范时,我都会有新的修改过的磁带数据文件,这些数据文件最终会被提交,这真的会稀释Git的日志。
对如何处理这个问题有什么建议吗?break的许多规范都基于这个匹配器:
describe "#change_plan_to", vcr: {match_requests_on: [:method, :uri, :body]} do这个匹配器是不是太容易改变了?我不能让规范以任何其他方式通过条带api调用。
Failure/Error: @subscription.create_stripe_customer
VCR::Errors::UnhandledHTTPRequestError:
================================================================================
An HTTP request has been made that VCR does not know how to handle:
POST https://api.stripe.com/v1/customers
VCR is currently using the following cassette:
- /Users/app/spec/data/Subscription/_change_plan_to/stripe_customer_subscription_plan_/name/.json
- :record => :once
- :match_requests_on => [:method, :uri, :body]
Under the current configuration VCR can not find a suitable HTTP interaction
to replay and is prevented from recording new requests. There are a few ways
you can deal with this:
* If you're surprised VCR is raising this error
and want insight about how VCR attempted to handle the request,
you can use the debug_logger configuration option to log more details [1].
* You can use the :new_episodes record mode to allow VCR to
record this new request to the existing cassette [2].
* If you want VCR to ignore this request (and others like it), you can
set an `ignore_request` callback [3].
* The current record mode (:once) does not allow new requests to be recorded
to a previously recorded cassette. You can delete the cassette file and re-run
your tests to allow the cassette to be recorded with this request [4].
* The cassette contains 109 HTTP interactions that have not been
played back. If your request is non-deterministic, you may need to
change your :match_requests_on cassette option to be more lenient
or use a custom request matcher to allow it to match [5].
[1] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/configuration/debug-logging
[2] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/record-modes/new-episodes
[3] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/configuration/ignore-request
[4] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/record-modes/once
[5] https://www.relishapp.com/vcr/vcr/v/2-5-0/docs/request-matching
================================================================================
# ./app/models/subscription.rb:83:in `create_stripe_customer'
# ./spec/models/subscription_spec.rb:68:in `block (3 levels) in <top (required)>'
# -e:1:in `<main>'我想出了更多。只有当我向堆栈中添加新的等级库时,等级库才会中断。当更多的东西添加到套件中时,它们怎么会断掉呢?
发布于 2013-07-24 23:41:31
您看到的行为表明,用于匹配请求的属性之一是不确定的,并且在每次运行测试时都会发生变化。您提到使用match_requests_on: [:method, :uri, :body]选项--我猜是body。请记住,录像机内置的body matcher会进行直接的body_string == body_string比较,很容易出现body在语义上相同但字符串不同的情况。例如,像{"a": 1", "b": 2}和{"b": 2, "a": 1}这样的JSON字符串。
我的建议是根本不匹配body:如果您在某些情况下需要它,它就在那里,但是如果您更宽松地匹配,VCR通常可以很好地工作,因为它以最初发生的顺序记录HTTP交互,然后在回放期间,它会回放第一个未使用的匹配交互--如果您的测试以最初的顺序发出请求,则会为每个请求回放正确的响应。
为了更深入地了解到底发生了什么,您可以使用debug logger选项,该选项将在它尝试匹配时为您提供详细的输出,以显示它为什么要这样做。
https://stackoverflow.com/questions/17822820
复制相似问题