Mocking methods in google ruby ​​api client

I am trying to make fun of some methods that google-api-ruby-client use to do some testing without actually calling the api. The authentication methods of both the client and the actions are taken from the example found on the github page (see Link above), so I skipped it here.

The method from the example is as follows:

def activities result = client.execute( :api_method => plus.activities.list, :parameters => {'collection' => 'public', 'userId' => 'me'} ) return result.data end 

I previously tried to drown out client methods (even chained to execution), however this leads to authorization requests for oauth that uses the gem under them, followed by mocks for plus.activities.list methods. Is there a way to directly mock client.exectute in order to return something useful by skipping the whole chain?

+4
source share
2 answers

I'm not sure I understand your problem correctly, but maybe something a little crazy will work.

I assume your method is in the client model, so something like this might work

 Client.stub_chain(:client, :execute).and_return(true) 

Of course, if you have a different name, you need to customize. I'm not sure, but you can try to try.

0
source

Source: https://habr.com/ru/post/1484226/


All Articles