lundi 4 janvier 2016

Minitest: assert that a value on an ActiveRecord object is `false` without allowing `nil` to pass

Given an ActiveRecord object with a boolean attribute, how can I write a test to ensure that the value is false that doesn't pass if the value is nil? I'm currently running into false positives where the attribute didn't get set to false during initialization, but my test:

refute penalty.team_penalty?

...is passing because of the falsy-ness of nil.

I realize I could add another test above:

refute penalty.team_penalty?.nil?
refute penalty.team_penalty?

...but is there any way to do this without using an extra test or a custom assertion?

Aucun commentaire:

Enregistrer un commentaire