Thursday, January 15, 2009

dm_skinny_specs ... trimming the fat from dm models' specs

Just released my 2nd gem dm_skinny_specs last night, this gem aims to help u trim away extra fat from dm models' specs. Here's a quick example of how things work (for 0.1.0):

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'dm_skinny_spec'

class User
include DataMapper::Resource

property :id, Serial
property :name, String, :auto_validation => false
property :email, String, :auto_validation => false

validates_length :name, :min => 5
validates_format :email, :as => :email_address, :allow_nil => false
end

User.fix {{
:name => /\w{5,10}/.gen,
:email => /\w{10}/.gen + '@fmail.com',
}}

describe User do

before do
User.auto_migrate!
@instances = {}
end

# This MUST be provided since we do not mandate u to use any specific fixture
# utility.
def instance(id=:default)
@instances[id] ||= User.gen
end

it_should_validate_length :name, :min => 5
it_should_validate_format :email, :as => :email_address, :allow_nil => false

end


Hey !! Wait a minute, doesn't skinny_spec and the whole idea of these spec helpers sound familiar ?! Ok Ok, i admit it, i was inspired by the original skinny_spec for rails :P

No comments: