methodic 1.2 → 1.3

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.
@@ -1,18 +1,23 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{methodic}
3
3
  s.author = "Romain GEORGES"
4
- s.version = "1.2"
4
+ s.version = "1.3"
5
5
  s.date = %q{2013-02-18}
6
6
  s.summary = %q{Methodic : Hash table options specification and validation componant}
7
7
  s.email = %q{romain@ultragreen.net}
8
- s.homepage = %q{http://www.ultragreen.net}
8
+ s.homepage = %q{https://github.com/Ultragreen/methodic}
9
9
  s.description = %q{Methodic : provide Hash table options arguments manager (specifications and validations}
10
- s.has_rdoc = true
11
- s.files = Dir['*/*/*/*'] + Dir['*/*/*'] + Dir['*/*'] + Dir['*']
12
- s.bindir = nil
13
- s.required_ruby_version = '>= 1.8.1'
14
- s.add_development_dependency "rspec", ">= 2.0.0"
15
- s.rdoc_options << '--title' << 'Methodic : Gem documentation' << '--main' << 'doc/manual.rdoc' << '--line-numbers'
10
+ s.files = `git ls-files`.split($/)
11
+ s.require_paths = ["lib"]
12
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
+ s.add_development_dependency 'rake', '~> 13.0.1'
14
+ s.add_development_dependency 'rspec', '~> 3.9.0'
15
+ s.add_development_dependency 'yard', '~> 0.9.24'
16
+ s.add_development_dependency 'rdoc', '~> 6.2.1'
17
+ s.add_development_dependency 'roodi', '~> 5.0.0'
18
+ s.add_development_dependency 'code_statistics', '~> 0.2.13'
19
+ s.add_development_dependency 'yard-rspec', '~> 0.1'
20
+ s.rdoc_options << '--title' << 'Methodic : Gem documentation' << '--main' << 'doc/manual.rdoc' << '--line-numbers'
16
21
  # << '--diagram'
17
- s.rubyforge_project = "nowarning"
18
- end
22
+ s.license = "BSD-2-Clause"
23
+ end
@@ -1,203 +1,205 @@
1
1
  require'rubygems'
2
2
  require'rspec'
3
- require 'lib/methodic'
3
+ require 'methodic'
4
4
 
5
5
  describe Methodic do
6
-
6
+
7
7
  before :all do
8
8
  $test_methodic_options = Methodic::get_options :name => 'Doe', :surname => 'John'
9
9
  $test_methodic_options_with_known_options = Methodic::get_options({:name => 'Doe', :surname => 'John'},true)
10
10
  end
11
- before :each do
11
+ before :each do
12
12
  $test_methodic_options.mandatories.clear
13
13
  $test_methodic_options.formats = {}
14
14
  $test_methodic_options.defaults = {}
15
15
  $test_methodic_options.classes = {}
16
16
  end
17
17
  subject { Methodic }
18
- specify { subject.should be_an_instance_of Module}
19
- context Methodic::Options do
18
+ specify { expect(subject).to be_an_instance_of Module}
19
+ context Methodic::Options do
20
20
  subject { Methodic::Options }
21
- specify { subject.should be_an_instance_of Class }
21
+ specify { expect(subject).to be_an_instance_of Class }
22
22
  it "should respond to all methods of a Hash" do
23
23
  Hash::new.methods.each do |method|
24
- $test_methodic_options.should respond_to(method)
24
+ expect($test_methodic_options).to respond_to(method)
25
25
  end
26
26
  end
27
27
  context "#new(_options) (initialization)" do
28
28
  context "Exception case" do
29
29
  it "should raise ArgumentError if _options is not a Hash" do
30
30
  [ 'a string', 12 ,Array::new,true,false].each do |item|
31
- lambda{ Methodic::Options::new(item)}.should raise_error ArgumentError
31
+ expect { Methodic::Options::new(item) }.to raise_error(ArgumentError)
32
+
32
33
  end
33
34
  end
34
- it "should not raise ArgumentError if no arg is passed to initializer" do
35
- lambda{ Methodic::Options::new}.should_not raise_error
36
- end
37
- it "should not raise ArgumentError if an Hash arg is passed to initializer" do
38
- lambda{ Methodic::Options::new :name => 'Doe' }.should_not raise_error
39
- end
40
35
  it "should raise ArgumentError if an Hash arg is passed to initializer but with keys different of Symbol" do
41
- lambda{ Methodic::Options::new 'titi' => 'tutu'}.should raise_error ArgumentError
36
+ expect { Methodic::Options::new({'titi' => 'tutu'}) }.to raise_error(ArgumentError)
42
37
  end
43
- it "should not raise ArgumentError if two arg is passed to initializer, second arg has a boolean value, must be object" do
44
- lambda{ Methodic::Options::new({:name => 'Doe'},true) }.should_not raise_error ArgumentError
45
- end
46
-
47
38
  it "should raise ArgumentError if more than two arg is passed to initializer" do
48
- lambda{ Methodic::Options::new({:name => 'Doe'},{:surname => 'John'},true) }.should raise_error ArgumentError
39
+ expect { Methodic::Options::new({:name => 'Doe'},{:surname => 'John'},true) }.to raise_error(ArgumentError)
49
40
  end
50
-
41
+
51
42
  end
52
43
 
53
44
  end
54
45
  context "Instance Attributs" do
55
46
  context "#classes R/W" do
56
- it { $test_methodic_options.should respond_to("classes") }
57
- it { $test_methodic_options.should respond_to("classes=") }
47
+ specify { expect($test_methodic_options).to respond_to("classes") }
48
+ specify { expect($test_methodic_options).to respond_to("classes=") }
58
49
 
59
- it "should be true that #classes must return a Hash" do
60
- $test_methodic_options.classes.class.should eq(Hash)
50
+ it "should be true that #classes must return a Hash" do
51
+ expect($test_methodic_options.classes.class).to eq(Hash)
61
52
  end
62
53
  it "#classes[] affectation must be possible and #classes must respond this affectation" do
63
54
  $test_methodic_options.classes[:test] = String
64
- $test_methodic_options.classes.should eq({:test => String})
55
+ expect($test_methodic_options.classes).to eq({:test => String})
65
56
  end
66
-
57
+
67
58
  end
68
59
  context "#defaults R/W" do
69
- it { $test_methodic_options.should respond_to("defaults") }
70
- it { $test_methodic_options.should respond_to("defaults=") }
71
-
60
+
61
+ specify { expect($test_methodic_options).to respond_to("defaults") }
62
+ specify { expect($test_methodic_options).to respond_to("defaults=") }
63
+
64
+ specify { expect($test_methodic_options).to respond_to("toto") }
65
+ specify { expect($test_methodic_options).to respond_to("toto=") }
66
+
72
67
  it "should be true that #defaults must return a Hash" do
73
- $test_methodic_options.defaults.class.should eq(Hash)
68
+ expect($test_methodic_options.defaults.class).to eq(Hash)
74
69
  end
75
70
  it "#defaults[] affectation must be possible and #defaults must respond this affectation" do
76
71
  $test_methodic_options.defaults[:test] = "value"
77
- $test_methodic_options.defaults.should eq({ :test => "value"})
72
+ expect($test_methodic_options.defaults).to eq({ :test => "value"})
78
73
  end
79
74
  end
80
75
 
81
76
  context "#formats R/W" do
82
- it { $test_methodic_options.should respond_to("formats") }
83
- it { $test_methodic_options.should respond_to("formats=") }
84
-
77
+
78
+ specify { expect($test_methodic_options).to respond_to("formats") }
79
+ specify { expect($test_methodic_options).to respond_to("formats=") }
80
+
81
+
85
82
  it "should be true that #formats must return a Hash" do
86
- $test_methodic_options.formats.class.should eq(Hash)
83
+ expect($test_methodic_options.formats.class).to eq(Hash)
87
84
  end
88
85
  it "#formats[] affectation must be possible and #formats must respond this affectation" do
89
- $test_methodic_options.formats[:test] = '.*'
90
- $test_methodic_options.formats.should eq({ :test => '.*' })
86
+ $test_methodic_options.formats[:test] = '.*'
87
+ expect($test_methodic_options.formats).to eq({ :test => '.*' })
91
88
  end
92
89
  end
93
90
 
94
91
  context "#conditions R/W" do
95
- it { $test_methodic_options.should respond_to("conditions") }
96
- it { $test_methodic_options.should respond_to("conditions=") }
97
-
92
+
93
+ specify { expect($test_methodic_options).to respond_to("conditions") }
94
+ specify { expect($test_methodic_options).to respond_to("conditions=") }
95
+
96
+
98
97
  it "should be true that #conditions must return a Hash" do
99
- $test_methodic_options.conditions.class.should eq(Hash)
98
+ expect($test_methodic_options.conditions.class).to eq(Hash)
100
99
  end
100
+
101
101
  it "#formats[] affectation must be possible and #formats must respond this affectation" do
102
102
  aCond = Proc::new do |option| case option
103
103
  when 'Doe' then true
104
104
  else false
105
105
  end
106
106
  end
107
- $test_methodic_options.conditions[:name] = aCond
108
- $test_methodic_options.conditions.should eq({ :name => aCond })
107
+ $test_methodic_options.conditions[:name] = aCond
108
+ expect($test_methodic_options.conditions).to eq({ :name => aCond })
109
109
  end
110
110
  end
111
111
 
112
112
  context "#mandatories R/W" do
113
- it { $test_methodic_options.should respond_to("mandatories") }
114
- it { $test_methodic_options.should respond_to("mandatories=") }
113
+ specify { expect($test_methodic_options).to respond_to("mandatories") }
114
+ specify { expect($test_methodic_options).to respond_to("mandatories=") }
115
115
 
116
116
  it "should be true that #mandatories must return a List < Array" do
117
- $test_methodic_options.mandatories.class.should eq(List)
117
+ expect($test_methodic_options.mandatories.class).to eq(List)
118
118
  end
119
119
  it "#mandatories.push affectation must be possible and #mandatories must respond this affectation" do
120
120
  $test_methodic_options.mandatories.push :test
121
- $test_methodic_options.mandatories.should eq([:test])
121
+ expect($test_methodic_options.mandatories).to eq([:test])
122
122
  end
123
123
  context "#mandatories.push" do
124
124
  it "should not duplicate entry"do
125
125
  $test_methodic_options.mandatories.push :test
126
126
  $test_methodic_options.mandatories.push :test
127
- $test_methodic_options.mandatories.count(:test).should eq 1
127
+ expect($test_methodic_options.mandatories.count(:test)).to eq 1
128
128
  end
129
129
  end
130
130
  end
131
131
 
132
132
 
133
133
  context "#known R/W" do
134
- it { $test_methodic_options.should respond_to("known") }
135
- it { $test_methodic_options.should respond_to("known=") }
136
-
134
+ specify { expect($test_methodic_options).to respond_to("known") }
135
+ specify { expect($test_methodic_options).to respond_to("known=") }
136
+
137
137
  it "should be true that #known must return a List < Array" do
138
- $test_methodic_options.known.class.should eq(List)
138
+ expect($test_methodic_options.known.class).to eq(List)
139
139
  end
140
140
  it "#known.push affectation must be possible and #known must respond this affectation" do
141
141
  $test_methodic_options.known.push :test
142
- $test_methodic_options.known.should include :test
142
+ expect($test_methodic_options.known).to include :test
143
143
  end
144
144
  context "#known.push" do
145
145
  it "should not duplicate entry" do
146
146
  $test_methodic_options.known.push :test
147
147
  $test_methodic_options.known.push :test
148
- $test_methodic_options.known.count(:test).should eq 1
148
+ expect($test_methodic_options.known.count(:test)).to eq 1
149
149
  end
150
150
  end
151
151
  end
152
152
  end
153
153
  context "Instance methods" do
154
-
154
+
155
155
 
156
156
 
157
157
 
158
158
  context "#options" do
159
- it { $test_methodic_options.should respond_to("options") }
159
+ specify { expect($test_methodic_options).to respond_to("options") }
160
160
  it "should be true that #options must return a Array" do
161
- $test_methodic_options.options.class.should eq(Array)
161
+ expect($test_methodic_options.options.class).to eq(Array)
162
162
  end
163
163
  it "should respond an Array of options keys" do
164
164
  $test_methodic_options.options.each do |item|
165
- [:name,:surname].should include item
166
- end
165
+ expect([:name,:surname]).to include item
166
+ end
167
167
  end
168
168
  end
169
-
169
+
170
170
  context "#specify_default_value" do
171
- it { $test_methodic_options.should respond_to("specify_default_value") }
172
- it { $test_methodic_options.should respond_to("specify_defaults_values") }
171
+ specify { expect($test_methodic_options).to respond_to("specify_default_value") }
172
+ specify { expect($test_methodic_options).to respond_to("specify_defaults_values") }
173
+
173
174
  it "should merge default value hash record in defaults attribut" do
174
175
 
175
176
  $test_methodic_options.specify_default_value :test => 'value'
176
- $test_methodic_options.defaults[:test].should eq 'value'
177
- $test_methodic_options.defaults.count.should eq 1
177
+ expect($test_methodic_options.defaults[:test]).to eq 'value'
178
+ expect($test_methodic_options.defaults.count).to eq 1
178
179
  end
179
- it "should redefine a new default value for a previous key" do
180
+ it "should redefine a new default value for a previous key" do
180
181
  $test_methodic_options.specify_default_value :test => 'value'
181
- $test_methodic_options.defaults[:test].should eq 'value'
182
+ expect($test_methodic_options.defaults[:test]).to eq 'value'
182
183
  $test_methodic_options.specify_default_value :test => 'newvalue'
183
- $test_methodic_options.defaults[:test].should eq 'newvalue'
184
+ expect($test_methodic_options.defaults[:test]).to eq 'newvalue'
184
185
  end
185
186
  end
186
-
187
- context "#specify_class_of" do
188
- it { $test_methodic_options.should respond_to("specify_class_of") }
189
- it { $test_methodic_options.should respond_to("specify_classes_of") }
187
+
188
+ context "#specify_class_of" do
189
+ specify { expect($test_methodic_options).to respond_to("specify_class_of") }
190
+ specify { expect($test_methodic_options).to respond_to("specify_classes_of") }
191
+
190
192
  it "should merge class hash record in classes attribut" do
191
193
 
192
194
  $test_methodic_options.specify_class_of :test => String
193
- $test_methodic_options.classes[:test].should eq String
194
- $test_methodic_options.classes.count.should eq 1
195
+ expect($test_methodic_options.classes[:test]).to eq String
196
+ expect($test_methodic_options.classes.count).to eq 1
195
197
  end
196
198
  it "should redefine a new class value for a previous key" do
197
199
  $test_methodic_options.specify_class_of :test => String
198
- $test_methodic_options.classes[:test].should eq String
200
+ expect($test_methodic_options.classes[:test]).to eq String
199
201
  $test_methodic_options.specify_class_of :test => Integer
200
- $test_methodic_options.classes[:test].should eq Integer
202
+ expect($test_methodic_options.classes[:test]).to eq Integer
201
203
 
202
204
  end
203
205
  end
@@ -207,17 +209,18 @@ describe Methodic do
207
209
 
208
210
 
209
211
  context "#specify_condition_for" do
210
- it { $test_methodic_options.should respond_to("specify_condition_for") }
211
- it { $test_methodic_options.should respond_to("specify_conditions_for") }
212
+ specify { expect($test_methodic_options).to respond_to("specify_condition_for") }
213
+ specify { expect($test_methodic_options).to respond_to("specify_conditions_for") }
214
+
212
215
  it "should merge condition hash record in conditions attribut" do
213
216
  aCond = Proc::new do |option| case option
214
217
  when "Doe" then true
215
218
  else false
216
219
  end
217
220
  end
218
- $test_methodic_options.specify_condition_for :name => aCond
219
- $test_methodic_options.conditions[:name].should eq aCond
220
- $test_methodic_options.conditions.count.should eq 1
221
+ $test_methodic_options.specify_condition_for :name => aCond
222
+ expect($test_methodic_options.conditions[:name]).to eq aCond
223
+ expect($test_methodic_options.conditions.count).to eq 1
221
224
  end
222
225
  it "should redefine a new class value for a previous key" do
223
226
  aCond = Proc::new do |option| case option
@@ -230,41 +233,42 @@ describe Methodic do
230
233
  else false
231
234
  end
232
235
  end
233
- $test_methodic_options.specify_condition_for :name => aCond
234
- $test_methodic_options.conditions[:name].should eq aCond
235
- $test_methodic_options.specify_condition_for :name => newCond
236
- $test_methodic_options.conditions[:name].should eq newCond
236
+ $test_methodic_options.specify_condition_for :name => aCond
237
+ expect($test_methodic_options.conditions[:name]).to eq aCond
238
+ $test_methodic_options.specify_condition_for :name => newCond
239
+ expect($test_methodic_options.conditions[:name]).to eq newCond
237
240
  $test_methodic_options.conditions = {}
238
241
  end
239
242
  end
240
243
 
241
244
  context "#specify_format_of" do
242
- it { $test_methodic_options.should respond_to("specify_format_of") }
243
- it { $test_methodic_options.should respond_to("specify_formats_of") }
245
+ specify { expect($test_methodic_options).to respond_to("specify_format_of") }
246
+ specify { expect($test_methodic_options).to respond_to("specify_formats_of") }
244
247
  it "should merge format hash record in formats attribut" do
245
248
  $test_methodic_options.formats = {}
246
249
  $test_methodic_options.specify_format_of :test => '.*'
247
- $test_methodic_options.formats[:test].should eq '.*'
248
- $test_methodic_options.formats.count.should eq 1
250
+ expect($test_methodic_options.formats[:test]).to eq '.*'
251
+ expect($test_methodic_options.formats.count).to eq 1
249
252
  end
250
253
  it "should redefine a new format value for a previous format key" do
251
254
  $test_methodic_options.specify_format_of :test => '.*'
252
- $test_methodic_options.formats[:test].should eq '.*'
255
+ expect($test_methodic_options.formats[:test]).to eq '.*'
253
256
  $test_methodic_options.specify_format_of :test => '\d*'
254
- $test_methodic_options.formats[:test].should eq '\d*'
257
+ expect($test_methodic_options.formats[:test]).to eq '\d*'
255
258
  end
256
259
  end
257
260
 
258
261
  context "#specify_presence_of" do
259
- it { $test_methodic_options.should respond_to("specify_presence_of") }
260
- it { $test_methodic_options.should respond_to("specify_presences_of") }
262
+ specify { expect($test_methodic_options).to respond_to("specify_presence_of") }
263
+ specify { expect($test_methodic_options).to respond_to("specify_presences_of") }
264
+
261
265
  it "should merge presence Array record in mandatories attribut" do
262
266
  $test_methodic_options.specify_presence_of :test
263
- $test_methodic_options.mandatories.should include(:test)
264
- $test_methodic_options.mandatories.count.should eq 1
267
+ expect($test_methodic_options.mandatories).to include(:test)
268
+ expect($test_methodic_options.mandatories.count).to eq 1
265
269
  $test_methodic_options.specify_presence_of :test
266
- $test_methodic_options.mandatories.should include(:test)
267
- $test_methodic_options.mandatories.count.should eq 1
270
+ expect($test_methodic_options.mandatories).to include(:test)
271
+ expect($test_methodic_options.mandatories.count).to eq 1
268
272
  end
269
273
  it "should be possible to give arguments list of symbols" do
270
274
  $test_methodic_options.specify_presences_of :test2, :test3, :test4
@@ -273,141 +277,87 @@ describe Methodic do
273
277
  end
274
278
 
275
279
  context "#specify_known_option" do
276
- it { $test_methodic_options.should respond_to("specify_known_option") }
277
- it { $test_methodic_options.should respond_to("specify_known_options") }
280
+ specify { expect($test_methodic_options).to respond_to("specify_known_option") }
281
+ specify { expect($test_methodic_options).to respond_to("specify_known_options") }
282
+
278
283
  it "should merge known Array record in known attribut" do
279
284
  $test_methodic_options.specify_known_option :test
280
- $test_methodic_options.known.should include(:test)
281
- $test_methodic_options.known.count.should eq 1
285
+ expect($test_methodic_options.known).to include(:test)
286
+ expect($test_methodic_options.known.count).to eq 1
282
287
  $test_methodic_options.specify_known_option :test
283
- $test_methodic_options.known.should include(:test)
284
- $test_methodic_options.known.count.should eq 1
288
+ expect($test_methodic_options.known).to include(:test)
289
+ expect($test_methodic_options.known.count).to eq 1
285
290
  end
286
291
  it "should be possible to give arguments list of symbols" do
287
292
  $test_methodic_options.specify_known_options :test2, :test3, :test4
288
293
  $test_methodic_options.specify_known_options [ :test5, :test6 ], :test7
289
-
294
+
290
295
  end
291
296
  end
292
297
 
293
298
  context "#validate" do
294
-
295
- it { $test_methodic_options.should respond_to("validate") }
296
- it { $test_methodic_options.should respond_to("validate!") }
297
-
298
-
299
- context "1/ validate known options" do
300
- context "@validate_known_options = false (default)" do
301
- it "should not raise ArgumentError if mandatories is not fully include in the known options list" do
302
- $test_methodic_options.known = []
303
- $test_methodic_options.specify_presences_of [ :name, :surname]
304
- $test_methodic_options.specify_known_options [ :surname]
305
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
306
- end
307
- it "should not raise ArgumentError if an option in options list not in the known options list" do
308
- $test_methodic_options.known = []
309
- $test_methodic_options.specify_known_options [ :surname ]
310
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
311
- end
312
- it "should not raise if all given options in options list is in known options " do
313
- $test_methodic_options.known = []
314
- $test_methodic_options.specify_known_options [ :name, :surname, :optional ]
315
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
316
- end
317
- it "should not raise ArgumentError if formats made a reference to an unknown options" do
318
- $test_methodic_options.known = []
319
- $test_methodic_options.specify_format_of :nickname => /.*/
320
- $test_methodic_options.specify_known_options [ :surname, :name ]
321
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
322
- end
323
- it "should not raise ArgumentError if classes made a reference to an unknown options" do
324
- $test_methodic_options.known = []
325
- $test_methodic_options[:nickname] = 'Jeedoe'
326
- $test_methodic_options.specify_class_of :nickname => String
327
- $test_methodic_options.specify_known_options [ :surname, :name ]
328
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
329
- end
330
- it "should not raise ArgumentError if default made a reference to an unknown options" do
331
- $test_methodic_options.known = []
332
- $test_methodic_options.specify_default_value :nickname => 'Jeedoe'
333
- $test_methodic_options.specify_known_options [ :surname, :name ]
334
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
335
- end
336
299
 
337
- end
338
- context "@validate_known_options = true" do
300
+ specify { expect($test_methodic_options).to respond_to("validate") }
301
+ specify { expect($test_methodic_options).to respond_to("validate!") }
302
+
303
+
304
+ context "1/ validate known options" do
305
+ context "@validate_known_options = true" do
339
306
  it "should raise ArgumentError if mandatories is not fully include in the known options list" do
340
307
  $test_methodic_options_with_known_options.known = []
341
308
  $test_methodic_options_with_known_options.specify_presences_of [ :name, :surname ]
342
309
  $test_methodic_options_with_known_options.specify_known_options [ :surname ]
343
- lambda{$test_methodic_options_with_known_options.validate!}.should raise_error ArgumentError
310
+ expect { $test_methodic_options_with_known_options.validate! }.to raise_error(ArgumentError)
344
311
  end
345
312
  it "should raise ArgumentError if an option in options list not in the known options list" do
346
313
  $test_methodic_options_with_known_options.known = []
347
314
  $test_methodic_options_with_known_options.specify_known_options [ :surname]
348
- lambda{$test_methodic_options_with_known_options.validate!}.should raise_error ArgumentError
349
- end
350
- it "should not raise if all given options in options list is in known options " do
351
- $test_methodic_options_with_known_options.known = []
352
- $test_methodic_options_with_known_options.specify_known_options [ :name, :surname,:optional]
353
- lambda{$test_methodic_options_with_known_options.validate!}.should_not raise_error ArgumentError
315
+ expect { $test_methodic_options_with_known_options.validate! }.to raise_error(ArgumentError)
354
316
  end
355
317
  it "should raise ArgumentError if formats made a reference to an unknown options" do
356
318
  $test_methodic_options_with_known_options.known = []
357
319
  $test_methodic_options_with_known_options.specify_format_of :nickname => /.*/
358
320
  $test_methodic_options_with_known_options.specify_known_options [ :surname, :name ]
359
- lambda{$test_methodic_options_with_known_options.validate!}.should raise_error ArgumentError
321
+ expect { $test_methodic_options_with_known_options.validate! }.to raise_error(ArgumentError)
360
322
  end
361
323
  it "should raise ArgumentError if classes made a reference to an unknown options" do
362
324
  $test_methodic_options_with_known_options.known = []
363
325
  $test_methodic_options_with_known_options[:nickname] = 'Jeedoe'
364
326
  $test_methodic_options_with_known_options.specify_class_of :nickname => String
365
327
  $test_methodic_options_with_known_options.specify_known_options [ :surname, :name ]
366
- lambda{$test_methodic_options_with_known_options.validate!}.should raise_error ArgumentError
328
+ expect { $test_methodic_options_with_known_options.validate! }.to raise_error(ArgumentError)
367
329
  end
368
330
  it "should raise ArgumentError if default made a reference to an unknown options" do
369
331
  $test_methodic_options_with_known_options.known = []
370
332
  $test_methodic_options_with_known_options.specify_default_value :nickname => 'Jeedoe'
371
333
  $test_methodic_options_with_known_options.specify_known_options [ :surname, :name ]
372
- lambda{$test_methodic_options_with_known_options.validate!}.should raise_error ArgumentError
334
+ expect { $test_methodic_options_with_known_options.validate! }.to raise_error(ArgumentError)
373
335
  end
374
-
336
+
375
337
  end
376
-
338
+
377
339
  end
378
340
 
379
341
  context "2/ validate classes" do
380
- it "should raise ArgumentError if an options don't match a class definition" do
342
+ it "should raise ArgumentError if an options don't match a class definition" do
381
343
  $test_methodic_options.specify_classes_of :name => Integer, :surname => String
382
- lambda{$test_methodic_options.validate!}.should raise_error ArgumentError
344
+ expect { $test_methodic_options.validate! }.to raise_error(ArgumentError)
383
345
 
384
346
  end
385
- it "should not raise if options match class definition" do
386
- $test_methodic_options.specify_classes_of :name => String, :surname => String
387
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
388
- end
389
347
  end
390
348
  context "3/ validate mandatories" do
391
349
  it "should raise ArgumentError if a mandatory option not in options list" do
392
350
  $test_methodic_options.specify_presences_of [ :name , :surname, :nickname, :age ]
393
- lambda{$test_methodic_options.validate!}.should raise_error ArgumentError
351
+ expect { $test_methodic_options.validate! }.to raise_error(ArgumentError)
394
352
 
395
353
  end
396
- it "should not raise if mandatory options and options list match" do
397
- $test_methodic_options.specify_presences_of [ :name , :surname ]
398
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
399
- end
400
354
  end
401
355
  context "4/ validate formats" do
402
356
  it "should raise ArgumentError if an option in options list not have the good registered formats" do
403
357
  $test_methodic_options.specify_formats_of :name => /.*/, :surname => /toto.*/
404
- lambda{$test_methodic_options.validate!}.should raise_error ArgumentError
358
+ expect { $test_methodic_options.validate! }.to raise_error(ArgumentError)
405
359
 
406
360
  end
407
- it "should not raise if all options in options list match formats definitions " do
408
- $test_methodic_options.specify_formats_of :name => /.*/, :surname => /.*/
409
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
410
- end
411
361
  end
412
362
  context "5/ validate conditions" do
413
363
  it "should raise ArgumentError if an option in options list not validate a registered condition" do
@@ -418,33 +368,24 @@ describe Methodic do
418
368
  end
419
369
  end
420
370
  $test_methodic_options.specify_condition_for :name => aCond
421
- lambda{$test_methodic_options.validate!}.should raise_error ArgumentError
371
+ expect { $test_methodic_options.validate! }.to raise_error(ArgumentError)
422
372
 
423
373
  end
424
- it "should not raise if all options in options list match formats definitions " do
425
- $test_methodic_options.conditions = {}
426
- aCond = Proc::new do |option| case option
427
- when 'Doe' then true
428
- else false
429
- end
430
- end
431
- $test_methodic_options.specify_condition_for :name => aCond
432
- lambda{$test_methodic_options.validate!}.should_not raise_error ArgumentError
433
- end
434
374
  end
435
375
 
436
376
 
437
377
 
438
- end
378
+ end
439
379
  context "#merge_with_defaults" do
440
- it { $test_methodic_options.should respond_to("merge_with_defaults") }
441
- it { $test_methodic_options.should respond_to("merge") }
442
- it "should merge defaults values and don't override with options" do
380
+ specify { expect($test_methodic_options).to respond_to("merge_with_defaults") }
381
+ specify { expect($test_methodic_options).to respond_to("merge") }
382
+
383
+ it "should merge defaults values and don't override with options" do
443
384
  $test_methodic_options.specify_defaults_values :name => 'Smith', :surname => 'Paul', :nickname => 'Jeedoe'
444
385
  $test_methodic_options.merge_with_defaults
445
- $test_methodic_options[:name].should eq "Doe"
446
- $test_methodic_options[:surname].should eq "John"
447
- $test_methodic_options[:nickname].should eq "Jeedoe"
386
+ expect($test_methodic_options[:name]).to eq "Doe"
387
+ expect($test_methodic_options[:surname]).to eq "John"
388
+ expect($test_methodic_options[:nickname]).to eq "Jeedoe"
448
389
 
449
390
  end
450
391
  end
@@ -452,8 +393,8 @@ describe Methodic do
452
393
  end
453
394
  context "Methodic::get_options" do
454
395
  it "should return a Methodic::Options Object" do
455
- Methodic::get_options({:name => 'Doe', :surname => 'John'}).should be_an_instance_of Methodic::Options
396
+ expect(Methodic::get_options({:name => 'Doe', :surname => 'John'})).to be_an_instance_of Methodic::Options
456
397
  end
457
398
  end
458
-
459
- end
399
+
400
+ end