tests: refactor MockUrlFetcher to use files
Opened this issue · 2 comments
nokome commented
The MockUrlFetcher
maps URLs to an Object
representing the expected JSON response.
Currently, adding a new URL requires adding a new method/if statement to the code. Instead, we could have a folder called tests/mockUrls
with files like http-crandb.r-pkg.org-gsl.json
with the expected JSON content. MockUrlFetcher
would then just look for a file matching the URL and return a 404 if no match was found. That would make it easier to add/update the expected JSON as we add new fixtured e.g.
curl http://crandb.r-pkg.org/gsl > tests/mockUrls/http-crandb.r-pkg.org-gsl.json
beneboy commented
This is a good idea. I did this for the NPM information but in the interest of getting the tests fixed quickly I reverted to the if-statement approach.