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

Eliminate #any_instance_of in logging specs #15058

Merged
merged 11 commits into from
Jul 5, 2017

Conversation

imtayadeway
Copy link
Contributor

@imtayadeway imtayadeway commented May 10, 2017

By mocking closer to the boundary (i.e. the $api_log itself) By injecting a StringIO into the $api_log and making expectations on it, we can decouple these tests from some implementation details that required us to use #any_instance_of. The result I think is greater confidence in these tests, greater visibility in what's being logged from the test body, and looser coupling between the test and its implementation, freeing us to refactor some of the logging later if needed. Also, by first stubbing the logger with allow .... to receive(:info), we no longer have to specify every message it receives, giving the tests greater readability. We also no longer required to specify every message that the logger receives (in the right order) - we can instead search through the log device to find only what is relevant to the example at hand. This also removes some constants from the example group which I know will make @kbrock happy 😁

@miq-bot add-label api, test, refactoring
@miq-bot assign @abellotti

@imtayadeway
Copy link
Contributor Author

Also customary ✂️ ✂️ ✂️

@chessbyte
Copy link
Member

@abellotti bump

@abellotti
Copy link
Member

wasn't too crazy with the string matching in the specs, vs. the previous hash ways.

@imtayadeway
Copy link
Contributor Author

@abellotti would you care to say why? And could you weigh any objections against the benefits I've outlined in #15058 (comment) ? I've rebased and updated a little bit since you last looked at it (principally to switch from mocking to verifying against an injected log device), although the expectations remain basically the same. Might allay some of your concerns though as I've tried to make the expectations as order-independent as possible. I think generally the result is a lot better though, because now these tests are testing external behavior, not private implementation details.

@kbrock
Copy link
Member

kbrock commented May 31, 2017

I like testing at the boundary. And testing in a way that is order independent.
Do agree that hash approach is a little nicer, but this is the logging specs, so testing what goes into the log seems reasonable.

@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2017

Checked commits imtayadeway/manageiq@fa02873~...aa602bc with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
1 file checked, 0 offenses detected
Everything looks fine. 🍰

@imtayadeway
Copy link
Contributor Author

@abellotti bump

@kbrock
Copy link
Member

kbrock commented Jun 29, 2017

The includes seems close to the pure hash version now.
Think it is a nice touch

@abellotti abellotti merged commit 0b7c24f into ManageIQ:master Jul 5, 2017
@abellotti abellotti added this to the Sprint 64 Ending Jul 10, 2017 milestone Jul 5, 2017
imtayadeway added a commit to imtayadeway/manageiq that referenced this pull request Jul 5, 2017
With the collision of ManageIQ#15058 and ManageIQ#15392 these specs are now
failing. Since there's no way to sensibly implement `#reopen` on a
multicast logger opaquely, instead we'll add a logger to the multicast
loggers and verify against that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants