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

Refactor unit test for SmartAnswer::Question::Base #2340

Merged
merged 12 commits into from
Mar 8, 2016

Conversation

floehopper
Copy link
Contributor

This follows on from #2319 and is further work in preparation for a proper version of #2311.

I was finding it increasingly hard to read and edit the unit test for SmartAnswer::Question::Base, so I decided to to some preparatory refactoring.

The main change in this PR is the grouping together of related tests into Shoulda contexts. I hope the commits are small enough that you can see what's going on in the diffs - you might need to ignore whitespace changes to make things clearer. I've also extracted a method to DRY up the test code a bit.

See the individual commit notes for details.

Given that I've only made changes to a single unit test and no "production" code, these changes should be pretty low risk, but it would be good if someone could give them the once over.

I want to introduce `shoulda` contexts into this test to make it easier
to understand, but these don't appear to work in conjunction with
`ActiveSupport`-style test definitions.
@erkde
Copy link
Contributor

erkde commented Mar 7, 2016

Other than minor comments, looks good to me

@erkde erkde added the LGTM label Mar 7, 2016
@floehopper floehopper force-pushed the refactor-question-base-test branch from 47f773e to 5b1987e Compare March 8, 2016 09:35
@floehopper
Copy link
Contributor Author

I'm going to do the interactive rebase against master now and force push in preparation for merging.

Into a context and improve the test name.
I noticed this scenario was missing after I'd reorganised the tests into
`shoulda` contexts.
This removes some duplication, improves the signal-to-noise ratio,
and makes it clearer which is the method-under-test in each case.
The call to the constructor of `SmartAnswer::State` in the previous line sets
its `current_node` to this value anyway.
There were two tests asserting against the message of this exception.

While it's worthwhile testing that both scenarios raise the exception,
it's not worth asserting against the message in both tests.
@floehopper floehopper force-pushed the refactor-question-base-test branch from 5b1987e to 3103862 Compare March 8, 2016 10:07
floehopper added a commit that referenced this pull request Mar 8, 2016
Refactor unit test for SmartAnswer::Question::Base
@floehopper floehopper merged commit 6942d51 into master Mar 8, 2016
@floehopper floehopper deleted the refactor-question-base-test branch March 8, 2016 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants