Mocking methods in google ruby api client
Asked Answered
P

2

6

I am trying to mock some methods that use the google-api-ruby-client to make some testing without actually calling the api. Authentication and client and activities methods are taken from the example found on the github page (see link above), which is why I skipped it here.

The method from the example is the following:

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

I previously tried to stub the client (even chained with the execute) methods, however this results in authorization requests for oauth, which the gem uses underneath followed by mocks for the plus.activities.list methods. Is there a way to directly mock client.exectute to return something useful while skipping the whole chain?

Perfunctory answered 3/6, 2013 at 15:18 Comment(1)
Chris did you ever figure this issue out?Hildebrand
F
0

I am not sure that I understand your problem correctly, but maybe something a little bit crazy will work

I assume that your method is in Client model so maybe something like that will work

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

Of course if you model have different name you have to adjust. I am not sure but you can give it a try

Futch answered 3/6, 2013 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.