Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 1, 2021 09:34 am GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To