2 ms·
I fend off the "magic numbers" people with a variable with a name that describes what the magic number is for. var expectedAccountBalance = 2500 expect(acc
by NortySpock 4y ago
I fend off the "magic numbers" people with a variable with a name that describes what the magic number is for.
var expectedAccountBalance = 2500
expect(account1.balance).to eq expectedAccountBalance
expect(account1.balance).to eq account2.balance
- tharkun__ 4y agoThat's a good enough (initial) workaround if you're in an environment where you're in the minority (or alone) w/ your opinion and you still want to do the right thing personally. I would advise you to try and convince your peers though and teach them the better way because I suspect that the people that you're fending off would not do what you did but rather just go w/ the one expect(account1.balance).to eq account2.balance Now while parts of the code base do the right thing (in a slightly long winded way), the rest of the code base written by these other people is still using bad tests.
- ilyt 4y agoas long as there is expect(account1.balance) eq 2500 before that isn't really a big problem. Also "how to do it" is kinda different topic to "how to convince peers that's the right way"
- jsrcout 4y agoThat's my approach as well. My idea is I can change the numbers, and it still better come out right. It forces you to think through (and code) things more clearly. It's too easy to write a test with hard-coded numbers that "just happens" to come out right.