forked from jnicklas/rorem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
73 lines (43 loc) · 1.55 KB
/
README
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Rorem
=====
Rorem is a random data generator that automatically fill Ruby classes with Random data, here's how:
class Car
include Rorem::Model
attr_accessor :brand, :seats, :owner_name, :owner_age, :special_car
end
Car.factory do |car|
# all brands are equality likely
car.brand = random(%w(BMW Mercedes Volvo Jaguar))
# assign probabilities to each value
car.seats = random([2, 4], :distribution => [0.2, 0.8])
# use a normal distribution to describe probabilities
car.owner_age = random(18..70, :distribution => normal(40, 15))
# generate a name from rorem's database of names
car.owner_name = random(:name
# a deterministic value can be set
car.special_car false
end
c = Car.new
c.fill
c.brand #=> 'BMW'
c.seats #=> 4
c.owner_age #=> 27
c.owner_name #=> 'Allan Hernandez'
c.special_car #=> false
another (more complex) example
class Employee
include Rorem::Model
attr_accessor :first_name, :last_name, :email, :employee_nr, :empolyee_id, :address, :city, :country
end
Employee.factory do
c.employee_nr = sequence(:employee_nr, :start => 1)
person = random(:person, :unique => true)
location = random(:location)
c.first_name = person.first_name
c.last_name = person.last_name
c.email = person.email
c.address = location.address
c.city = location.city
c.country = location.country
c.employee_id = c.first_name[1..3] + c.last_name[1..4] + c.employee_nr.to_s
end