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

Test exact array contents where possible #3731

Merged
merged 7 commits into from
Sep 29, 2019
Merged

Test exact array contents where possible #3731

merged 7 commits into from
Sep 29, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Sep 26, 2019

References

Objectives

  • Make tests checking the contents of an array easier to read
  • Make these tests more consistent with the rest of our tests
  • Reduce the number of unused variable warnings given by the Ruby interpreter

@javierm javierm added the Specs label Sep 26, 2019
@javierm javierm self-assigned this Sep 26, 2019
@javierm javierm added this to Reviewing in Roadmap via automation Sep 26, 2019
@javierm javierm force-pushed the array_specs branch 2 times, most recently from e4ad68d to 66d0fb9 Compare September 26, 2019 19:15
spec/models/debate_spec.rb Show resolved Hide resolved
spec/models/debate_spec.rb Show resolved Hide resolved
Instead of testing the contents of each element, we can test the whole
array at once.
It's shorter, and easy to read.
@javierm javierm changed the base branch from remove_obsolete_code to master September 29, 2019 21:25
We were using `to_sentence` to check the order, while it's easier to
just check the exact contents of the array.

Furthermore, using `to_sentence` checked the order of the array, so it
was a potentially flaky spec since the method doesn't specify an order
and PostgreSQL doesn't guarantee the order of the records.
The test or the draft phase legislation filter was using an entirely
different set of records, but was still creating the records used in the
open and past filter as well.

This made it hard to test the filter, since it returned records from
both sets.

Grouping the past and open filters together guarantees their records
won't be created in the phase draft test, and so we can test the exact
contents of the array.
We're using `eq` and `match_array` in most places, but there were a few
places where we were still checking each element is included in the
array. This is a bit dangerous, because the array could have duplicate
elements, and we wouldn't detect them with `include`.
Using `not_to include` does not test for other elements which could be
present in the array.
When we already have tests checking which records are included, in the
tests testing records are not included we can just generate records
which will not be included and test against an empty array.

We were already using this approach in some tests. This way we also
avoid useless assignments.
@javierm javierm merged commit 3b5cbc2 into master Sep 29, 2019
Roadmap automation moved this from Reviewing to Release 1.1.0 Sep 29, 2019
@javierm javierm deleted the array_specs branch November 7, 2019 23:42
smarques pushed a commit to venetochevogliamo/consul that referenced this pull request Apr 29, 2020
Test exact array contents where possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

None yet

2 participants