File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rails antipattern : testing the validation rules ?

 
Thomas Queste
Greenhorn
Posts: 15
  • 0
  • 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
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • 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 :)
 
Tammer Saleh
author
Greenhorn
Posts: 11
Ruby
  • 0
  • 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
Pie
Posts: 1367
18
  • 0
  • 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 :)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic