本文介绍了VCR 不生成 yml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RSpec 测试运行成功,但录像机没有生成 yml 文件.

RSpec test runs successfully, but VCR doesn't generate yml file.

spec/spec_helper.rb

require 'vcr'

VCR.configure do |c|
  c.cassette_library_dir     = 'spec/cassettes'
  c.hook_into :typhoeus
  # c.ignore_localhost         = false
  # c.default_cassette_options = { :record => :new_episodes }
end

spec/smoothPayApi_spec.rb

require 'smoothPayApi'
require 'spec_helper'

describe SmoothPayApi do

    before :each do
        @item = SmoothPayApi.new
        @token = ''
    end

    describe "#getToken" do

        # use_vcr_cassette

        it "gets token by calling gen_token_test" do
            VCR.use_cassette 'api/getToken' do

                return_info = @item.getToken('X3r82l89', 1)
                expect(return_info.message).to eq('success')
                @token = return_info.data

            end
        end
    end
end

SmoothPayApi::getToken 使用 Net::HTTP::Post.

SmoothPayApi::getToken uses Net::HTTP::Post.

我在本地主机上做这个测试.是不是有问题?

I do this test in localhost. Is it the problem?

推荐答案

听起来您没有使用 Typhoeus 来发出 HTTP 请求,但您正在使用 VCR 挂钩.您需要将 VCR 挂接到一个可以拦截您发出的请求的库中.VCR 文档 有一个列表.基于此声明:

It sounds like you aren't using Typhoeus to make your HTTP requests but you are having VCR hook into it. You need to have VCR hook into a library that can intercept the requests you are making. The VCR docs have a list. Based on this statement:

SmoothPayApi::getToken 使用 Net::HTTP::Post.

...听起来您想使用 hook_into :webmock 而不是 hook_into :typhoeus.

...it sounds like you want to use hook_into :webmock rather than hook_into :typhoeus.

这篇关于VCR 不生成 yml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:05