shoulda-matchers icon indicating copy to clipboard operation
shoulda-matchers copied to clipboard

should_not validate_presence_of can give a false positive

Open mcmire opened this issue 4 years ago • 1 comments

If you have a situation where you have a presence validation with a custom message and you say it { should_not validate_presence_of(:attribute) } when in fact the validation is being run, the test will pass. This is technically true, because it { should_not validate_presence_of(:attribute) } is the same thing as saying it { should_not validate_presence_of(:attribute).with_message(:blank) }. That may make sense for should, but for should_not this doesn't make any sense.

mcmire avatar May 15 '20 18:05 mcmire

Hey @mcmire. I'm working on this one. But honestly, I'm getting lost searching for the responsible method of the false positive, in lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb.

Can you help me out? :smile:

HeitorMC avatar Mar 07 '23 14:03 HeitorMC