使用vcr存根ViewPoint gem返回取消授权来自ews API的响应

Dic*_*Boy 11 rspec ruby-on-rails exchangewebservices vcr viewpoint

我正在查看通过ViewPoint gem的所有请求.使用vcr gem.

require 'spec_helper'
require 'vcr'

describe CalendarImporters::Ews::Get do
  let(:conf_connection) { FactoryGirl.create(:conf_connection)}
  let(:calendar) { create(:calendar, :for_ews) }
  let(:connection) { Connections::Ews.new(conf_connection, calendar.ews_email) }

  it "works" do
    VCR.use_cassette("a/cassette") do
      connection.client.get_folder(:calendar)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

connection.client返回一个新ViewPoint连接.

我从gem返回的响应是:Viewpoint::EWS::Errors::UnauthorizedResponseError这相当于来自ews api的401未授权代码.

我发现了这个问题:https://github.com/vcr/vcr/issues/297

这是我遇到的完全相同的问题,但它已经3年了,没有解决方案.我所有的其他谷歌foo都没有发现.

深入研究视点宝石,我发现请求对象除了:HTTPClientWebMockHTTPClient预期之外没有任何区别.

obe*_*nda 1

ViewPoint 使用 HTTPClient 进行连接,因此您需要配置 VCR 以使用 hook into :webmock 并存根您的请求。