An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
March 1, 2021 09:34 am GMT
Original Link: https://dev.to/vasily/which-test-will-fall-if-we-delete-this-piece-of-code-4l3n
Which test will fall if we delete this piece of code?
Look, there is an alarm like this:
class Alarm def to_human at.strftime("%k:%M").strip endend
Enter fullscreen mode Exit fullscreen mode
And this test:
it "returns alarm in human-readable 24-hour format" do time = Time.local(2019, 7, 7, 10, 35) alarm = described_class.new(at: time) expect(alarm.to_human).to eq "10:35"end
Enter fullscreen mode Exit fullscreen mode
To see if these tests are enough, I look at the module being tested and ask myself: what would happen, if I remove this piece of code, which expectation will fail? If none, then I'm 100% missing checks or expectations.
In the alarm clock example, the .strip
is in question. If you delete it, the test stays green. So the expectation is missing:
it "strips any leading spaces" do time = Time.local(2019, 7, 7, 7, 15) alarm = described_class.new(at: time) expect(alarm.to_human).to eq "7:15"end
Enter fullscreen mode Exit fullscreen mode
Original Link: https://dev.to/vasily/which-test-will-fall-if-we-delete-this-piece-of-code-4l3n
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To