New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logical not quite right for install_github_single #388

Closed
hadley opened this Issue Dec 2, 2013 · 4 comments

Comments

Projects
None yet
3 participants
@hadley
Member

hadley commented Dec 2, 2013

e.g. install_github("hadley/ggplot2#878") fails with "Must specify either a ref or a pull request".

Can you take a look @krlmlr?

@krlmlr

This comment has been minimized.

Member

krlmlr commented Dec 2, 2013

That's what I get for not testing it... A fix is just being tested by Travis.

@hadley: I need to mock github_pull_info for a unit test. I have a hack, but I was wondering if there are any recommended techniques. A StackOverflow search for [testthat] mock returned no results, and a post to R-devel hasn't been answered.

@hadley

This comment has been minimized.

Member

hadley commented Dec 2, 2013

Don't know of any mocking frameworks in R, sorry :/ Not even sure how you'd attack the problem - I guess you could temporarily functions in the right environment.

@wch

This comment has been minimized.

Member

wch commented Dec 2, 2013

If I understand correctly, you want to put in a temporary replacement version of github_pull_info, because it's called by another function. Here's an idea for how to do this:

  • Create a new environment as a child of the namespace
  • Copy the function(s) to be tested into the new environment, and set their environment to the new environment.
  • Define the mock function (github_pull_info) in that environment
  • Call the functions that you want to test

There are some limitations of doing it this way. If you want to call the mock function indirectly (via another function that's not copied to the new environment), it won't work right. To get around this issue, you could copy over everything from the namespace into the new environment, and simply replace the mocked function, but this could be slow if you're running a lot of tests.

All of this is overkill for this one test, but it's a way you could do mocking in general.

@krlmlr

This comment has been minimized.

Member

krlmlr commented Dec 2, 2013

@wch: Thanks for the writeup. Perhaps one day... For now, I hope my hack will do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.