Skip to content
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 · Fixed by #390
Closed

Logical not quite right for install_github_single #388

hadley opened this issue Dec 2, 2013 · 4 comments · Fixed by #390

Comments

@hadley
Copy link
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
Copy link
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
Copy link
Member Author

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
Copy link
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
Copy link
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.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants