Archive for the ‘Testing’ Category

Bulk testing your model attributes with rails

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
Loading ... Loading ...
Wednesday, December 12th, 2007

When it comes to testing in Ruby on Rails I tend to test every piece of its public interface. This means I test every single public method and attribute to ensure my desired functionality. Recently I’ve updated my application from Rails 1.2.5 to 2.0.1 and I was happy to have tests. None of them failed and so I knew that my application is ready to rock with the new Rails 2.0.
However, what I want to write in this article about is how to do bulk testing of each single attribute of your models. Let’s be a bit precise. Say we have a model User which has attributes firstname, lastnameand age. In order to perfectly test the User model we should write tests which …

  1. ensure that invalid values result in an error for the tested attribute (e.g. age -2 is invalid, so the instance should hold an error for the attribute age)
  2. and valid values don’t result in an error for the tested attribute (e.g. age 20 should be fine)

Usually you should test a couple of invalid values and a couple of valid values against each attribute of your model. This can be quite a lot to code. I explain a nice approach how to speed things up and save time for the next family event. (more…)

Testing a change, bugfix, implemented feature, …

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Thursday, November 23rd, 2006

When you implement a new feature somewhere, when you change just some bits of the code, when you fix a bug, when you just change a common text in an app.. What do you do afterwards? Do you really check the result or do you trust yourself that it works 100%. It is an interesting thing to talk about… (more…)