xmlconv 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/History.txt +8 -0
  4. data/README.txt +0 -4
  5. data/Rakefile +16 -32
  6. data/bin/migrate_xmlconv_to_utf_8 +235 -0
  7. data/bin/{admin → xmlconv_admin} +0 -0
  8. data/bin/xmlconvd +3 -1
  9. data/converter_scripts/convert.rb +23 -0
  10. data/{xmlconv_convert.rb → converter_scripts/xmlconv_convert.rb} +0 -0
  11. data/lib/xmlconv/config.rb +6 -0
  12. data/lib/xmlconv/custom/lookandfeel.rb +1 -1
  13. data/lib/xmlconv/i2/header.rb +5 -3
  14. data/lib/xmlconv/i2/position.rb +3 -2
  15. data/lib/xmlconv/util/application.rb +9 -6
  16. data/lib/xmlconv/util/destination.rb +11 -6
  17. data/lib/xmlconv/util/mail.rb +26 -14
  18. data/lib/xmlconv/util/transaction.rb +3 -1
  19. data/lib/xmlconv/version.rb +3 -0
  20. data/readme.md +46 -0
  21. data/test/data/polling.yaml +10 -0
  22. data/test/test_i2/address.rb +2 -2
  23. data/test/test_i2/date.rb +2 -2
  24. data/test/test_i2/document.rb +12 -22
  25. data/test/test_i2/header.rb +2 -2
  26. data/test/test_i2/order.rb +18 -32
  27. data/test/test_i2/parser.rb +4 -3
  28. data/test/test_i2/position.rb +9 -23
  29. data/test/test_model/address.rb +2 -2
  30. data/test/test_model/agreement.rb +2 -2
  31. data/test/test_model/bdd.rb +8 -9
  32. data/test/test_model/bsr.rb +6 -7
  33. data/test/test_model/delivery.rb +11 -15
  34. data/test/test_model/delivery_item.rb +5 -5
  35. data/test/test_model/freetext_container.rb +3 -3
  36. data/test/test_model/invoice.rb +8 -11
  37. data/test/test_model/invoice_item.rb +5 -4
  38. data/test/test_model/name.rb +2 -2
  39. data/test/test_model/part_info.rb +2 -2
  40. data/test/test_model/party.rb +16 -22
  41. data/test/test_model/price.rb +2 -2
  42. data/test/test_util/application.rb +36 -86
  43. data/test/test_util/destination.rb +11 -19
  44. data/test/test_util/invoicer.rb +3 -3
  45. data/test/test_util/polling_manager.rb +11 -11
  46. data/test/test_util/transaction.rb +31 -55
  47. data/xmlconv.gemspec +45 -0
  48. metadata +378 -78
  49. data/.gemtest +0 -0
  50. data/lib/xmlconv/i2/parser.rb +0 -23
  51. data/lib/xmlconv.rb +0 -3
  52. data/test/mock.rb +0 -149
metadata CHANGED
@@ -1,61 +1,344 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xmlconv
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 1
10
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
11
5
  platform: ruby
12
- authors:
13
- - Masaomi Hatakeyama, Zeno R.R. Davatz
6
+ authors:
7
+ - Masaomi Hatakeyama, Zeno R.R. Davatz, Niklaus Giger
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-02-24 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: hoe
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 41
30
- segments:
31
- - 2
32
- - 9
33
- - 1
34
- version: 2.9.1
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: odba
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: ydbd-pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: ydbi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sbsm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: htmlgrid
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ydim
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: syck
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: mail
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rclconf
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: needle
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: ypdf-writer
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: hpricot
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: deprecated
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '='
200
+ - !ruby/object:Gem::Version
201
+ version: 2.0.1
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '='
207
+ - !ruby/object:Gem::Version
208
+ version: 2.0.1
209
+ - !ruby/object:Gem::Dependency
210
+ name: yus
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: bundler
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: simplecov
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
35
244
  type: :development
36
- version_requirements: *id001
37
- description: xmlconverter, convert XML to flat files.
38
- email:
39
- - mhatakeyama@ywesee.com, zdavatz@ywesee.com
40
- executables:
41
- - admin
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: rake
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: flexmock
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: minitest
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: minitest-should_syntax
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ - !ruby/object:Gem::Dependency
308
+ name: rspec
309
+ requirement: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - ">="
312
+ - !ruby/object:Gem::Version
313
+ version: '0'
314
+ type: :development
315
+ prerelease: false
316
+ version_requirements: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - ">="
319
+ - !ruby/object:Gem::Version
320
+ version: '0'
321
+ description: xmlconverter, convert XML to flat files. A Ruby gem
322
+ email: mhatakeyama@ywesee.com, zdavatz@ywesee.com, ngiger@ywesee.com
323
+ executables:
324
+ - migrate_xmlconv_to_utf_8
325
+ - xmlconv_admin
42
326
  - xmlconvd
43
327
  extensions: []
44
-
45
- extra_rdoc_files:
46
- - History.txt
47
- - Manifest.txt
48
- - README.txt
49
- files:
328
+ extra_rdoc_files: []
329
+ files:
330
+ - Gemfile
50
331
  - History.txt
51
332
  - LICENSE
52
333
  - Manifest.txt
53
334
  - README.txt
54
335
  - Rakefile
55
- - bin/admin
336
+ - bin/migrate_xmlconv_to_utf_8
337
+ - bin/xmlconv_admin
56
338
  - bin/xmlconvd
339
+ - converter_scripts/convert.rb
340
+ - converter_scripts/xmlconv_convert.rb
57
341
  - data/grammar/i2.grammar
58
- - lib/xmlconv.rb
59
342
  - lib/xmlconv/config.rb
60
343
  - lib/xmlconv/custom/lookandfeel.rb
61
344
  - lib/xmlconv/i2/address.rb
@@ -63,7 +346,6 @@ files:
63
346
  - lib/xmlconv/i2/document.rb
64
347
  - lib/xmlconv/i2/header.rb
65
348
  - lib/xmlconv/i2/order.rb
66
- - lib/xmlconv/i2/parser.rb
67
349
  - lib/xmlconv/i2/position.rb
68
350
  - lib/xmlconv/i2/record.rb
69
351
  - lib/xmlconv/model/address.rb
@@ -102,6 +384,7 @@ files:
102
384
  - lib/xmlconv/util/session.rb
103
385
  - lib/xmlconv/util/transaction.rb
104
386
  - lib/xmlconv/util/validator.rb
387
+ - lib/xmlconv/version.rb
105
388
  - lib/xmlconv/view/foot.rb
106
389
  - lib/xmlconv/view/head.rb
107
390
  - lib/xmlconv/view/login.rb
@@ -112,8 +395,9 @@ files:
112
395
  - lib/xmlconv/view/template.rb
113
396
  - lib/xmlconv/view/transaction.rb
114
397
  - lib/xmlconv/view/transactions.rb
398
+ - readme.md
115
399
  - test/config.rb
116
- - test/mock.rb
400
+ - test/data/polling.yaml
117
401
  - test/suite.rb
118
402
  - test/test_i2/address.rb
119
403
  - test/test_i2/date.rb
@@ -140,42 +424,58 @@ files:
140
424
  - test/test_util/invoicer.rb
141
425
  - test/test_util/polling_manager.rb
142
426
  - test/test_util/transaction.rb
143
- - xmlconv_convert.rb
144
- - .gemtest
145
- has_rdoc: true
146
- homepage: http://scm.ywesee.com/?p=xmlconv/.git;a=summary
147
- licenses: []
148
-
427
+ - xmlconv.gemspec
428
+ homepage: https://github.com/zdavatz/xmlconv
429
+ licenses:
430
+ - GPL-v2
431
+ metadata: {}
149
432
  post_install_message:
150
- rdoc_options:
151
- - --main
152
- - README.txt
153
- require_paths:
433
+ rdoc_options: []
434
+ require_paths:
154
435
  - lib
155
- required_ruby_version: !ruby/object:Gem::Requirement
156
- none: false
157
- requirements:
436
+ required_ruby_version: !ruby/object:Gem::Requirement
437
+ requirements:
158
438
  - - ">="
159
- - !ruby/object:Gem::Version
160
- hash: 3
161
- segments:
162
- - 0
163
- version: "0"
164
- required_rubygems_version: !ruby/object:Gem::Requirement
165
- none: false
166
- requirements:
439
+ - !ruby/object:Gem::Version
440
+ version: '0'
441
+ required_rubygems_version: !ruby/object:Gem::Requirement
442
+ requirements:
167
443
  - - ">="
168
- - !ruby/object:Gem::Version
169
- hash: 3
170
- segments:
171
- - 0
172
- version: "0"
444
+ - !ruby/object:Gem::Version
445
+ version: '0'
173
446
  requirements: []
174
-
175
- rubyforge_project: xmlconv
176
- rubygems_version: 1.4.2
447
+ rubyforge_project:
448
+ rubygems_version: 2.4.5
177
449
  signing_key:
178
- specification_version: 3
179
- summary: xmlconverter, convert XML to flat files.
180
- test_files: []
181
-
450
+ specification_version: 4
451
+ summary: xmlconverter, convert XML to flat files
452
+ test_files:
453
+ - test/config.rb
454
+ - test/data/polling.yaml
455
+ - test/suite.rb
456
+ - test/test_i2/address.rb
457
+ - test/test_i2/date.rb
458
+ - test/test_i2/document.rb
459
+ - test/test_i2/header.rb
460
+ - test/test_i2/order.rb
461
+ - test/test_i2/parser.rb
462
+ - test/test_i2/position.rb
463
+ - test/test_model/address.rb
464
+ - test/test_model/agreement.rb
465
+ - test/test_model/bdd.rb
466
+ - test/test_model/bsr.rb
467
+ - test/test_model/delivery.rb
468
+ - test/test_model/delivery_item.rb
469
+ - test/test_model/freetext_container.rb
470
+ - test/test_model/invoice.rb
471
+ - test/test_model/invoice_item.rb
472
+ - test/test_model/name.rb
473
+ - test/test_model/part_info.rb
474
+ - test/test_model/party.rb
475
+ - test/test_model/price.rb
476
+ - test/test_util/application.rb
477
+ - test/test_util/destination.rb
478
+ - test/test_util/invoicer.rb
479
+ - test/test_util/polling_manager.rb
480
+ - test/test_util/transaction.rb
481
+ has_rdoc:
data/.gemtest DELETED
File without changes
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # I2::Parser -- xmlconv2 -- 28.06.2004 -- hwyss@ywesee.com
3
-
4
- require 'rockit/rockit'
5
-
6
- module XmlConv
7
- module I2
8
- def cached_parser
9
- grammar_path = File.expand_path('i2.grammar', CONFIG.grammar_dir)
10
- parser_path = File.expand_path('i2_parser.rb', CONFIG.grammar_dir)
11
- old_path = File.expand_path('i2.grammar.old', CONFIG.grammar_dir)
12
- src = File.read(grammar_path)
13
- unless(File.exists?(old_path) && File.read(old_path) == src)
14
- File.delete(old_path) if File.exists?(old_path)
15
- Parse.generate_parser_from_file_to_file(grammar_path, parser_path, "make_i2_parser", 'XmlConv')
16
- File.open(old_path, 'w') { |f| f << src }
17
- end
18
- require parser_path
19
- XmlConv.make_i2_parser
20
- end
21
- module_function :cached_parser
22
- end
23
- end
data/lib/xmlconv.rb DELETED
@@ -1,3 +0,0 @@
1
- class Version
2
- VERSION = '1.0.1'
3
- end
data/test/mock.rb DELETED
@@ -1,149 +0,0 @@
1
- # Ruby/Mock version 1.0
2
- #
3
- # A class for conveniently building mock objects in RUnit test cases.
4
- # Copyright (c) 2001 Nat Pryce, all rights reserved
5
- #
6
- # This program is free software; you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation; either version 2 of the License.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program; if not, write to the Free Software
17
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
-
19
- require 'runit/error'
20
-
21
-
22
- class Mock
23
- # Creates a new, named mock object. The name is reported in exceptions
24
- # thrown by the mock object when method invocations are incorrect.
25
- #
26
- def initialize( mock_name = self.to_s )
27
- @mock_calls = []
28
- @next_call = 0
29
- @name = mock_name
30
- end
31
-
32
- # Mock the next method call to be made to this mock object.
33
- #
34
- # A mock method is defined by the method name (a symbol) and a block
35
- # that defines the arity of the method and the mocked behaviour for
36
- # this call. The mocked behaviour should assert preconditions and
37
- # return a value. Mocked behaviour should rarely be any more complex
38
- # than that. If it is, that's probably an indication that the tests
39
- # need some restructuring or that the tested code needs refactoring.
40
- #
41
- # If no block is given and preconditions have been defined for the named
42
- # method, a block is created for the mocked methodthat has the same arity
43
- # as the precondition and returns self.
44
- #
45
- def __next( name, &test )
46
- if test == nil
47
- if respond_to?( Mock.__pre(name) )
48
- test = proc { |*args| self }
49
- else
50
- raise "no block given for mocked method #{name}"
51
- end
52
- end
53
- @mock_calls.push( [name,test] )
54
- end
55
-
56
- # Call this at the end of a test to ensure that all scheduled calls
57
- # have been made to the mock
58
- #
59
- def __verify
60
- if @next_call != @mock_calls.length
61
- raise RUNIT::AssertionFailedError,
62
- "not all expected method calls were made to #{@name}",
63
- caller
64
- end
65
- end
66
-
67
-
68
- private
69
- # Dispatches aribtrary method calls to the next mocked behaviour
70
- #
71
- def method_missing( name, *args, &block )
72
- __mock_call( name, args, (block_given? ? block : nil) )
73
- end
74
-
75
- # Implements a method call using the next mocked behaviour and asserts
76
- # that the expected method is called with the expected number of
77
- # arguments.
78
- #
79
- def __mock_call( name, args, block )
80
- if @next_call >= @mock_calls.length
81
- raise RUNIT::AssertionFailedError,
82
- "unexpected call to #{name} method of #{@name}",
83
- caller(2)
84
- end
85
-
86
- expected_name,body = @mock_calls[@next_call]
87
- @next_call += 1
88
-
89
- if name != expected_name
90
- raise RUNIT::AssertionFailedError,
91
- "wrong method called on #{@name}; " +
92
- "expected #{expected_name}, was #{name}",
93
- caller(2)
94
- end
95
-
96
- args_length = args.length + (block ? 1 : 0)
97
-
98
- if body.arity < 0
99
- if (body.arity+1).abs > args_length
100
- raise RUNIT::AssertionFailedError,
101
- "too few arguments to #{name} method of #{@name}; " +
102
- "require #{(body.arity+1).abs}, got #{args.length}",
103
- caller(2)
104
- end
105
- else
106
- if body.arity != args_length
107
- raise RUNIT::AssertionFailedError,
108
- "wrong number of arguments to " +
109
- "#{name} method of #{@name}; " +
110
- "require #{body.arity}, got #{args.length}",
111
- caller(2)
112
- end
113
- end
114
-
115
- if respond_to? Mock.__pre(name)
116
- if block
117
- precondition_ok = __send__( Mock.__pre(name), *args, &block )
118
- else
119
- precondition_ok = __send__( Mock.__pre(name), *args )
120
- end
121
-
122
- if not precondition_ok
123
- raise RUNIT::AssertionFailedError,
124
- "precondition of #{name} method violated",
125
- caller(2)
126
- end
127
- end
128
-
129
- if block
130
- instance_eval { body.call( block, *args ) }
131
- else
132
- instance_eval { body.call( *args ) }
133
- end
134
- end
135
-
136
- # The name of a precondition for a method
137
- def Mock.__pre( method )
138
- "__pre_#{method.to_i}".intern
139
- end
140
-
141
-
142
- def Mock.method_added( name )
143
- unless(/^__pre_/.match(name.to_s))
144
- pre = self.__pre(name)
145
- alias_method( pre, name )
146
- undef_method(name)
147
- end
148
- end
149
- end