randomperson 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -1
- data/.travis.yml +1 -2
- data/CHANGELOG.md +16 -0
- data/Gemfile +13 -0
- data/LICENCE +19 -0
- data/README.markdown +4 -22
- data/Rakefile +1 -1
- data/lib/randomperson.rb +35 -14
- data/lib/randomperson/demographic.rb +38 -29
- data/lib/randomperson/generator.rb +10 -4
- data/lib/randomperson/loader.rb +24 -12
- data/lib/randomperson/name.rb +1 -1
- data/lib/randomperson/outputter.rb +36 -5
- data/lib/randomperson/ratio.rb +7 -2
- data/lib/randomperson/version.rb +4 -1
- data/randomperson.gemspec +2 -7
- data/spec/last_and_first_names_spec.rb +19 -8
- data/spec/randomperson_spec.rb +151 -178
- data/spec/spec_helper.rb +11 -2
- data/spec/support/shared_examples/names.rb +2 -2
- metadata +17 -122
- data/lib/randomperson/ext/date.rb +0 -16
- data/lib/randomperson/ext/hash.rb +0 -6
- data/lib/randomperson/ext/kernel.rb +0 -21
- data/lib/randomperson/ext/set.rb +0 -15
- data/lib/randomperson/ext/string.rb +0 -0
data/lib/randomperson/name.rb
CHANGED
@@ -2,22 +2,47 @@
|
|
2
2
|
|
3
3
|
# uses the @on_execute block of the including class
|
4
4
|
module Outputter
|
5
|
+
|
6
|
+
# ClassMethods
|
7
|
+
# @api private
|
5
8
|
module ClassMethods
|
6
9
|
|
7
10
|
end # ClassMethods
|
8
|
-
|
11
|
+
|
12
|
+
|
13
|
+
# Instance methods
|
14
|
+
# @api private
|
9
15
|
module InstanceMethods
|
16
|
+
|
17
|
+
# Block to execute when instance is ready.
|
18
|
+
# @example
|
19
|
+
# # In the AmericanSuffix constructor
|
20
|
+
# # Some help to make sure suffixes are age appropriate.
|
21
|
+
# on_execute do |person|
|
22
|
+
# r = rand(99)
|
23
|
+
# if person.age > 17
|
24
|
+
# r += 1 #Jr can't happen and Snr can
|
25
|
+
# end
|
26
|
+
# #
|
27
|
+
# @possibles.each_pair{|k,v| break v if k === r }
|
28
|
+
# end
|
29
|
+
# @api private
|
10
30
|
def on_execute( &block )
|
11
31
|
@on_execute = block
|
12
32
|
end
|
13
33
|
|
34
|
+
|
35
|
+
# Command pattern
|
36
|
+
# @api private
|
14
37
|
def execute( person=nil )
|
15
38
|
@on_execute.call( person )
|
16
39
|
end
|
17
40
|
|
18
41
|
private
|
19
|
-
|
20
|
-
#
|
42
|
+
|
43
|
+
# Handles the outputting of prefixes like Mr, Mrs etc.
|
44
|
+
#TODO rename this as other classes are using it too
|
45
|
+
# @api private
|
21
46
|
def for_prefixes( for_females, for_males, male_upper_bound=50, child_age_upper_bound=16, female_lower_bound=50)
|
22
47
|
|
23
48
|
->(person){
|
@@ -32,7 +57,10 @@ module Outputter
|
|
32
57
|
name
|
33
58
|
}
|
34
59
|
end # prefixes
|
35
|
-
|
60
|
+
|
61
|
+
|
62
|
+
# Handles the outputting for the rest of the name.
|
63
|
+
# @api private
|
36
64
|
def for_standard
|
37
65
|
->(person=nil){
|
38
66
|
f = if @formats.length > 1
|
@@ -45,7 +73,10 @@ module Outputter
|
|
45
73
|
}
|
46
74
|
end
|
47
75
|
end
|
48
|
-
|
76
|
+
|
77
|
+
|
78
|
+
# Classic hooking in.
|
79
|
+
# @api private
|
49
80
|
def self.included(receiver)
|
50
81
|
receiver.extend ClassMethods
|
51
82
|
receiver.send :include, InstanceMethods
|
data/lib/randomperson/ratio.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module RandomPerson #namespace
|
2
2
|
|
3
|
+
# Handles ratios for demographics e.g. 1 male for 1 female.
|
3
4
|
module Ratio
|
4
5
|
|
5
6
|
#create a ratio that is made up of ranges
|
@@ -12,7 +13,8 @@ module RandomPerson #namespace
|
|
12
13
|
new_ratio.shift #get rid of 0..0
|
13
14
|
return new_ratio
|
14
15
|
end
|
15
|
-
|
16
|
+
|
17
|
+
|
16
18
|
#find the order of magnitude of a number for use with this module
|
17
19
|
def ordmag( n )
|
18
20
|
m = 10
|
@@ -22,8 +24,11 @@ module RandomPerson #namespace
|
|
22
24
|
end
|
23
25
|
m
|
24
26
|
end
|
25
|
-
|
27
|
+
|
28
|
+
|
26
29
|
#use this method if you don't have a ratio at all for an array and, hey presto! It'll make one for you
|
30
|
+
# @param [Integer] len Length
|
31
|
+
# @param [Integer] mag Magnitude
|
27
32
|
def presto_rangio( len, mag )
|
28
33
|
return [ ] unless len >= 1
|
29
34
|
l, m = len, mag
|
data/lib/randomperson/version.rb
CHANGED
data/randomperson.gemspec
CHANGED
@@ -4,6 +4,7 @@ require File.expand_path( '../lib/randomperson/version', __FILE__ )
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.authors = ["Iain Barnett"]
|
6
6
|
s.email = ["iainspeed@gmail.com"]
|
7
|
+
s.license = "MIT"
|
7
8
|
s.description = <<-EOF
|
8
9
|
RandomPerson is a port to Ruby of Perl's Data::RandomPerson. Use it to generate random persons given various parameters, such as country, age and gender ratio.
|
9
10
|
EOF
|
@@ -16,11 +17,5 @@ Gem::Specification.new do |s|
|
|
16
17
|
s.name = "randomperson"
|
17
18
|
s.require_paths = ['lib']
|
18
19
|
s.version = RandomPerson::VERSION
|
19
|
-
s.
|
20
|
-
s.add_development_dependency( "rspec" )
|
21
|
-
s.add_development_dependency( "rake" )
|
22
|
-
s.add_development_dependency( "simplecov" )
|
23
|
-
s.add_development_dependency( "yard" )
|
24
|
-
s.add_development_dependency( "redcarpet" ) # for yard
|
25
|
-
s.required_ruby_version = ">= 1.9.1"
|
20
|
+
s.required_ruby_version = ">= 2.0.0"
|
26
21
|
end
|
@@ -4,26 +4,37 @@ require "spec_helper"
|
|
4
4
|
require_relative "./support/shared_examples/names.rb"
|
5
5
|
require_relative "../lib/randomperson/person.rb"
|
6
6
|
require_relative "../lib/randomperson/demographic.rb"
|
7
|
+
require_relative "../lib/randomperson.rb"
|
7
8
|
require_relative "./support/helpers.rb"
|
8
9
|
|
9
10
|
module RandomPerson
|
10
11
|
module Names
|
11
12
|
|
12
|
-
|
13
|
-
klass = klass.split("::").last
|
13
|
+
describe "RandomPerson::Names" do
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
before :all do
|
16
|
+
Demographic.new.require_and_add(Demographic.load_names)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
RandomPerson().loaded_classes.each do |klass|
|
21
|
+
klass_basename = klass.name.split("::").last
|
22
|
+
|
23
|
+
puts "Describe #{klass.name}" #because rspec doesn't output this before it blow up! Sheesh!!
|
24
|
+
describe klass_basename do
|
25
|
+
let(:instance) {
|
26
|
+
klass.new
|
27
|
+
}
|
18
28
|
subject{ instance }
|
19
29
|
it_should_behave_like "a Name class"
|
20
|
-
if ["Prefix", "Suffix"].any?{|x|
|
21
|
-
it_should_behave_like "it cares about gender and/or age", RandomPerson::Spec::Helpers.fix_fixtures[
|
30
|
+
if ["Prefix", "Suffix"].any?{|x| klass_basename.include? x }
|
31
|
+
it_should_behave_like "it cares about gender and/or age", RandomPerson::Spec::Helpers.fix_fixtures[klass_basename]
|
22
32
|
else
|
23
|
-
it_should_behave_like "a name generator", RandomPerson::Spec::Helpers.fixtures[
|
33
|
+
it_should_behave_like "a name generator", RandomPerson::Spec::Helpers.fixtures[klass_basename]
|
24
34
|
end
|
25
35
|
end # describe
|
26
36
|
end # loop
|
37
|
+
end
|
27
38
|
|
28
39
|
end # Names
|
29
40
|
end # RandomPerson
|
data/spec/randomperson_spec.rb
CHANGED
@@ -3,52 +3,8 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
require_relative "../lib/randomperson.rb"
|
5
5
|
|
6
|
-
shared_examples "a Person" do
|
7
|
-
it { subject.first.should_not be_nil }
|
8
|
-
it { subject.first.should be_a_kind_of String }
|
9
|
-
it { subject.last.should_not be_nil }
|
10
|
-
it { subject.last.should be_a_kind_of String }
|
11
|
-
it { subject.prefix.should_not be_nil }
|
12
|
-
it { subject.prefix.should be_a_kind_of String }
|
13
|
-
end
|
14
|
-
|
15
|
-
shared_examples "there is more than one demographic" do
|
16
|
-
context "Given a new demographic" do
|
17
|
-
before(:all) { r.demographic("America").add_American }
|
18
|
-
context "but not changing to it" do
|
19
|
-
let(:last_run) { r.person }
|
20
|
-
subject { last_run }
|
21
|
-
it { should equal first_run }
|
22
|
-
context "changing to the new demographic" do
|
23
|
-
let(:new_demo_person) { r.person "America" }
|
24
|
-
subject { new_demo_person }
|
25
|
-
it { should_not equal last_run }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
shared_examples "getting the last person" do
|
32
|
-
context "on first run" do
|
33
|
-
subject{ first_run }
|
34
|
-
it_behaves_like "a Person"
|
35
|
-
context "on next run" do
|
36
|
-
context "Given no demographic" do
|
37
|
-
subject { r.person }
|
38
|
-
it { should equal first_run }
|
39
|
-
end
|
40
|
-
context "Given the same demographic" do
|
41
|
-
subject{ r.person "Spain" }
|
42
|
-
it { should equal first_run }
|
43
|
-
it_behaves_like "there is more than one demographic"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
6
|
shared_examples "clear or reset" do
|
50
|
-
|
51
|
-
before(:all) {
|
7
|
+
Given!(:before) {
|
52
8
|
r.demographic("Spain").add_Spanish
|
53
9
|
r.demographic("Finland").add_Finnish
|
54
10
|
r.generate "Spain"
|
@@ -57,45 +13,44 @@ shared_examples "clear or reset" do
|
|
57
13
|
r.generate
|
58
14
|
r.generate "Spain"
|
59
15
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
specify { r.demographics.should be_empty }
|
16
|
+
Then { r.clear.nil? }
|
17
|
+
And { r.should_not be_nil }
|
18
|
+
And { r.should be_a_kind_of RandomPerson::Facade }
|
19
|
+
And { r.generators.should be_empty }
|
20
|
+
And { r.demographics.should be_empty }
|
66
21
|
end
|
67
22
|
|
68
23
|
|
69
24
|
describe RandomPerson do
|
70
|
-
|
25
|
+
Given(:r) { RandomPerson() }
|
26
|
+
|
71
27
|
describe :person do
|
72
|
-
let(:r) { RandomPerson() }
|
73
28
|
context "Given a demographic" do
|
74
29
|
context "With a name" do
|
75
|
-
|
76
|
-
|
30
|
+
demo_name = "Spain"
|
31
|
+
context "and one demographic specified, that of #{demo_name}," do
|
32
|
+
Given!(:spanish_was_added) {
|
77
33
|
r.demographic("Spain").add_Spanish
|
78
34
|
}
|
79
|
-
|
80
|
-
|
81
|
-
|
35
|
+
Given(:first_run) { r.person "Spain" }
|
36
|
+
Then { first_run.first.should_not be_nil }
|
37
|
+
And { first_run.first.should be_a_kind_of String }
|
38
|
+
And { first_run.last.should_not be_nil }
|
39
|
+
And { first_run.last.should be_a_kind_of String }
|
40
|
+
And { first_run.prefix.should_not be_nil }
|
41
|
+
And { first_run.prefix.should be_a_kind_of String }
|
82
42
|
context "on next run" do
|
83
43
|
context "Given no demographic" do
|
84
|
-
|
85
|
-
it { should equal first_run }
|
44
|
+
Then { r.person == first_run }
|
86
45
|
context "and then given the same demographic explicitly" do
|
87
|
-
|
88
|
-
it { should equal first_run }
|
46
|
+
Then { r.person("Spain") == first_run }
|
89
47
|
context "and then given a demo name that doesn't exist" do
|
90
|
-
|
91
|
-
it { should be_nil }
|
48
|
+
Then { r.person("Spurious").nil? }
|
92
49
|
context "and then given no demo name" do
|
93
|
-
|
94
|
-
it { should equal first_run }
|
50
|
+
Then { r.person == first_run }
|
95
51
|
end
|
96
52
|
context "and then given the last good demographic explicitly" do
|
97
|
-
|
98
|
-
it { should equal first_run }
|
53
|
+
Then { r.person("Spain") == first_run }
|
99
54
|
end
|
100
55
|
end
|
101
56
|
end
|
@@ -104,42 +59,69 @@ describe RandomPerson do
|
|
104
59
|
end
|
105
60
|
|
106
61
|
context "and no demographic specified" do
|
107
|
-
|
62
|
+
Given!(:spanish_was_added) {
|
108
63
|
r.demographic("Spain").add_Spanish
|
109
64
|
}
|
110
|
-
|
111
|
-
|
65
|
+
context "on first run" do
|
66
|
+
Given!(:first_run) { r.person }
|
67
|
+
Then { first_run.first.should_not be_nil }
|
68
|
+
And { first_run.first.should be_a_kind_of String }
|
69
|
+
And { first_run.last.should_not be_nil }
|
70
|
+
And { first_run.last.should be_a_kind_of String }
|
71
|
+
And { first_run.prefix.should_not be_nil }
|
72
|
+
And { first_run.prefix.should be_a_kind_of String }
|
73
|
+
context "on next run" do
|
74
|
+
context "Given no demographic" do
|
75
|
+
When(:person) { r.person }
|
76
|
+
Then { person == first_run }
|
77
|
+
end
|
78
|
+
context "Given the same demographic" do
|
79
|
+
When(:spanish){ r.person "Spain" }
|
80
|
+
Then { spanish == first_run }
|
81
|
+
context "there is more than one demographic" do
|
82
|
+
context "Given a new demographic" do
|
83
|
+
Given(:american_added) { r.demographic("America").add_American }
|
84
|
+
context "but not changing to it" do
|
85
|
+
When(:r_person) { r.person }
|
86
|
+
Then { r_person == first_run }
|
87
|
+
context "changing to the new demographic" do
|
88
|
+
Given(:new_demo_person) { r.person "America" }
|
89
|
+
When(:new_person) { new_demo_person }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
112
97
|
end
|
113
98
|
|
114
99
|
end
|
115
100
|
|
116
101
|
context "Without a name" do
|
117
102
|
context "and with a demographic specified" do
|
118
|
-
|
103
|
+
Given(:spanish_without_a_name) {
|
119
104
|
r.clear
|
120
105
|
r.demographic.add_Spanish
|
121
106
|
}
|
122
|
-
|
123
|
-
|
107
|
+
When(:person_is_spanish) { r.person "Spain" }
|
108
|
+
Then { person_is_spanish.nil? }
|
124
109
|
end
|
125
110
|
|
126
111
|
context "and no demographic specified" do
|
127
|
-
|
128
|
-
|
129
|
-
}
|
130
|
-
let(:first_run) { r.person }
|
131
|
-
subject { r.person }
|
132
|
-
it { should equal first_run }
|
112
|
+
Given!(:spanish_added) { r.demographic.add_Spanish }
|
113
|
+
When(:first_run) { r.person }
|
114
|
+
Then { r.person == first_run }
|
133
115
|
context "on repeated runs" do
|
134
|
-
|
116
|
+
Given!(:clearing) {
|
135
117
|
r.clear
|
136
118
|
r.demographic.add_Spanish
|
137
119
|
r.generate
|
138
120
|
r.generate
|
139
121
|
}
|
140
|
-
|
141
|
-
|
142
|
-
|
122
|
+
Given(:last_generated) { r.person }
|
123
|
+
When(:person_generated) { r.person }
|
124
|
+
Then { person_generated == last_generated }
|
143
125
|
end
|
144
126
|
|
145
127
|
end
|
@@ -147,29 +129,21 @@ describe RandomPerson do
|
|
147
129
|
end
|
148
130
|
|
149
131
|
context "With no demographic" do
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
it { should be_a_kind_of RandomPerson::Person }
|
154
|
-
context "and given a demo name (that does not exist)" do
|
155
|
-
subject { r.person "Not loaded" }
|
156
|
-
it { should be_nil }
|
157
|
-
end
|
158
|
-
end
|
132
|
+
Given!(:cleared) { r.demographics.clear }
|
133
|
+
Then { r.person.kind_of? RandomPerson::Person }
|
134
|
+
Then { r.person("Not loaded").nil? }
|
159
135
|
context "Because they've been cleared" do
|
160
|
-
|
161
|
-
subject { r.person }
|
162
|
-
it { should be_a_kind_of RandomPerson::Person }
|
136
|
+
Then { r.person.kind_of? RandomPerson::Person }
|
163
137
|
context "and given a demo name (that does not exist)" do
|
164
|
-
|
165
|
-
it { should be_nil }
|
138
|
+
Then { r.person("Been cleared").nil? }
|
166
139
|
context "and given a block with a raise" do
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
140
|
+
Then {
|
141
|
+
expect {
|
142
|
+
r.person "Does not exist" do
|
143
|
+
fail "This demo name does not exist!"
|
144
|
+
end
|
145
|
+
}
|
171
146
|
}
|
172
|
-
specify { expect { subject }.to raise_error }
|
173
147
|
end
|
174
148
|
end
|
175
149
|
end
|
@@ -178,26 +152,23 @@ describe RandomPerson do
|
|
178
152
|
|
179
153
|
|
180
154
|
describe :generators do
|
181
|
-
|
182
|
-
before(:all) {
|
155
|
+
Given(:spanish_and_finish_added) {
|
183
156
|
r.demographic("Spain").add_Spanish
|
184
157
|
r.demographic("Finland").add_Finnish
|
185
158
|
}
|
186
159
|
context "Before first run" do
|
187
|
-
|
188
|
-
it { should be_empty }
|
160
|
+
Then { r.generators.empty? }
|
189
161
|
end
|
190
162
|
context "First run" do
|
191
|
-
|
163
|
+
Given(:some_people_are_generated) {
|
192
164
|
r.generate "Spain"
|
193
165
|
r.generate
|
194
166
|
r.generate "Finland"
|
195
167
|
r.generate
|
196
168
|
r.generate "Spain"
|
197
169
|
}
|
198
|
-
|
199
|
-
|
200
|
-
specify { subject.keys.should include("Spain", "Finland") }
|
170
|
+
Then { r.generators.empty? }
|
171
|
+
And { r.generators.keys.all?{|x| (x == "Spain") || (x == "Finland")}}
|
201
172
|
end
|
202
173
|
end # generators
|
203
174
|
|
@@ -210,117 +181,119 @@ describe RandomPerson do
|
|
210
181
|
end
|
211
182
|
|
212
183
|
describe :generate do
|
213
|
-
let(:r) { RandomPerson() }
|
214
184
|
context "Before a demographic has been loaded" do
|
215
|
-
|
216
|
-
|
217
|
-
it { should be_a_kind_of RandomPerson::Person }
|
185
|
+
Then { !r.generate.nil? }
|
186
|
+
And { r.generate.kind_of? RandomPerson::Person }
|
218
187
|
end
|
219
188
|
context "When there is a demographic loaded" do
|
220
|
-
|
189
|
+
Given!(:demographic) {
|
221
190
|
r.demographic("Spain").add_Spanish
|
222
191
|
}
|
223
|
-
|
192
|
+
Given(:people) {
|
224
193
|
people = []
|
225
194
|
1000.times{ people << r.generate }
|
226
195
|
people
|
227
196
|
}
|
228
197
|
context "Given a demographic name" do
|
229
198
|
context "That has been added to demographics" do
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
199
|
+
When(:spanish) { r.generate "Spain" }
|
200
|
+
Then { !spanish.nil? }
|
201
|
+
And { spanish.kind_of? RandomPerson::Person }
|
202
|
+
And { spanish.first.should_not be_nil }
|
203
|
+
And { spanish.first.should be_a_kind_of String }
|
204
|
+
And { spanish.last.should_not be_nil }
|
205
|
+
And { spanish.last.should be_a_kind_of String }
|
206
|
+
And { spanish.prefix.should_not be_nil }
|
207
|
+
And { spanish.prefix.should be_a_kind_of String }
|
208
|
+
Then { !people.include?(spanish) }
|
235
209
|
end
|
236
210
|
context "That has not been added to demographics" do
|
237
|
-
|
238
|
-
|
211
|
+
When(:spurious) { r.generate "Spurious" }
|
212
|
+
Then { spurious.nil? }
|
239
213
|
end
|
240
214
|
end
|
241
215
|
context "Given a no demographic name" do
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
216
|
+
Then { !r.generate.nil? }
|
217
|
+
And { r.generate.kind_of? RandomPerson::Person }
|
218
|
+
And { r.generate.first.should_not be_nil }
|
219
|
+
And { r.generate.first.should be_a_kind_of String }
|
220
|
+
And { r.generate.last.should_not be_nil }
|
221
|
+
And { r.generate.last.should be_a_kind_of String }
|
222
|
+
And { r.generate.prefix.should_not be_nil }
|
223
|
+
And { r.generate.prefix.should be_a_kind_of String }
|
224
|
+
And { !people.include? r.generate }
|
247
225
|
end
|
248
226
|
end
|
249
227
|
context "When there is no demographic loaded" do
|
250
|
-
|
251
|
-
|
252
|
-
|
228
|
+
When(:spain) { r.generate "Spain" }
|
229
|
+
Then { spain.nil? }
|
230
|
+
When(:no_name) { r.generate }
|
231
|
+
Then { !no_name.nil? }
|
253
232
|
end
|
254
233
|
end
|
255
234
|
|
256
235
|
|
257
236
|
describe :demographics do
|
258
|
-
let(:r) { RandomPerson() }
|
259
237
|
context "With no demographics loaded" do
|
260
|
-
|
261
|
-
|
262
|
-
it { should be_a_kind_of Hash }
|
238
|
+
Then { r.demographics.empty? }
|
239
|
+
And { r.demographics.kind_of? Hash }
|
263
240
|
end
|
264
241
|
context "Given a demographic" do
|
265
242
|
context "With a name" do
|
266
|
-
|
243
|
+
Given!(:spanish_added) {
|
267
244
|
r.demographic("Spain").add_Spanish
|
268
245
|
}
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
specify { subject.first.last.should be_a_kind_of RandomPerson::Demographic }
|
246
|
+
Then { !r.demographics.empty? }
|
247
|
+
And { r.demographics.kind_of? Hash }
|
248
|
+
And { r.demographics.first.kind_of? Array }
|
249
|
+
And { r.demographics.first.first.kind_of? String }
|
250
|
+
And { r.demographics.first.last.kind_of? RandomPerson::Demographic }
|
275
251
|
end
|
276
252
|
context "Without a name" do
|
277
|
-
|
253
|
+
Given!(:demo_spanish) {
|
278
254
|
r.demographic.add_Spanish
|
279
255
|
}
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
specify { subject.first.last.should be_a_kind_of RandomPerson::Demographic }
|
256
|
+
Then { !r.demographics.empty? }
|
257
|
+
And { r.demographics.kind_of? Hash }
|
258
|
+
And { r.demographics.first.kind_of? Array }
|
259
|
+
And { r.demographics.first.first.kind_of? String }
|
260
|
+
And { r.demographics.first.last.kind_of? RandomPerson::Demographic }
|
286
261
|
end
|
287
262
|
|
288
263
|
context "With options" do
|
289
264
|
context "With a named demographic" do
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
265
|
+
Given(:lower){ rand(99) }
|
266
|
+
Given(:upper){ rand(100 - lower) + lower }
|
267
|
+
Given(:females) { rand(10) }
|
268
|
+
Given(:males) { rand(10) }
|
269
|
+
Given!(:demo) {
|
295
270
|
r.demographic("Random!", gender_ratio: [females,males] , age_lower: lower, age_upper: upper ).add_Spanish
|
296
271
|
}
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
specify { subject.first.last.gender_ratio.should == [females,males] }
|
272
|
+
Then { !r.demographics.empty? }
|
273
|
+
And { r.demographics.kind_of? Hash }
|
274
|
+
And { r.demographics.first.should be_a_kind_of Array }
|
275
|
+
And { r.demographics.first.first.should be_a_kind_of String }
|
276
|
+
And { r.demographics.first.last.should be_a_kind_of RandomPerson::Demographic }
|
277
|
+
And { r.demographics.first.last.age_lower.should == lower }
|
278
|
+
And { r.demographics.first.last.age_upper.should == upper }
|
279
|
+
And { r.demographics.first.last.gender_ratio.should == [females,males] }
|
306
280
|
end
|
307
281
|
context "Without a named demographic" do
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
282
|
+
Given(:lower){ rand(99) }
|
283
|
+
Given(:upper){ rand(100 - lower) + lower }
|
284
|
+
Given(:females) { rand(10) }
|
285
|
+
Given(:males) { rand(10) }
|
286
|
+
Given!(:spanish_was_added) {
|
313
287
|
r.demographic(gender_ratio: [females,males] , age_lower: lower, age_upper: upper ).add_Spanish
|
314
288
|
}
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
specify { subject.first.last.gender_ratio.should == [females,males] }
|
289
|
+
Then { r.demographics.kind_of? Hash }
|
290
|
+
And { !r.demographics.empty? }
|
291
|
+
And { r.demographics.first.should be_a_kind_of Array }
|
292
|
+
And { r.demographics.first.first.should be_a_kind_of String }
|
293
|
+
And { r.demographics.first.last.should be_a_kind_of RandomPerson::Demographic }
|
294
|
+
And { r.demographics.first.last.age_lower.should == lower }
|
295
|
+
And { r.demographics.first.last.age_upper.should == upper }
|
296
|
+
And { r.demographics.first.last.gender_ratio.should == [females,males] }
|
324
297
|
end
|
325
298
|
end
|
326
299
|
end
|