Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vcr to stub ViewPoint gem returns Unauthorize response from ews API

I am stubbing all requests that go through the ViewPoint gem. Using the 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

connection.client returns a new ViewPoint connection.

The response i get back from the gem is: Viewpoint::EWS::Errors::UnauthorizedResponseError which equates to a 401 unauthorised code from the ews api.

I found this issue: https://github.com/vcr/vcr/issues/297

It is exactly the same problem I am having, but it is 3 years old and with no solution. All of my other google foo has turned up nothing.

Digging into the viewpoint gem, I can't find any difference between the request objects apart from: HTTPClient and WebMockHTTPClient which is to be expected.

like image 709
DickieBoy Avatar asked Sep 15 '16 15:09

DickieBoy


1 Answers

ViewPoint is using HTTPClient for its connection, so you need to configure VCR to use hook into :webmock and stub your requests.

like image 106
obenda Avatar answered Oct 07 '22 14:10

obenda