-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Check page content from the user's perspective #3725
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
houndci-bot
reviewed
Sep 25, 2019
d888cfc
to
7ca09df
Compare
6cf29db
to
cc76a4d
Compare
70275c8
to
4ada00c
Compare
cc76a4d
to
8fba68b
Compare
4ada00c
to
c7b4099
Compare
8fba68b
to
b722fa2
Compare
c7b4099
to
7894af6
Compare
b722fa2
to
ed45561
Compare
7894af6
to
d5b0354
Compare
93036d4
to
65e6002
Compare
bbf2fe7
to
a48bada
Compare
08931c0
to
105fa69
Compare
519b7ca
to
e439845
Compare
2bdcde7
to
0484318
Compare
27d0322
to
8baa80b
Compare
0484318
to
570b753
Compare
05b7dad
to
8ca04e9
Compare
fdf806f
to
1a55fb6
Compare
56e14bd
to
9942ae3
Compare
1a55fb6
to
f189c97
Compare
9942ae3
to
e0f4825
Compare
f189c97
to
33cb460
Compare
e0f4825
to
47368f1
Compare
33cb460
to
9529d59
Compare
47368f1
to
fd85611
Compare
9b14c8a
to
0b80d26
Compare
fd85611
to
d9b412e
Compare
0b80d26
to
2e74ab8
Compare
71af17d
to
e2b536e
Compare
Assigning a variable to each budget we declare results in useless assignments. We could just delete the three useless assignments and leave the fourth one, but I find the code easier to read if we use the name of the budgets to differenciate between them. This way we also keep the code vertically aligned.
Since we're obtaining titles and usernames in the response, it's easier to compare them to titles and usernames we manually set. Furthermore, this way we avoid many useless assignments.
While this is potentially very dangerous because assigning the ID does not increase the ID sequence, it's safe to do so in tests where we assign the ID to every record created on a certain table. Even so, I'd consider it a bad practice which must be used with care. In this case I'm using it because we look for IDs in the response, and most tests in this file use literals to compare the response. This changes makes it possible to remove unused variables while keeping the test readable.
This way we write the tests from the user's point of view: users can see (for example) a proposal with the title "Make everything awesome", but they don't see a proposal with a certain ID. There are probably dozens, if not hundreds, of places where we could write tests this way. However, it's very hard to filter which ones are safe to edit, since not many of them have an HTML class we can use in the tests, and adding a class might generate conflicts with CSS styles. So, for now, I'm only changing the ones allowing us to cleanly remove useless assignements while maintaining the code vertically aligned.
We usually check against the literal text instead of storing the text in a variable.
We were creating records with a title we manually set, so to be consistent with the rest of the code, in the test we check the title is present using a string literal. This way we can also remove useless assignments while keeping the code vertically aligned.
This is easier to follow
This way we check the page from the user's point of view.
This way we also simplify the code by avoiding instance variables.
2e74ab8
to
1ebfa04
Compare
smarques
pushed a commit
to venetochevogliamo/consul
that referenced
this pull request
Apr 29, 2020
Check page content from the user's perspective
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Our tests vary in style: sometimes we create a proposal and check the view for the proposal's title writing
expect(page).to have_content proposal.title
, and sometimes we create a proposal with a title like "More schools" and check the view withexpect(page).to have_content "More schools"
.We unanimously prefer the latter style unless there's a good reason to use the former.
Objectives
Notes
We're not changing every existing test because it would be overkill. For now we're changing the ones were the Ruby interpreter