Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Rails antipattern : testing the validation rules ?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wonder what do you think about testing the validation rules ?

I have written code against simple rules, as validate_presence and so on.
Today, I don't do it anymore, because the "Return on investment" is not relevant for this test code.

(Exception to the rules : I do test my validation methods if they are complexe, like regex)

What do you think : is testing validation rules an anti-pattern ?

Thanks,
Tom
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if it's an anti-pattern per se, but it's certainly a waste of time to test the framework -- there's other code testing that those validations work.

The exception would be if you're test driving the behavior of that code, at which point you're not testing validations you're specifying behavior.
Thin line, I guess :)
 
author
Posts: 11
Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a fairly well contested question, but I fall on the TDD line: I work best when I write tests before each line of code. Basically, it's more about tempo than knowing that I've got 100% test coverage.

So, with that philosophy, I end up writing tests for everything, including the fact that a validation was setup.
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I generally fall on the TDD side as well; my colleagues don't. That way we're certain to have covered all possible exits :)
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic