You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But I'm unable to do this as the current version is not loading the Hubspot::Crm::Contacts::BasicApi constant automatically. Well, I've added my own requires into the spec/spec_helper.rb file as follows:
require'hubspot/helpers/get_all_helper'# I don't even know why but without this require the spec won't workrequire'hubspot/codegen/crm/contacts/api/basic_api'
Still no luck as this code would load a Hubspot::Discovery::Crm::Contacts::BasicApi constant and fill it with methods in real-time but by that point the Hubspot::Crm::Contacts::BasicApi (from the codegen folder) would be already altered by my mock which leads to an error in the BaseApiClient#define_api_methods.
@client=Hubspot::Client.new(access_token: access_token)base_api=@client.crm.contacts.basic_apibase_api.get_by_id(contact_id: user.hubspot_id)# cannot load such file -- hubspot/codegen/crm/contacts/models/args
What if we would require the discovery module and mock the Hubspot::Discovery::Crm::Contacts::BasicApi?
require'hubspot/discovery/crm/contacts/api/basic_api'expect_any_instance_of(Hubspot::Discovery::Crm::Contacts::BasicApi).toreceive(:get_by_id).with(contact_id: hubspot_id).and_return(OpenStruct.new({id: hubspot_id}))# Hubspot::Discovery::Crm::Contacts::BasicApi does not implement #get_by_id
Well because of this requiring the module loaded it doesn't have any methods! As they are all generated real-time when a BasicApi instance is created. There is no method to stub unless there is an instance present.
I don't even know how to do this anymore
The text was updated successfully, but these errors were encountered:
I've got an idea to stub Hubspot::Discovery::Crm::Contacts::BasicApi.new to an exact instance and maybe mock it's methods instead.
require'hubspot/helpers/get_all_helper'require'hubspot/discovery/crm/contacts/api/basic_api'Hubspot::Discovery::Crm::Contacts::BasicApi.new({access_token: '123123123123'}).get_by_id# cannot load such file -- hubspot/codegen/crm/contacts/models/contact_id (LoadError)
As the BaseApiClient#define_api_methods check for the method in a codegen class it's reasonable it would check the Hubspot::Crm::Contacts::BasicApi#get_by_id method. And it's definition (def get_by_id(contact_id, opts = {})) shows us that it will search for a contact_id.rb in a models folder. And of course there is no such file. I don't even know how that is supposed to work.
I'll probably downgrade for now as it's a mess to test. I'm up for the dynamic reflective code (that's fun to program) but there it has too much drawbacks.
I would like to have an option to somehow preload all modules and classes in the test env and be able to stub class methods that would be there already. Thanks
For some my RSpec tests I've been mocking methods that call the API like so:
But I'm unable to do this as the current version is not loading the
Hubspot::Crm::Contacts::BasicApi
constant automatically. Well, I've added my own requires into thespec/spec_helper.rb
file as follows:Still no luck as this code would load a
Hubspot::Discovery::Crm::Contacts::BasicApi
constant and fill it with methods in real-time but by that point theHubspot::Crm::Contacts::BasicApi
(from the codegen folder) would be already altered by my mock which leads to an error in theBaseApiClient#define_api_methods
.What if we would require the discovery module and mock the
Hubspot::Discovery::Crm::Contacts::BasicApi
?Well because of this requiring the module loaded it doesn't have any methods! As they are all generated real-time when a BasicApi instance is created. There is no method to stub unless there is an instance present.
I don't even know how to do this anymore
The text was updated successfully, but these errors were encountered: