{"action":"created","comment":{"url":"https://api.github.com/repos/platanus/blog/pulls/comments/46835324","id":46835324,"diff_hunk":"@@ -0,0 +1,103 @@\n+---\n+layout: post\n+title: ¿Cómo probamos las APIs de terceros?\n+author: arturopuente\n+tags:\n+  - rails\n+  - testing\n+  - api\n+  - third-party\n+---\n+\n+Un problema común que nos encontramos al testear nuestras aplicaciones es la integración con servicios de terceros.\n+\n+Enviar los requests a las APIs de terceros en cada test tiene varios problemas:\n+\n+- Nos topamos con el límite de requests en un determinado tiempo\n+- Los tests pueden fallar por problemas de conexión\n+- La suite de pruebas demora **mucho**\n+\n+Hay gemas que nos ayudan que nuestras pruebas funcionen mejor, por ejemplo:\n+\n+- **[Webmock](https://github.com/bblimke/webmock)** desactiva los requests a cualquier servicio externo e ir devolviendo respuestas predeterminadas por cada URL.\n+\n+- **[VCR](https://github.com/vcr/vcr)** ejecuta nuestros tests una vez contra los servicios reales y guarda las respuestas en un JSON (cassettes), de forma que la siguiente vez que la suite se ejecute ese JSON servirá para mockear la respuesta del servidor.\n+\n+Sin embargo, todas estas gemas añaden una capa de complejidad a nuestra suite:\n+\n+- Con Webmock si queremos que hacer requests a un servicio de terceros en una prueba tenemos que manejar manualmente la activación/desactivación de los requests externos\n+\n+- Al usar VCR tenemos que manejar los cassettes y como contienen toda la interacción entre los servidores, manipularlos y editarlos es más complejo y tedioso.\n+\n+¿Qué alternativa tenemos entonces? Me parece que la respuesta está en usar RSpec hasta que la complejidad de nuestra suite nos obligue a buscar una gema adicional, así evitamos añadir una dependencia más y evitamos los problemas/workarounds que las otras gemas traen consigo.\n+\n+## Usando RSpec para mockear servicios externos","path":"_drafts/testing-third-party-apis.md","position":34,"original_position":34,"commit_id":"c314500162709089e553c9ddf0543ecd3c240a35","original_commit_id":"c314500162709089e553c9ddf0543ecd3c240a35","user":{"login":"juliogarciag","id":362584,"avatar_url":"https://avatars.githubusercontent.com/u/362584?v=3","gravatar_id":"","url":"https://api.github.com/users/juliogarciag","html_url":"https://github.com/juliogarciag","followers_url":"https://api.github.com/users/juliogarciag/followers","following_url":"https://api.github.com/users/juliogarciag/following{/other_user}","gists_url":"https://api.github.com/users/juliogarciag/gists{/gist_id}","starred_url":"https://api.github.com/users/juliogarciag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliogarciag/subscriptions","organizations_url":"https://api.github.com/users/juliogarciag/orgs","repos_url":"https://api.github.com/users/juliogarciag/repos","events_url":"https://api.github.com/users/juliogarciag/events{/privacy}","received_events_url":"https://api.github.com/users/juliogarciag/received_events","type":"User","site_admin":false},"body":"No había escuchado nunca ese término pero me suena a la españolización del verbo inglés `mock`: `mock the service to...`, que es bastante usado en la literatura de tests. Quizás una buena traducción sería `simular`.","created_at":"2015-12-07T15:46:24Z","updated_at":"2015-12-07T15:46:24Z","html_url":"https://github.com/platanus/blog/pull/57#discussion_r46835324","pull_request_url":"https://api.github.com/repos/platanus/blog/pulls/57","_links":{"self":{"href":"https://api.github.com/repos/platanus/blog/pulls/comments/46835324"},"html":{"href":"https://github.com/platanus/blog/pull/57#discussion_r46835324"},"pull_request":{"href":"https://api.github.com/repos/platanus/blog/pulls/57"}}},"pull_request":{"url":"https://api.github.com/repos/platanus/blog/pulls/57","id":52845821,"html_url":"https://github.com/platanus/blog/pull/57","diff_url":"https://github.com/platanus/blog/pull/57.diff","patch_url":"https://github.com/platanus/blog/pull/57.patch","issue_url":"https://api.github.com/repos/platanus/blog/issues/57","number":57,"state":"open","locked":false,"title":"feat(blog): Add testing third party apis draft","user":{"login":"arturopuente","id":95116,"avatar_url":"https://avatars.githubusercontent.com/u/95116?v=3","gravatar_id":"","url":"https://api.github.com/users/arturopuente","html_url":"https://github.com/arturopuente","followers_url":"https://api.github.com/users/arturopuente/followers","following_url":"https://api.github.com/users/arturopuente/following{/other_user}","gists_url":"https://api.github.com/users/arturopuente/gists{/gist_id}","starred_url":"https://api.github.com/users/arturopuente/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arturopuente/subscriptions","organizations_url":"https://api.github.com/users/arturopuente/orgs","repos_url":"https://api.github.com/users/arturopuente/repos","events_url":"https://api.github.com/users/arturopuente/events{/privacy}","received_events_url":"https://api.github.com/users/arturopuente/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-07T13:44:05Z","updated_at":"2015-12-07T15:46:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8868af3cea782933d0f4ddaf94c94ffe57f5602a","assignee":{"login":"juliogarciag","id":362584,"avatar_url":"https://avatars.githubusercontent.com/u/362584?v=3","gravatar_id":"","url":"https://api.github.com/users/juliogarciag","html_url":"https://github.com/juliogarciag","followers_url":"https://api.github.com/users/juliogarciag/followers","following_url":"https://api.github.com/users/juliogarciag/following{/other_user}","gists_url":"https://api.github.com/users/juliogarciag/gists{/gist_id}","starred_url":"https://api.github.com/users/juliogarciag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliogarciag/subscriptions","organizations_url":"https://api.github.com/users/juliogarciag/orgs","repos_url":"https://api.github.com/users/juliogarciag/repos","events_url":"https://api.github.com/users/juliogarciag/events{/privacy}","received_events_url":"https://api.github.com/users/juliogarciag/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/platanus/blog/pulls/57/commits","review_comments_url":"https://api.github.com/repos/platanus/blog/pulls/57/comments","review_comment_url":"https://api.github.com/repos/platanus/blog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/platanus/blog/issues/57/comments","statuses_url":"https://api.github.com/repos/platanus/blog/statuses/c314500162709089e553c9ddf0543ecd3c240a35","head":{"label":"platanus:testing-third-party-apis","ref":"testing-third-party-apis","sha":"c314500162709089e553c9ddf0543ecd3c240a35","user":{"login":"platanus","id":1158740,"avatar_url":"https://avatars.githubusercontent.com/u/1158740?v=3","gravatar_id":"","url":"https://api.github.com/users/platanus","html_url":"https://github.com/platanus","followers_url":"https://api.github.com/users/platanus/followers","following_url":"https://api.github.com/users/platanus/following{/other_user}","gists_url":"https://api.github.com/users/platanus/gists{/gist_id}","starred_url":"https://api.github.com/users/platanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/platanus/subscriptions","organizations_url":"https://api.github.com/users/platanus/orgs","repos_url":"https://api.github.com/users/platanus/repos","events_url":"https://api.github.com/users/platanus/events{/privacy}","received_events_url":"https://api.github.com/users/platanus/received_events","type":"Organization","site_admin":false},"repo":{"id":9174344,"name":"blog","full_name":"platanus/blog","owner":{"login":"platanus","id":1158740,"avatar_url":"https://avatars.githubusercontent.com/u/1158740?v=3","gravatar_id":"","url":"https://api.github.com/users/platanus","html_url":"https://github.com/platanus","followers_url":"https://api.github.com/users/platanus/followers","following_url":"https://api.github.com/users/platanus/following{/other_user}","gists_url":"https://api.github.com/users/platanus/gists{/gist_id}","starred_url":"https://api.github.com/users/platanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/platanus/subscriptions","organizations_url":"https://api.github.com/users/platanus/orgs","repos_url":"https://api.github.com/users/platanus/repos","events_url":"https://api.github.com/users/platanus/events{/privacy}","received_events_url":"https://api.github.com/users/platanus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/platanus/blog","description":"Jekyll based blog","fork":false,"url":"https://api.github.com/repos/platanus/blog","forks_url":"https://api.github.com/repos/platanus/blog/forks","keys_url":"https://api.github.com/repos/platanus/blog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/platanus/blog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/platanus/blog/teams","hooks_url":"https://api.github.com/repos/platanus/blog/hooks","issue_events_url":"https://api.github.com/repos/platanus/blog/issues/events{/number}","events_url":"https://api.github.com/repos/platanus/blog/events","assignees_url":"https://api.github.com/repos/platanus/blog/assignees{/user}","branches_url":"https://api.github.com/repos/platanus/blog/branches{/branch}","tags_url":"https://api.github.com/repos/platanus/blog/tags","blobs_url":"https://api.github.com/repos/platanus/blog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/platanus/blog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/platanus/blog/git/refs{/sha}","trees_url":"https://api.github.com/repos/platanus/blog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/platanus/blog/statuses/{sha}","languages_url":"https://api.github.com/repos/platanus/blog/languages","stargazers_url":"https://api.github.com/repos/platanus/blog/stargazers","contributors_url":"https://api.github.com/repos/platanus/blog/contributors","subscribers_url":"https://api.github.com/repos/platanus/blog/subscribers","subscription_url":"https://api.github.com/repos/platanus/blog/subscription","commits_url":"https://api.github.com/repos/platanus/blog/commits{/sha}","git_commits_url":"https://api.github.com/repos/platanus/blog/git/commits{/sha}","comments_url":"https://api.github.com/repos/platanus/blog/comments{/number}","issue_comment_url":"https://api.github.com/repos/platanus/blog/issues/comments{/number}","contents_url":"https://api.github.com/repos/platanus/blog/contents/{+path}","compare_url":"https://api.github.com/repos/platanus/blog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/platanus/blog/merges","archive_url":"https://api.github.com/repos/platanus/blog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/platanus/blog/downloads","issues_url":"https://api.github.com/repos/platanus/blog/issues{/number}","pulls_url":"https://api.github.com/repos/platanus/blog/pulls{/number}","milestones_url":"https://api.github.com/repos/platanus/blog/milestones{/number}","notifications_url":"https://api.github.com/repos/platanus/blog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/platanus/blog/labels{/name}","releases_url":"https://api.github.com/repos/platanus/blog/releases{/id}","created_at":"2013-04-02T16:15:04Z","updated_at":"2015-08-26T20:32:52Z","pushed_at":"2015-12-07T15:38:48Z","git_url":"git://github.com/platanus/blog.git","ssh_url":"git@github.com:platanus/blog.git","clone_url":"https://github.com/platanus/blog.git","svn_url":"https://github.com/platanus/blog","homepage":null,"size":8115,"stargazers_count":5,"watchers_count":5,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":9,"forks":1,"open_issues":9,"watchers":5,"default_branch":"master"}},"base":{"label":"platanus:master","ref":"master","sha":"74b2fadd3ba21c7bc07d88368a8e459f8553b739","user":{"login":"platanus","id":1158740,"avatar_url":"https://avatars.githubusercontent.com/u/1158740?v=3","gravatar_id":"","url":"https://api.github.com/users/platanus","html_url":"https://github.com/platanus","followers_url":"https://api.github.com/users/platanus/followers","following_url":"https://api.github.com/users/platanus/following{/other_user}","gists_url":"https://api.github.com/users/platanus/gists{/gist_id}","starred_url":"https://api.github.com/users/platanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/platanus/subscriptions","organizations_url":"https://api.github.com/users/platanus/orgs","repos_url":"https://api.github.com/users/platanus/repos","events_url":"https://api.github.com/users/platanus/events{/privacy}","received_events_url":"https://api.github.com/users/platanus/received_events","type":"Organization","site_admin":false},"repo":{"id":9174344,"name":"blog","full_name":"platanus/blog","owner":{"login":"platanus","id":1158740,"avatar_url":"https://avatars.githubusercontent.com/u/1158740?v=3","gravatar_id":"","url":"https://api.github.com/users/platanus","html_url":"https://github.com/platanus","followers_url":"https://api.github.com/users/platanus/followers","following_url":"https://api.github.com/users/platanus/following{/other_user}","gists_url":"https://api.github.com/users/platanus/gists{/gist_id}","starred_url":"https://api.github.com/users/platanus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/platanus/subscriptions","organizations_url":"https://api.github.com/users/platanus/orgs","repos_url":"https://api.github.com/users/platanus/repos","events_url":"https://api.github.com/users/platanus/events{/privacy}","received_events_url":"https://api.github.com/users/platanus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/platanus/blog","description":"Jekyll based blog","fork":false,"url":"https://api.github.com/repos/platanus/blog","forks_url":"https://api.github.com/repos/platanus/blog/forks","keys_url":"https://api.github.com/repos/platanus/blog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/platanus/blog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/platanus/blog/teams","hooks_url":"https://api.github.com/repos/platanus/blog/hooks","issue_events_url":"https://api.github.com/repos/platanus/blog/issues/events{/number}","events_url":"https://api.github.com/repos/platanus/blog/events","assignees_url":"https://api.github.com/repos/platanus/blog/assignees{/user}","branches_url":"https://api.github.com/repos/platanus/blog/branches{/branch}","tags_url":"https://api.github.com/repos/platanus/blog/tags","blobs_url":"https://api.github.com/repos/platanus/blog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/platanus/blog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/platanus/blog/git/refs{/sha}","trees_url":"https://api.github.com/repos/platanus/blog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/platanus/blog/statuses/{sha}","languages_url":"https://api.github.com/repos/platanus/blog/languages","stargazers_url":"https://api.github.com/repos/platanus/blog/stargazers","contributors_url":"https://api.github.com/repos/platanus/blog/contributors","subscribers_url":"https://api.github.com/repos/platanus/blog/subscribers","subscription_url":"https://api.github.com/repos/platanus/blog/subscription","commits_url":"https://api.github.com/repos/platanus/blog/commits{/sha}","git_commits_url":"https://api.github.com/repos/platanus/blog/git/commits{/sha}","comments_url":"https://api.github.com/repos/platanus/blog/comments{/number}","issue_comment_url":"https://api.github.com/repos/platanus/blog/issues/comments{/number}","contents_url":"https://api.github.com/repos/platanus/blog/contents/{+path}","compare_url":"https://api.github.com/repos/platanus/blog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/platanus/blog/merges","archive_url":"https://api.github.com/repos/platanus/blog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/platanus/blog/downloads","issues_url":"https://api.github.com/repos/platanus/blog/issues{/number}","pulls_url":"https://api.github.com/repos/platanus/blog/pulls{/number}","milestones_url":"https://api.github.com/repos/platanus/blog/milestones{/number}","notifications_url":"https://api.github.com/repos/platanus/blog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/platanus/blog/labels{/name}","releases_url":"https://api.github.com/repos/platanus/blog/releases{/id}","created_at":"2013-04-02T16:15:04Z","updated_at":"2015-08-26T20:32:52Z","pushed_at":"2015-12-07T15:38:48Z","git_url":"git://github.com/platanus/blog.git","ssh_url":"git@github.com:platanus/blog.git","clone_url":"https://github.com/platanus/blog.git","svn_url":"https://github.com/platanus/blog","homepage":null,"size":8115,"stargazers_count":5,"watchers_count":5,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":9,"forks":1,"open_issues":9,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/platanus/blog/pulls/57"},"html":{"href":"https://github.com/platanus/blog/pull/57"},"issue":{"href":"https://api.github.com/repos/platanus/blog/issues/57"},"comments":{"href":"https://api.github.com/repos/platanus/blog/issues/57/comments"},"review_comments":{"href":"https://api.github.com/repos/platanus/blog/pulls/57/comments"},"review_comment":{"href":"https://api.github.com/repos/platanus/blog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/platanus/blog/pulls/57/commits"},"statuses":{"href":"https://api.github.com/repos/platanus/blog/statuses/c314500162709089e553c9ddf0543ecd3c240a35"}}}}