roxml 3.3.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +7 -0
- data/Gemfile +9 -6
- data/Gemfile.lock +96 -40
- data/History.txt +9 -0
- data/README.rdoc +3 -2
- data/Rakefile +6 -9
- data/VERSION +1 -1
- data/examples/search_query.rb +17 -0
- data/lib/roxml.rb +8 -2
- data/lib/roxml/definition.rb +2 -7
- data/lib/roxml/xml/references.rb +22 -7
- data/roxml.gemspec +48 -36
- data/spec/definition_spec.rb +81 -101
- data/spec/examples/active_record_spec.rb +13 -13
- data/spec/examples/amazon_spec.rb +13 -13
- data/spec/examples/current_weather_spec.rb +6 -6
- data/spec/examples/dashed_elements_spec.rb +3 -3
- data/spec/examples/library_spec.rb +3 -3
- data/spec/examples/library_with_fines_spec.rb +7 -7
- data/spec/examples/person_spec.rb +3 -3
- data/spec/examples/post_spec.rb +4 -4
- data/spec/examples/search_query_spec.rb +26 -0
- data/spec/examples/twitter_spec.rb +4 -4
- data/spec/reference_spec.rb +2 -2
- data/spec/regression_spec.rb +13 -8
- data/spec/roxml_spec.rb +30 -43
- data/spec/shared_specs.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/xml/array_spec.rb +2 -2
- data/spec/xml/attributes_spec.rb +7 -7
- data/spec/xml/encoding_spec.rb +9 -9
- data/spec/xml/namespace_spec.rb +40 -21
- data/spec/xml/namespaces_spec.rb +3 -3
- data/spec/xml/object_spec.rb +7 -7
- data/spec/xml/parser_spec.rb +2 -2
- data/spec/xml/text_spec.rb +6 -6
- data/test/fixtures/book_with_octal_pages.xml +2 -3
- data/test/test_helper.rb +1 -2
- data/test/unit/definition_test.rb +26 -27
- data/test/unit/deprecations_test.rb +23 -2
- data/test/unit/to_xml_test.rb +7 -7
- data/test/unit/xml_attribute_test.rb +3 -2
- data/test/unit/xml_block_test.rb +3 -2
- data/test/unit/xml_bool_test.rb +7 -8
- data/test/unit/xml_convention_test.rb +4 -3
- data/test/unit/xml_hash_test.rb +5 -13
- data/test/unit/xml_initialize_test.rb +4 -3
- data/test/unit/xml_name_test.rb +3 -2
- data/test/unit/xml_namespace_test.rb +4 -3
- data/test/unit/xml_object_test.rb +8 -7
- data/test/unit/xml_required_test.rb +7 -6
- data/test/unit/xml_text_test.rb +3 -2
- data/website/index.html +11 -11
- metadata +115 -60
data/spec/definition_spec.rb
CHANGED
@@ -4,19 +4,19 @@ require_relative './spec_helper'
|
|
4
4
|
describe ROXML::Definition do
|
5
5
|
describe "#name_explicit?" do
|
6
6
|
it "should indicate whether from option is present" do
|
7
|
-
ROXML::Definition.new(:element, :from => 'somewhere').name_explicit
|
8
|
-
ROXML::Definition.new(:element).name_explicit
|
7
|
+
expect(ROXML::Definition.new(:element, :from => 'somewhere').name_explicit?).to be_truthy
|
8
|
+
expect(ROXML::Definition.new(:element).name_explicit?).to be_falsey
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should not consider name proxies as explicit" do
|
12
|
-
ROXML::Definition.new(:element, :from => :attr).name_explicit
|
13
|
-
ROXML::Definition.new(:element, :from => :content).name_explicit
|
12
|
+
expect(ROXML::Definition.new(:element, :from => :attr).name_explicit?).to be_falsey
|
13
|
+
expect(ROXML::Definition.new(:element, :from => :content).name_explicit?).to be_falsey
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
shared_examples_for "DateTime reference" do
|
18
18
|
it "should return nil on empty string" do
|
19
|
-
@subject.blocks.first.call(" ").
|
19
|
+
expect(@subject.blocks.first.call(" ")).to be_nil
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should return a time version of the string" do
|
@@ -25,14 +25,14 @@ describe ROXML::Definition do
|
|
25
25
|
|
26
26
|
context "when passed an array of values" do
|
27
27
|
it "should timify all of them" do
|
28
|
-
@subject.blocks.first.call(["12:05pm, September 3rd, 1970", "3:00pm, May 22, 1700"]).map(&:to_s).
|
28
|
+
expect(@subject.blocks.first.call(["12:05pm, September 3rd, 1970", "3:00pm, May 22, 1700"]).map(&:to_s)).to eq(["1970-09-03T12:05:00+00:00", "1700-05-22T15:00:00+00:00"])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
shared_examples_for "Date reference" do
|
34
34
|
it "should return nil on empty string" do
|
35
|
-
@subject.blocks.first.call(" ").
|
35
|
+
expect(@subject.blocks.first.call(" ")).to be_nil
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should return a time version of the string" do
|
@@ -41,26 +41,26 @@ describe ROXML::Definition do
|
|
41
41
|
|
42
42
|
context "when passed an array of values" do
|
43
43
|
it "should timify all of them" do
|
44
|
-
@subject.blocks.first.call(["September 3rd, 1970", "1776-07-04"]).map(&:to_s).
|
44
|
+
expect(@subject.blocks.first.call(["September 3rd, 1970", "1776-07-04"]).map(&:to_s)).to eq(["1970-09-03", "1776-07-04"])
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should unescape xml entities" do
|
50
|
-
ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
|
50
|
+
expect(ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
|
51
51
|
<xml>
|
52
52
|
<question>"Wickard & Filburn" ></question>
|
53
53
|
<question> < McCulloch & Maryland?</question>
|
54
54
|
</xml>
|
55
|
-
}).
|
55
|
+
})).to eq(["\"Wickard & Filburn\" >", " < McCulloch & Maryland?"])
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should unescape utf characters in xml" do
|
59
|
-
ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
|
59
|
+
expect(ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
|
60
60
|
<xml>
|
61
61
|
<question>ROXML\342\204\242</question>
|
62
62
|
</xml>
|
63
|
-
}).
|
63
|
+
})).to eq(["ROXML™"])
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "attr name" do
|
@@ -87,8 +87,8 @@ describe ROXML::Definition do
|
|
87
87
|
describe "=> []" do
|
88
88
|
it "should means array of texts" do
|
89
89
|
opts = ROXML::Definition.new(:authors, :as => [])
|
90
|
-
opts.array
|
91
|
-
opts.sought_type.
|
90
|
+
expect(opts.array?).to be_truthy
|
91
|
+
expect(opts.sought_type).to eq(:text)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -99,7 +99,7 @@ describe ROXML::Definition do
|
|
99
99
|
|
100
100
|
it "should store type" do
|
101
101
|
opts = ROXML::Definition.new(:name, :as => RoxmlClass)
|
102
|
-
opts.sought_type.
|
102
|
+
expect(opts.sought_type).to eq(RoxmlClass)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -112,35 +112,35 @@ describe ROXML::Definition do
|
|
112
112
|
|
113
113
|
it "should accept type" do
|
114
114
|
opts = ROXML::Definition.new(:name, :as => OctalInteger)
|
115
|
-
opts.sought_type.
|
115
|
+
expect(opts.sought_type).to eq(OctalInteger)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "=> NonRoxmlClass" do
|
120
120
|
it "should fail with a warning" do
|
121
|
-
|
121
|
+
expect { ROXML::Definition.new(:authors, :as => Module) }.to raise_error(ArgumentError)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
125
|
describe "=> [NonRoxmlClass]" do
|
126
126
|
it "should raise" do
|
127
|
-
|
127
|
+
expect { ROXML::Definition.new(:authors, :as => [Module]) }.to raise_error(ArgumentError)
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
describe "=> {}" do
|
132
132
|
shared_examples_for "hash options declaration" do
|
133
133
|
it "should represent a hash" do
|
134
|
-
@opts.hash
|
134
|
+
expect(@opts.hash?).to be_truthy
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should have hash definition" do
|
138
|
-
{@opts.hash.key.sought_type => @opts.hash.key.name}.
|
139
|
-
{@opts.hash.value.sought_type => @opts.hash.value.name}.
|
138
|
+
expect({@opts.hash.key.sought_type => @opts.hash.key.name}).to eq(@hash_args[:key])
|
139
|
+
expect({@opts.hash.value.sought_type => @opts.hash.value.name}).to eq(@hash_args[:value])
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should not represent an array" do
|
143
|
-
@opts.array
|
143
|
+
expect(@opts.array?).to be_falsey
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -193,32 +193,32 @@ describe ROXML::Definition do
|
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should be detected as array reference" do
|
196
|
-
@opts.array
|
196
|
+
expect(@opts.array?).to be_truthy
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should be normal otherwise" do
|
200
|
-
@opts.sought_type.
|
201
|
-
@opts.blocks.size.
|
200
|
+
expect(@opts.sought_type).to eq(:text)
|
201
|
+
expect(@opts.blocks.size).to eq(1)
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should have no blocks without a shorthand" do
|
206
|
-
ROXML::Definition.new(:count).blocks.
|
206
|
+
expect(ROXML::Definition.new(:count).blocks).to be_empty
|
207
207
|
end
|
208
208
|
|
209
209
|
it "should raise on unknown :as" do
|
210
|
-
|
211
|
-
|
210
|
+
expect { ROXML::Definition.new(:count, :as => :bogus) }.to raise_error(ArgumentError)
|
211
|
+
expect { ROXML::Definition.new(:count, :as => :foat) }.to raise_error(ArgumentError)
|
212
212
|
end
|
213
213
|
|
214
214
|
shared_examples_for "block shorthand type declaration" do
|
215
215
|
it "should translate nil to nil" do
|
216
|
-
@definition.blocks.first.call(nil).
|
216
|
+
expect(@definition.blocks.first.call(nil)).to be_nil
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should translate empty strings to nil" do
|
220
|
-
@definition.blocks.first.call("").
|
221
|
-
@definition.blocks.first.call(" ").
|
220
|
+
expect(@definition.blocks.first.call("")).to be_nil
|
221
|
+
expect(@definition.blocks.first.call(" ")).to be_nil
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
@@ -230,20 +230,21 @@ describe ROXML::Definition do
|
|
230
230
|
it_should_behave_like "block shorthand type declaration"
|
231
231
|
|
232
232
|
it "should translate text to integers" do
|
233
|
-
@definition.blocks.first['3'].
|
234
|
-
@definition.blocks.first['792'].
|
233
|
+
expect(@definition.blocks.first['3']).to eq(3)
|
234
|
+
expect(@definition.blocks.first['792']).to eq(792)
|
235
|
+
expect(@definition.blocks.first['08']).to eq(8)
|
236
|
+
expect(@definition.blocks.first['279.23']).to eq(279)
|
235
237
|
end
|
236
238
|
|
237
|
-
it "should
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
proc { @definition.blocks.first['11sttf'] }.should raise_error(ArgumentError)
|
239
|
+
it "should extract whatever is possible and fall back to 0" do
|
240
|
+
expect(@definition.blocks.first['junk 11']).to eql(0)
|
241
|
+
expect(@definition.blocks.first['.?sttf']).to eql(0)
|
242
|
+
expect(@definition.blocks.first['11sttf']).to eql(11)
|
242
243
|
end
|
243
244
|
|
244
245
|
context "when passed an array" do
|
245
246
|
it "should translate the array elements to integer" do
|
246
|
-
@definition.blocks.first.call(["792", "12", "328"]).
|
247
|
+
expect(@definition.blocks.first.call(["792", "12", "328"])).to eq([792, 12, 328])
|
247
248
|
end
|
248
249
|
end
|
249
250
|
end
|
@@ -256,18 +257,18 @@ describe ROXML::Definition do
|
|
256
257
|
it_should_behave_like "block shorthand type declaration"
|
257
258
|
|
258
259
|
it "should translate text to float" do
|
259
|
-
@definition.blocks.first['3'].
|
260
|
-
@definition.blocks.first['12.7'].
|
260
|
+
expect(@definition.blocks.first['3']).to eq(3.0)
|
261
|
+
expect(@definition.blocks.first['12.7']).to eq(12.7)
|
261
262
|
end
|
262
263
|
|
263
264
|
it "should raise on non-float values" do
|
264
|
-
|
265
|
-
|
265
|
+
expect { @definition.blocks.first['junk 11.3'] }.to raise_error(ArgumentError)
|
266
|
+
expect { @definition.blocks.first['11.1sttf'] }.to raise_error(ArgumentError)
|
266
267
|
end
|
267
268
|
|
268
269
|
context "when passed an array" do
|
269
270
|
it "should translate the array elements to integer" do
|
270
|
-
@definition.blocks.first.call(["792.13", "240", "3.14"]).
|
271
|
+
expect(@definition.blocks.first.call(["792.13", "240", "3.14"])).to eq([792.13, 240.0, 3.14])
|
271
272
|
end
|
272
273
|
end
|
273
274
|
end
|
@@ -280,67 +281,46 @@ describe ROXML::Definition do
|
|
280
281
|
it_should_behave_like "block shorthand type declaration"
|
281
282
|
|
282
283
|
it "should translate text to decimal numbers" do
|
283
|
-
@definition.blocks.first['3'].
|
284
|
-
@definition.blocks.first['0.3'].
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should extract what it can, and fall back to 0" do
|
288
|
-
@definition.blocks.first['junk 11'].should eql(BigDecimal.new("0"))
|
289
|
-
@definition.blocks.first['11sttf'].should eql(BigDecimal.new("11.0"))
|
284
|
+
expect(@definition.blocks.first['3']).to eq(BigDecimal.new("3.0"))
|
285
|
+
expect(@definition.blocks.first['0.3']).to eq(BigDecimal.new("0.3"))
|
290
286
|
end
|
291
287
|
|
292
|
-
|
293
|
-
|
294
|
-
|
288
|
+
# Ruby behavior of BigDecimal changed in 2.4, this test is not valid on older rubies
|
289
|
+
if RUBY_VERSION >= "2.4"
|
290
|
+
it "should raise on non-decimal values" do
|
291
|
+
expect { @definition.blocks.first['junk 11'] }.to raise_error(ArgumentError)
|
295
292
|
end
|
296
293
|
end
|
297
|
-
end
|
298
294
|
|
299
|
-
|
300
|
-
|
301
|
-
@definition = ROXML::Definition.new(:fixnumvalue, :as => Fixnum)
|
302
|
-
end
|
303
|
-
|
304
|
-
it_should_behave_like "block shorthand type declaration"
|
305
|
-
|
306
|
-
it "should translate text to integers" do
|
307
|
-
@definition.blocks.first['3'].should == 3
|
308
|
-
@definition.blocks.first['792'].should == 792
|
309
|
-
@definition.blocks.first['08'].should == 8
|
310
|
-
@definition.blocks.first['279.23'].should == 279
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should extract whatever is possible and fall back to 0" do
|
314
|
-
@definition.blocks.first['junk 11'].should eql(0)
|
315
|
-
@definition.blocks.first['.?sttf'].should eql(0)
|
316
|
-
@definition.blocks.first['11sttf'].should eql(11)
|
295
|
+
it "should extract what it can" do
|
296
|
+
expect(@definition.blocks.first['11sttf']).to eql(BigDecimal.new("11.0"))
|
317
297
|
end
|
318
298
|
|
319
299
|
context "when passed an array" do
|
320
300
|
it "should translate the array elements to integer" do
|
321
|
-
@definition.blocks.first.call(["
|
301
|
+
expect(@definition.blocks.first.call(["12.1", "328.2"])).to eq([BigDecimal.new("12.1"), BigDecimal.new("328.2")])
|
322
302
|
end
|
323
303
|
end
|
324
304
|
end
|
325
305
|
|
326
306
|
describe ":bool" do
|
327
307
|
it "should boolify individual values" do
|
328
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("1").
|
329
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("True").
|
330
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("Yes").
|
308
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("1")).to be_truthy
|
309
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("True")).to be_truthy
|
310
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("Yes")).to be_truthy
|
331
311
|
end
|
332
312
|
|
333
313
|
context "when an array is passed in" do
|
334
314
|
it "should boolify arrays of values" do
|
335
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("0").
|
336
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("false").
|
337
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("nO").
|
315
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("0")).to be_falsey
|
316
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("false")).to be_falsey
|
317
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("nO")).to be_falsey
|
338
318
|
end
|
339
319
|
end
|
340
320
|
|
341
321
|
context "when no value is detected" do
|
342
322
|
it "should return nil" do
|
343
|
-
ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("junk").
|
323
|
+
expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("junk")).to be_nil
|
344
324
|
end
|
345
325
|
|
346
326
|
context "when a literal block is available" do
|
@@ -351,16 +331,16 @@ describe ROXML::Definition do
|
|
351
331
|
|
352
332
|
describe "Time" do
|
353
333
|
it "should return nil on empty string" do
|
354
|
-
ROXML::Definition.new(:floatvalue, :as => Time).blocks.first.call(" ").
|
334
|
+
expect(ROXML::Definition.new(:floatvalue, :as => Time).blocks.first.call(" ")).to be_nil
|
355
335
|
end
|
356
336
|
|
357
337
|
it "should return a time version of the string" do
|
358
|
-
ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call("12:31am").min.
|
338
|
+
expect(ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call("12:31am").min).to eq(31)
|
359
339
|
end
|
360
340
|
|
361
341
|
context "when passed an array of values" do
|
362
342
|
it "should timify all of them" do
|
363
|
-
ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call(["12:31am", "3:00pm", "11:59pm"]).map(&:min).
|
343
|
+
expect(ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call(["12:31am", "3:00pm", "11:59pm"]).map(&:min)).to eq([31, 0, 59])
|
364
344
|
end
|
365
345
|
end
|
366
346
|
end
|
@@ -380,12 +360,12 @@ describe ROXML::Definition do
|
|
380
360
|
end
|
381
361
|
|
382
362
|
it "should prohibit multiple shorthands" do
|
383
|
-
|
363
|
+
expect { ROXML::Definition.new(:count, :as => [Float, Integer]) }.to raise_error(ArgumentError)
|
384
364
|
end
|
385
365
|
|
386
366
|
it "should stack block shorthands with explicit blocks" do
|
387
|
-
ROXML::Definition.new(:count, :as => Integer) {|val| val.to_i }.blocks.size.
|
388
|
-
ROXML::Definition.new(:count, :as => Float) {|val| val.object_id }.blocks.size.
|
367
|
+
expect(ROXML::Definition.new(:count, :as => Integer) {|val| val.to_i }.blocks.size).to eq(2)
|
368
|
+
expect(ROXML::Definition.new(:count, :as => Float) {|val| val.object_id }.blocks.size).to eq(2)
|
389
369
|
end
|
390
370
|
end
|
391
371
|
end
|
@@ -393,17 +373,17 @@ describe ROXML::Definition do
|
|
393
373
|
describe ":from" do
|
394
374
|
shared_examples_for "attribute reference" do
|
395
375
|
it "should be interpreted as :attr" do
|
396
|
-
@opts.sought_type.
|
376
|
+
expect(@opts.sought_type).to eq(:attr)
|
397
377
|
end
|
398
378
|
|
399
379
|
it "should strip '@' from name" do
|
400
|
-
@opts.name.
|
380
|
+
expect(@opts.name).to eq('attr_name')
|
401
381
|
end
|
402
382
|
|
403
383
|
it "should unescape xml entities" do
|
404
|
-
@opts.to_ref(RoxmlObject.new).value_in(%{
|
384
|
+
expect(@opts.to_ref(RoxmlObject.new).value_in(%{
|
405
385
|
<question attr_name=""Wickard & Filburn" > / < McCulloch & Marryland?" />
|
406
|
-
}).
|
386
|
+
})).to eq("\"Wickard & Filburn\" > / < McCulloch & Marryland?")
|
407
387
|
end
|
408
388
|
end
|
409
389
|
|
@@ -425,12 +405,12 @@ describe ROXML::Definition do
|
|
425
405
|
|
426
406
|
describe ":content" do
|
427
407
|
it "should be recognized" do
|
428
|
-
ROXML::Definition.new(:author).content
|
429
|
-
ROXML::Definition.new(:author, :from => :content).content
|
408
|
+
expect(ROXML::Definition.new(:author).content?).to be_falsey
|
409
|
+
expect(ROXML::Definition.new(:author, :from => :content).content?).to eq(true)
|
430
410
|
end
|
431
411
|
|
432
412
|
it "should be equivalent to :from => '.'" do
|
433
|
-
ROXML::Definition.new(:author, :from => '.').content
|
413
|
+
expect(ROXML::Definition.new(:author, :from => '.').content?).to eq(true)
|
434
414
|
end
|
435
415
|
end
|
436
416
|
end
|
@@ -438,13 +418,13 @@ describe ROXML::Definition do
|
|
438
418
|
describe ":in" do
|
439
419
|
context "as xpath" do
|
440
420
|
it "should pass through as wrapper" do
|
441
|
-
ROXML::Definition.new(:manufacturer, :in => './').wrapper.
|
421
|
+
expect(ROXML::Definition.new(:manufacturer, :in => './').wrapper).to eq('./')
|
442
422
|
end
|
443
423
|
end
|
444
424
|
|
445
425
|
context "as xpath" do
|
446
426
|
it "should pass through as wrapper" do
|
447
|
-
ROXML::Definition.new(:manufacturer, :in => 'wrapper').wrapper.
|
427
|
+
expect(ROXML::Definition.new(:manufacturer, :in => 'wrapper').wrapper).to eq('wrapper')
|
448
428
|
end
|
449
429
|
end
|
450
430
|
end
|
@@ -454,12 +434,12 @@ describe ROXML::Definition do
|
|
454
434
|
shared_examples_for "boolean option" do
|
455
435
|
it "should be recognized" do
|
456
436
|
ROXML::Definition.new(:author, :from => :content, @option => true).respond_to?(:"#{@option}?")
|
457
|
-
ROXML::Definition.new(:author, :from => :content, @option => true).send(:"#{@option}?").
|
458
|
-
ROXML::Definition.new(:author, :from => :content, @option => false).send(:"#{@option}?").
|
437
|
+
expect(ROXML::Definition.new(:author, :from => :content, @option => true).send(:"#{@option}?")).to be_truthy
|
438
|
+
expect(ROXML::Definition.new(:author, :from => :content, @option => false).send(:"#{@option}?")).to be_falsey
|
459
439
|
end
|
460
440
|
|
461
441
|
it "should default to false" do
|
462
|
-
ROXML::Definition.new(:author, :from => :content).send(:"#{@option}?").
|
442
|
+
expect(ROXML::Definition.new(:author, :from => :content).send(:"#{@option}?")).to be_falsey
|
463
443
|
end
|
464
444
|
end
|
465
445
|
|
@@ -471,8 +451,8 @@ describe ROXML::Definition do
|
|
471
451
|
it_should_behave_like "boolean option"
|
472
452
|
|
473
453
|
it "should not be allowed together with :else" do
|
474
|
-
|
475
|
-
|
454
|
+
expect { ROXML::Definition.new(:author, :from => :content, :required => true, :else => 'Johnny') }.to raise_error(ArgumentError)
|
455
|
+
expect { ROXML::Definition.new(:author, :from => :content, :required => false, :else => 'Johnny') }.to_not raise_error
|
476
456
|
end
|
477
457
|
end
|
478
458
|
|
@@ -8,30 +8,30 @@ describe ROXML, "under ActiveRecord" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should be parsed" do
|
11
|
-
@route.
|
12
|
-
@route.
|
11
|
+
expect(@route).to_not eq(nil)
|
12
|
+
expect(@route).to be_an_instance_of(Route)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "xml attributes" do
|
16
16
|
it "should extract xml attributes" do
|
17
|
-
@route.totalHg.
|
18
|
-
@route.lonlatx.
|
19
|
-
@route.lonlaty.
|
20
|
-
@route.grcenter.
|
21
|
-
@route.totalMins.
|
22
|
-
@route.totalDist.
|
17
|
+
expect(@route.totalHg).to eq("640")
|
18
|
+
expect(@route.lonlatx).to eq("357865")
|
19
|
+
expect(@route.lonlaty).to eq("271635")
|
20
|
+
expect(@route.grcenter).to eq("SH 71635 57865")
|
21
|
+
expect(@route.totalMins).to eq("235.75000000000003")
|
22
|
+
expect(@route.totalDist).to eq("11185.321521477119")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "xml sub-objects" do
|
27
27
|
it "should extract xml sub-objects" do
|
28
|
-
@route.
|
29
|
-
@route.waypoints.each {|waypoint| waypoint.
|
28
|
+
expect(@route.waypoints.size).to eq(6)
|
29
|
+
@route.waypoints.each {|waypoint| expect(waypoint).to be_an_instance_of(Waypoint)}
|
30
30
|
end
|
31
31
|
it "should be usable as a ActiveRecord object" do
|
32
|
-
Waypoint.count.
|
32
|
+
expect(Waypoint.count).to eq(0)
|
33
33
|
@route.save!
|
34
|
-
Waypoint.count.
|
34
|
+
expect(Waypoint.count).to eq(6)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|