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 diary tests #1285

Merged
merged 6 commits into from Sep 15, 2016
Merged

Refactor diary tests #1285

merged 6 commits into from Sep 15, 2016

Conversation

@gravitystorm
Copy link
Collaborator

@gravitystorm gravitystorm commented Sep 14, 2016

This PR refactors that diary entry and diary comment tests to remove the associated fixtures.

Note that you may need to remove the fixtures from your test database, since there's nothing in the rails code that removes unnecessary fixtures after their definitions are deleted. Either reload the test database completely, or run "delete from" via psql for diary_entries and diary_comments.

gravitystorm added 5 commits Sep 8, 2016
Replaces unnecessary test.
The original name is reserved, which means the user was invalid,
and this causes problems when building objects using it via
associations.
Note that you might need to empty the tables in your local test
database, since the removed fixtures may still linger there.
end

def test_list_user
diary_entry = create(:diary_entry)
geo_entry = create(:diary_entry, :latitude => 51.50763, :longitude => -0.10781)

This comment has been minimized.

@tomhughes

tomhughes Sep 14, 2016
Member

So the problem here is that by only creating those two entries we are no longer testing that the right posts get selected because there are no non-matching posts in the database. Much the same applies to the other list tests.

@gravitystorm
Copy link
Collaborator Author

@gravitystorm gravitystorm commented Sep 15, 2016

Ugh, implicit tests. Testing negatives are bad enough (just as likely to have an incorrect test as to be successfully testing that something is missing), but implicit ones are the worst. Due to the fixtures our tests are full of implicit negatives.

I'll fix these though, update soon.

In general, our tests have too high ratio of assertions to tests, so it's very hard to discern that e.g. "test_list_user" is supposed to both test that particular things show, and also that other things aren't. But it's nowhere near as bad as e.g. test_new, which crams 5 different tests (even needs comments to delineate them) and 40 assertions into one MegaTest(tm). But I'm trying to avoid biting off too much at once.

The other list tests already have assetions showing the different
lengths of lists.
@tomhughes tomhughes merged commit 516979b into openstreetmap:master Sep 15, 2016
1 of 2 checks passed
1 of 2 checks passed
coverage/coveralls Coverage decreased (-0.009%) to 89.757%
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@gorn
Copy link

@gorn gorn commented Sep 16, 2016

I am reasonably experienced rails dev, but I have never seed osmsite codebase. Therefore a question which is quite important to me is - how good/exhaustive are the tests right now? Even if I know the codebase I always start with enrighing the test to maximum extend BEFORE refactoring, because it sort of preserves the quality of the code brought in by years in wild. Basically at this point of development I test the added test by the codebase itself, if I beleive it its correctness :)

If you feel they are comprehensive enough, I would be much more inclined to jump in to refactoring, because it would feel less nervous about breaking any functionality I am not aware of. Of course I would start with syntactic stuff which theoretically should not change the behavior of code at all, but you know - that is a theory.

@gravitystorm
Copy link
Collaborator Author

@gravitystorm gravitystorm commented Sep 26, 2016

@gorn The tests are substantial - there are over 290,000 assertions in the test suite. So you can feel confident at getting started with developing.

@gravitystorm gravitystorm deleted the gravitystorm:diarytests branch Oct 19, 2016
@gravitystorm gravitystorm restored the gravitystorm:diarytests branch Oct 19, 2016
@gravitystorm gravitystorm deleted the gravitystorm:diarytests branch Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.