Are there any testing tools included with this library? I'd like to test my application code without making actual requests to Google; the only way I can think of doing this is to use webmock to mock out requests that Google Api Client makes.
:+1: Same here
Any suggestions for this? I would find advice on this very helpful.
A coworker reached out to me about this today, so I'm commenting and closing out this issue. It's been over a year since I last worked with this library, but I have some suggestions--keep in mind they're just my opinion.
For any methods provided by the GoogleApiRubyClient gem that you'll be consuming, I recommend writing your own wrapper methods so that you can mock out this library's behavior. Use this strategy for most of your application unit and integration testing.
Benefits:
Write a small subset of your tests to make calls to Google. Set up test accounts as necessary for this. Use a tool like VCR to capture and refresh your API fixtures on a regular basis (i.e. monthly, every 3 months, etc).
Benefits:
Drawbacks:
Don't treat any of this as gospel. If the suggestions above don't make sense to you, don't use them. Go out and build stuff :)
In addition you can generate google api model objects:
person = Google::Apis::PeopleV1::Person::Representation.new(Google::Apis::PeopleV1::Person.new).from_json(body, unwrap: Google::Apis::PeopleV1::Person)
where body is json string like this:
{
"resourceName": "people/114528407945569518008",
"etag": "%EgoBAj0DCAk+CjcuGgwBAgMEBQYHCAkKCwwiDFVjcjlBeHF==",
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "114528407945569518"
}
},
"displayName": "Test Testov",
"familyName": "Testov",
"givenName": "Test",
"displayNameLastFirst": "Testov, Test"
}
]
}
You can create some json files with test data, load them with File.read and test your business logic
Most helpful comment
A coworker reached out to me about this today, so I'm commenting and closing out this issue. It's been over a year since I last worked with this library, but I have some suggestions--keep in mind they're just my opinion.
For any methods provided by the GoogleApiRubyClient gem that you'll be consuming, I recommend writing your own wrapper methods so that you can mock out this library's behavior. Use this strategy for most of your application unit and integration testing.
Benefits:
Write a small subset of your tests to make calls to Google. Set up test accounts as necessary for this. Use a tool like VCR to capture and refresh your API fixtures on a regular basis (i.e. monthly, every 3 months, etc).
Benefits:
Drawbacks:
Don't treat any of this as gospel. If the suggestions above don't make sense to you, don't use them. Go out and build stuff :)