rspec_rails_4 icon indicating copy to clipboard operation
rspec_rails_4 copied to clipboard

Ch.5, p.59 - Incomplete spec?

Open olerass opened this issue 12 years ago • 0 comments
trafficstars

This is more a question than an actual issue (and related to one of my other issues with creating contacts, see https://github.com/everydayrails/rspec_rails_4/issues/38).

Does the deletes the contact test on page 59 really test that the contact is deleted?

it "deletes the contact" do
  expect{
  delete :destroy, id: @contact
  }.to change(Contact,:count).by(-1)
end

In my opinion this test does nothing but test that some contact is deleted (and thus should really be named deletes some contact). The deleted contact could be any contact, but there's nothing that ensures it's the one with the correct id. Should we not test this? Isn't it a plausible bug to delete a wrong contact?. I know we can't discover ALL bugs with tests, but in this case it seems obvious that the test doesn't test what it says it does and can be improved.

Book version: 2013-10-29 (PDF)

olerass avatar Nov 02 '13 13:11 olerass