namae 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/namae/parser.rb +4 -2
- data/lib/namae/version.rb +2 -2
- metadata +17 -33
- data/.codeclimate.yml +0 -16
- data/.coveralls.yml +0 -1
- data/.document +0 -7
- data/.rspec +0 -2
- data/.rubocop.yml +0 -1156
- data/.simplecov +0 -4
- data/.travis.yml +0 -38
- data/.yardopts +0 -3
- data/Gemfile +0 -26
- data/Rakefile +0 -74
- data/cucumber.yml +0 -1
- data/features/bibtex.feature +0 -78
- data/features/examples.feature +0 -52
- data/features/lists.feature +0 -138
- data/features/step_definitions/namae_steps.rb +0 -45
- data/features/suffix.feature +0 -49
- data/features/support/env.rb +0 -24
- data/features/title.feature +0 -17
- data/namae.gemspec +0 -70
- data/spec/namae/name_spec.rb +0 -133
- data/spec/namae/parser_spec.rb +0 -263
- data/spec/namae/utility_spec.rb +0 -21
- data/spec/spec_helper.rb +0 -32
- data/spec/thread_safety_spec.rb +0 -25
data/spec/namae/name_spec.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module Namae
|
2
|
-
describe 'Name' do
|
3
|
-
|
4
|
-
describe '.new' do
|
5
|
-
|
6
|
-
it 'returns an empty name by default' do
|
7
|
-
expect(Name.new).to be_empty
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'sets all passed-in attributes' do
|
11
|
-
expect(Name.new(:given => 'Foo').given).to eq('Foo')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'ignores unknown attributes' do
|
15
|
-
expect(Name.new(:foo => 'bar')).to be_empty
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '.parse' do
|
21
|
-
it 'returns an empty name for an empty string' do
|
22
|
-
expect(Name.parse('')).to be_empty
|
23
|
-
expect(Name.parse('')).to be_a(Name)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns a single name object if there is more than one name' do
|
27
|
-
expect(Name.parse('Plato and Sokrates').given).to eq('Plato')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#values_at' do
|
32
|
-
it 'returns an array with the given values' do
|
33
|
-
expect(Name.new(:family => 'foo').values_at(:family)).to eq(['foo'])
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns an array with the given values' do
|
37
|
-
expect(Name.new(:family => 'foo').values_at(:family)).to eq(['foo'])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#initials' do
|
42
|
-
it "returns the name's initials" do
|
43
|
-
expect(Name.new(:family => 'Poe', :given => 'Edgar A.').initials).to eq('E.A.P.')
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns the name's initials but leaves the family name expanded" do
|
47
|
-
expect(Name.new(:family => 'Poe', :given => 'Edgar A.').initials(:expand => true)).to eq('E.A. Poe')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#normalize_initials' do
|
52
|
-
it "adds dots to existing initials" do
|
53
|
-
expect(Name.new(:given => 'Edgar A').normalize_initials.given).to eq('Edgar A.')
|
54
|
-
expect(Name.new(:given => 'A').normalize_initials.given).to eq('A.')
|
55
|
-
expect(Name.new(:given => 'E A').normalize_initials.given).to eq('E.A.')
|
56
|
-
expect(Name.new(:given => 'EA').normalize_initials.given).to eq('E.A.')
|
57
|
-
expect(Name.new(:given => 'JFK').normalize_initials.given).to eq('J.F.K.')
|
58
|
-
expect(Name.new(:given => 'E-A').normalize_initials.given).to eq('E.-A.')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#merge' do
|
63
|
-
it 'merges the attributes in the given hash into the name' do
|
64
|
-
expect(Name.new.merge(:family => 'foo').family).to eq('foo')
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'merges the attributes in the given name into the name' do
|
68
|
-
expect(Name.new.merge(Name.new(:family => 'foo')).family).to eq('foo')
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'ignores unknown attributes' do
|
72
|
-
expect(Name.new.merge(:foo => 'bar')).to be_empty
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'ignores nil values' do
|
76
|
-
expect(Name.new(:family => 'foo').merge(:family => nil).family).to eq('foo')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe '#inspect' do
|
81
|
-
it 'returns the name as a string' do
|
82
|
-
expect(Name.new(:given => 'Ichiro').inspect).to eq('#<Name given="Ichiro">')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#sort_order' do
|
87
|
-
it 'returns an empty string by default' do
|
88
|
-
expect(Name.new.sort_order).to eq('')
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'returns the name in sort order' do
|
92
|
-
expect(Name.new(:given => 'Ichiro', :family => 'Suzuki').sort_order).to eq('Suzuki, Ichiro')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'returns only the given if there is no family name' do
|
96
|
-
expect(Name.new(:given => 'Ichiro').sort_order).to eq('Ichiro')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'returns only the family if there is no given name' do
|
100
|
-
expect(Name.new(:family => 'Suzuki').sort_order).to eq('Suzuki')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'includes the suffix' do
|
104
|
-
expect(Name.new(:family => 'Griffey', :suffix => 'Jr.').sort_order).to eq('Griffey, Jr.')
|
105
|
-
expect(Name.new(:family => 'Griffey', :given => 'Ken', :suffix => 'Jr.').sort_order).to eq('Griffey, Jr., Ken')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '#display_order' do
|
110
|
-
it 'returns an empty string by default' do
|
111
|
-
expect(Name.new.display_order).to eq('')
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'returns the name in display order' do
|
115
|
-
expect(Name.new(:given => 'Ichiro', :family => 'Suzuki').display_order).to eq('Ichiro Suzuki')
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'returns only the given if there is no family name' do
|
119
|
-
expect(Name.new(:given => 'Ichiro').display_order).to eq('Ichiro')
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'returns only the family if there is no given name' do
|
123
|
-
expect(Name.new(:family => 'Suzuki').display_order).to eq('Suzuki')
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'includes the suffix' do
|
127
|
-
expect(Name.new(:family => 'Griffey', :suffix => 'Jr.').display_order).to eq('Griffey Jr.')
|
128
|
-
expect(Name.new(:family => 'Griffey', :given => 'Ken', :suffix => 'Jr.').display_order).to eq('Ken Griffey Jr.')
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
data/spec/namae/parser_spec.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
module Namae
|
2
|
-
describe 'Parser' do
|
3
|
-
describe '.instance' do
|
4
|
-
let(:parser) { Parser.instance }
|
5
|
-
|
6
|
-
it 'returns the parser' do
|
7
|
-
expect(parser).to be_a(Parser)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#next_token' do
|
11
|
-
before(:each) do
|
12
|
-
Parser.instance.reset
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'when the input is empty' do
|
16
|
-
it 'returns nil' do
|
17
|
-
expect(parser.send(:next_token)).to be_nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'when the next input is " and "' do
|
22
|
-
before { parser.send(:input).string = ' and ' }
|
23
|
-
it 'returns an AND token' do
|
24
|
-
expect(parser.send(:next_token)).to eq([:AND, :AND])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'when the next input is " & "' do
|
29
|
-
before { parser.send(:input).string = ' & ' }
|
30
|
-
it 'returns an AND token' do
|
31
|
-
expect(parser.send(:next_token)).to eq([:AND, :AND])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'when the next input is " , "' do
|
36
|
-
before { parser.send(:input).string = ' , ' }
|
37
|
-
it 'returns a COMMA token' do
|
38
|
-
expect(parser.send(:next_token)).to eq([:COMMA, :COMMA])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'when the next input is ", "' do
|
43
|
-
before { parser.send(:input).string = ', ' }
|
44
|
-
it 'returns a COMMA token' do
|
45
|
-
expect(parser.send(:next_token)).to eq([:COMMA, :COMMA])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'when the next input is "; "' do
|
50
|
-
before { parser.send(:input).string = '; ' }
|
51
|
-
it 'returns an AND token' do
|
52
|
-
expect(parser.send(:next_token)).to eq([:AND, :AND])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'when the next input is "foo;"' do
|
57
|
-
before { parser.send(:input).string = 'foo;' }
|
58
|
-
it 'returns an LWORD token "foo"' do
|
59
|
-
expect(parser.send(:next_token)).to eq([:LWORD, 'foo'])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'when the next input is " \'foo bar\' "' do
|
64
|
-
before { parser.send(:input).string = " 'foo bar' " }
|
65
|
-
it 'returns a NICK token' do
|
66
|
-
expect(parser.send(:next_token)).to eq([:NICK, 'foo bar'])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
%w{Mr. Mr Mrs. Ms Herr Frau Miss}.each do |appellation|
|
71
|
-
describe "the next token is #{appellation.inspect}" do
|
72
|
-
before { parser.reset.send(:input).string = appellation }
|
73
|
-
it 'returns an APPELLATION token' do
|
74
|
-
expect(parser.send(:next_token)).to eq([:APPELLATION, appellation])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
%w{Jr. Jr Sr. Sr II II. VII IX}.each do |suffix|
|
80
|
-
describe "the next token is #{suffix.inspect}" do
|
81
|
-
before { parser.send(:input).string = suffix }
|
82
|
-
it 'returns an SUFFIX token' do
|
83
|
-
expect(parser.send(:next_token)).to eq([:SUFFIX, suffix])
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'the input matches the suffix pattern' do
|
87
|
-
expect(parser.suffix).to match(suffix)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
%w{Ph.D. PhD PHD Dr. Dr Prof.}.each do |title|
|
93
|
-
describe "the next token is #{title.inspect}" do
|
94
|
-
before { parser.send(:input).string = title }
|
95
|
-
it 'returns a TITLE token' do
|
96
|
-
expect(parser.send(:next_token)).to eq([:TITLE, title])
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'the input matches the suffix pattern' do
|
100
|
-
expect(parser.title).to match(title)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
%w{Gen. Adm Col. Maj Capt. Cmdr. Lt. Sgt. Cpl Pvt.}.each do |title|
|
106
|
-
describe "the next token is #{title.inspect}" do
|
107
|
-
before { parser.send(:input).string = title }
|
108
|
-
it 'returns a TITLE token' do
|
109
|
-
expect(parser.send(:next_token)).to eq([:TITLE, title])
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'the input matches the suffix pattern' do
|
113
|
-
expect(parser.title).to match(title)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
%w{Pastor Pr. Reverend Rev. Elder Deacon Deaconess Father Fr. Vicar Rabbi Cantor}.each do |title|
|
119
|
-
describe "the next token is #{title.inspect}" do
|
120
|
-
before { parser.send(:input).string = title }
|
121
|
-
it 'returns a TITLE token' do
|
122
|
-
expect(parser.send(:next_token)).to eq([:TITLE, title])
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'the input matches the suffix pattern' do
|
126
|
-
expect(parser.title).to match(title)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe '#parse!' do
|
133
|
-
it 'returns an empty list by default' do
|
134
|
-
expect(parser.parse!('')).to be_empty
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'returns a list of names' do
|
138
|
-
expect(parser.parse!('foo')[0]).to be_a(Name)
|
139
|
-
end
|
140
|
-
|
141
|
-
describe 'when parsing a single name' do
|
142
|
-
|
143
|
-
it 'treats "Ichiro" as a given name' do
|
144
|
-
expect(parser.parse!('Ichiro')[0].given).to eq('Ichiro')
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'treats "Lord Byron" as a title and family name' do
|
148
|
-
expect(parser.parse!('Lord Byron')[0].values_at(:family, :title)).to eq(['Byron', 'Lord'])
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'parses given and family part name in "Ichiro Suzuki"' do
|
152
|
-
expect(parser.parse!('Ichiro Suzuki')[0].values_at(:given, :family)).to eq(%w{Ichiro Suzuki})
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'parses given, nick and family part name in "Yukihiro \'Matz\' Matsumoto"' do
|
156
|
-
expect(parser.parse!("Yukihiro 'Matz' Matsumoto")[0].values_at(:given, :family, :nick)).to eq(%w{Yukihiro Matsumoto Matz})
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'parses given, nick and family part name in \'Yukihiro "Matz" Matsumoto\'' do
|
160
|
-
expect(parser.parse!('Yukihiro "Matz" Matsumoto')[0].values_at(:given, :family, :nick)).to eq(%w{Yukihiro Matsumoto Matz})
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'parses appellation and nick in \'Mr. Yukihiro "Matz" Matsumoto\'' do
|
164
|
-
expect(parser.parse!('Mr. Yukihiro "Matz" Matsumoto')[0].values_at(:appellation, :nick)).to eq(%w{Mr. Matz})
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'parses suffix and nick in \'Yukihiro "Matz" Matsumoto Jr.\'' do
|
168
|
-
expect(parser.parse!('Yukihiro "Matz" Matsumoto Jr.')[0].values_at(:suffix, :nick)).to eq(%w{Jr. Matz})
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'parses given and family name in "Poe, Edgar A."' do
|
172
|
-
expect(parser.parse!('Poe, Edgar A.')[0].values_at(:given, :family)).to eq(['Edgar A.', 'Poe'])
|
173
|
-
end
|
174
|
-
|
175
|
-
%w{Mr. Mr Mrs. Ms Herr Frau Miss}.each do |appellation|
|
176
|
-
it "recognizes #{appellation.inspect} as an appellation" do
|
177
|
-
expect(parser.parse!([appellation, 'Edgar A. Poe'].join(' '))[0].appellation).to eq(appellation)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'parses common Jr. as a suffix in sort order' do
|
182
|
-
expect(parser.parse!('Griffey, Jr., Ken')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
|
183
|
-
expect(parser.parse!('Griffey, Ken, Jr.')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'parses common Jr. as a suffix in display order' do
|
187
|
-
expect(parser.parse!('Ken Griffey Jr.')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'parses Ph.D. title suffix in display order' do
|
191
|
-
expect(parser.parse!('Bernado Franecki Ph.D.')[0].values_at(:given, :family, :title)).to eq(['Bernado', 'Franecki', 'Ph.D.'])
|
192
|
-
#expect(parser.parse!('Bernado Franecki, Ph.D.')[0].values_at(:given, :family, :title)).to eq(['Bernado', 'Franecki', 'Ph.D.'])
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'parses consecutive titles in display order' do
|
196
|
-
expect(parser.parse!('Lt. Col. Bernado Franecki')[0].values_at(:given, :family, :title)).to eq(['Bernado', 'Franecki', 'Lt. Col.'])
|
197
|
-
end
|
198
|
-
|
199
|
-
context 'when include_particle_in_family is false' do
|
200
|
-
let(:parser) { Parser.new(include_particle_in_family: false) }
|
201
|
-
|
202
|
-
it 'parses common capitalized particles as the family name in display order' do
|
203
|
-
expect(parser.parse!('Carlos De Silva')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'Silva', 'De'])
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'parses common capitalized particles with punctuation as the family name in display order' do
|
207
|
-
expect(parser.parse!('Matt St. Hilaire')[0].values_at(:given, :family, :particle)).to eq(['Matt', 'Hilaire', 'St.'])
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'parses multiple common capitalized particles as the family name in display order' do
|
211
|
-
expect(parser.parse!('Tom Van De Weghe')[0].values_at(:given, :family, :particle)).to eq(['Tom', 'Weghe', 'Van De'])
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'parses common lowercase particles as a particle, not family name in display order' do
|
215
|
-
expect(parser.parse!('Carlos de Silva')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'Silva', 'de'])
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'parses common capitalized particles as the family name in sort order' do
|
219
|
-
expect(parser.parse!('De Silva, Carlos')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'Silva', 'De'])
|
220
|
-
end
|
221
|
-
|
222
|
-
it 'parses common lowercase particles as a particle, not family name in sort order' do
|
223
|
-
expect(parser.parse!('de Silva, Carlos')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'Silva', 'de'])
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'parses common capitalized particles with punctuation as the family name in display order' do
|
227
|
-
expect(parser.parse!('St. Hilaire, Matt')[0].values_at(:given, :family, :particle)).to eq(['Matt', 'Hilaire', 'St.'])
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context 'when include_particle_in_family is true' do
|
232
|
-
let(:parser) { Parser.new(include_particle_in_family: true) }
|
233
|
-
|
234
|
-
it 'parses common capitalized particles as the family name in display order' do
|
235
|
-
expect(parser.parse!('Carlos De Silva')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'De Silva', nil])
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'parses common capitalized particles with punctuation as the family name in display order' do
|
239
|
-
expect(parser.parse!('Matt St. Hilaire')[0].values_at(:given, :family, :particle)).to eq(['Matt', 'St. Hilaire', nil])
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'parses common lowercase particles as family name in display order' do
|
243
|
-
expect(parser.parse!('Carlos de Silva')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'de Silva', nil])
|
244
|
-
end
|
245
|
-
|
246
|
-
it 'parses common capitalized particles as the family name in sort order' do
|
247
|
-
expect(parser.parse!('De Silva, Carlos')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'De Silva', nil])
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'parses common lowercase particles as family name in sort order' do
|
251
|
-
expect(parser.parse!('de Silva, Carlos')[0].values_at(:given, :family, :particle)).to eq(['Carlos', 'de Silva', nil])
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'parses common capitalized particles with punctuation as the family name in display order' do
|
255
|
-
expect(parser.parse!('St. Hilaire, Matt')[0].values_at(:given, :family, :particle)).to eq(['Matt', 'St. Hilaire', nil])
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
data/spec/namae/utility_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
describe 'Namae' do
|
2
|
-
|
3
|
-
describe '.parse' do
|
4
|
-
it 'returns an empty list by default' do
|
5
|
-
expect(Namae.parse('')).to be_empty
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '.parse!' do
|
10
|
-
it 'returns an empty list by default' do
|
11
|
-
expect(Namae.parse!('')).to be_empty
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '.options' do
|
16
|
-
it 'returns the parse options' do
|
17
|
-
expect(Namae.options).to equal(Namae::Parser.instance.options)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'simplecov'
|
3
|
-
require 'coveralls' if ENV['CI']
|
4
|
-
rescue LoadError
|
5
|
-
# ignore
|
6
|
-
end unless RUBY_VERSION < '1.9'
|
7
|
-
|
8
|
-
begin
|
9
|
-
case
|
10
|
-
when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
11
|
-
require 'rubinius/debugger'
|
12
|
-
when RUBY_VERSION > '2.0'
|
13
|
-
require 'byebug'
|
14
|
-
else
|
15
|
-
require 'debugger'
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
# ignore
|
19
|
-
end
|
20
|
-
|
21
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
22
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
23
|
-
require 'rspec'
|
24
|
-
require 'namae'
|
25
|
-
|
26
|
-
# Requires supporting files with custom matchers and macros, etc,
|
27
|
-
# in ./support/ and its subdirectories.
|
28
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
29
|
-
|
30
|
-
RSpec.configure do |config|
|
31
|
-
|
32
|
-
end
|
data/spec/thread_safety_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Namae
|
2
|
-
describe 'Parser using threads' do
|
3
|
-
let(:name_1_str) { "Foo Bar" }
|
4
|
-
let(:name_2_str) { "Baz" }
|
5
|
-
let(:name_1) { Namae.parse(name_1_str).first }
|
6
|
-
let(:name_2) { Namae.parse(name_2_str).first }
|
7
|
-
|
8
|
-
def compare(string, expectation)
|
9
|
-
name = Namae.parse(string).first
|
10
|
-
given_name_match = expectation.given == name.given
|
11
|
-
family_name_match = expectation.family == name.family
|
12
|
-
raise unless given_name_match && family_name_match
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'has no conflicts' do
|
16
|
-
[[name_1_str, name_1], [name_2_str, name_2]].map do |string, expectation|
|
17
|
-
Thread.new do
|
18
|
-
1000.times do
|
19
|
-
compare(string, expectation)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end.each(&:join)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|