DRY Unit Testing
I got really tired of having to write basically the same exact tests for each ActiveRecord class that has a ‘validates_presence_of :gang, :star’ line. This lead me to write my first Rails plugin, verbosely titled test_required_attributes. Observe:
class GangsterTest < ActiveSupport::TestCase
# Only pass attributes listed in the validates_presence_of call in the model.
test_required_attributes(Gangster, :name => 'Al', :boss => true, :loot => 1e10)
end
Giggidy giggidy!
