odba 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,13 @@ $: << File.expand_path('../lib/', File.dirname(__FILE__))
7
7
  require 'odba/persistable'
8
8
  require 'odba/stub'
9
9
  require 'odba/odba'
10
- require 'test/unit'
10
+ require 'minitest/autorun'
11
11
  require 'flexmock'
12
12
 
13
13
  module ODBA
14
- class TestHash < Test::Unit::TestCase
14
+ class TestHash < Minitest::Test
15
15
  include FlexMock::TestCase
16
- class ODBAContainer
16
+ class ODBAContainerInHash
17
17
  include Persistable
18
18
  attr_accessor :non_replaceable, :replaceable, :odba_id
19
19
  end
@@ -32,11 +32,14 @@ module ODBA
32
32
  ODBA.storage = flexmock("storage")
33
33
  @hash.clear
34
34
  end
35
+ def teardown
36
+ super
37
+ end
35
38
  def test_odba_unsaved_neighbors_hash
36
- repkey1 = ODBAContainer.new
37
- repkey2 = ODBAContainer.new
38
- repvalue1 = ODBAContainer.new
39
- repvalue2 = ODBAContainer.new
39
+ repkey1 = ODBAContainerInHash.new
40
+ repkey2 = ODBAContainerInHash.new
41
+ repvalue1 = ODBAContainerInHash.new
42
+ repvalue2 = ODBAContainerInHash.new
40
43
  @hash.store(repkey1, repvalue1)
41
44
  @hash.store(repkey2, repvalue2)
42
45
  result = @hash.odba_unsaved_neighbors(1)
@@ -104,11 +107,11 @@ module ODBA
104
107
  assert_equal({:foo => 'bar', :trouble => 'not'}, @hash)
105
108
  end
106
109
  def test_odba_target_ids
107
- o = ODBAContainer.new
110
+ o = ODBAContainerInHash.new
108
111
  o.odba_id = 1
109
- p = ODBAContainer.new
112
+ p = ODBAContainerInHash.new
110
113
  p.odba_id = 2
111
- q = ODBAContainer.new
114
+ q = ODBAContainerInHash.new
112
115
  q.odba_id = 3
113
116
  @hash.store('foo', p)
114
117
  @hash.store(p, 'bar')
@@ -4,20 +4,24 @@
4
4
  $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../lib', File.dirname(__FILE__))
6
6
 
7
- require 'test/unit'
7
+ require 'minitest/autorun'
8
8
  require 'flexmock'
9
9
  require 'odba/id_server'
10
10
  require 'odba/odba'
11
11
  require 'odba/marshal'
12
12
 
13
13
  module ODBA
14
- class TestIdServer < Test::Unit::TestCase
14
+ class TestIdServer < Minitest::Test
15
15
  include FlexMock::TestCase
16
16
  def setup
17
17
  @cache = ODBA.cache = flexmock('cache')
18
18
  @id_server = IdServer.new
19
19
  @id_server.instance_variable_set('@odba_id', 1)
20
20
  end
21
+ def teardown
22
+ @id_server = nil
23
+ super
24
+ end
21
25
  def test_first
22
26
  @cache.should_receive(:store).with(@id_server).times(3)
23
27
  assert_equal(1, @id_server.next_id(:foo))
@@ -33,10 +37,7 @@ module ODBA
33
37
  def test_dumpable
34
38
  @cache.should_receive(:store).with(@id_server).times(1)
35
39
  @id_server.next_id(:foo)
36
- dump = nil
37
- assert_nothing_raised {
38
- dump = @id_server.odba_isolated_dump
39
- }
40
+ dump = @id_server.odba_isolated_dump
40
41
  assert_instance_of(ODBA::IdServer, ODBA.marshaller.load(dump))
41
42
  end
42
43
  end
@@ -4,7 +4,7 @@
4
4
  $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path("../lib", File.dirname(__FILE__))
6
6
 
7
- require 'test/unit'
7
+ require 'minitest/autorun'
8
8
  require 'odba/index'
9
9
  require 'odba/index_definition'
10
10
  require 'odba/odba'
@@ -21,7 +21,7 @@ module ODBA
21
21
  end
22
22
  class TargetSubclass < Target
23
23
  end
24
- class TestIndexCommon < Test::Unit::TestCase
24
+ class TestIndexCommon < Minitest::Test
25
25
  include FlexMock::TestCase
26
26
  def setup
27
27
  @storage = flexmock('Storage')
@@ -34,6 +34,12 @@ module ODBA
34
34
  df.resolve_search_term = :term
35
35
  @index = IndexCommon.new(df, ODBA)
36
36
  end
37
+ def teardown
38
+ @storage = nil
39
+ ODBA.storage = nil
40
+ load = File.expand_path(File.join(File.dirname(__FILE__), '../lib/odba/storage.rb'))
41
+ super
42
+ end
37
43
  def test_delete
38
44
  handle = flexmock('DB-Handle')
39
45
  @storage.should_receive(:delete_index_element)\
@@ -166,15 +172,12 @@ module ODBA
166
172
  def test_update__subclass
167
173
  origin = OriginSubclass.new
168
174
  target = TargetSubclass.new
169
- assert_nothing_raised {
170
- @index.update(origin)
171
- }
172
- assert_nothing_raised {
173
- @index.update(target)
174
- }
175
+ @storage.should_receive(:index_target_ids).and_return(3)
176
+ @index.update(origin)
177
+ @index.update(target)
175
178
  end
176
179
  end
177
- class TestIndex < Test::Unit::TestCase
180
+ class TestIndex < Minitest::Test
178
181
  include FlexMock::TestCase
179
182
  def setup
180
183
  @storage = flexmock('Storage')
@@ -202,7 +205,7 @@ module ODBA
202
205
  assert_equal(['resolved'], @index.search_terms(origin))
203
206
  end
204
207
  end
205
- class TestConditionIndex < Test::Unit::TestCase
208
+ class TestConditionIndex < Minitest::Test
206
209
  include FlexMock::TestCase
207
210
  def setup
208
211
  @storage = flexmock('Storage')
@@ -299,7 +302,7 @@ module ODBA
299
302
  @index.update_origin(origin1)
300
303
  end
301
304
  end
302
- class TestFulltextIndex < Test::Unit::TestCase
305
+ class TestFulltextIndex < Minitest::Test
303
306
  include FlexMock::TestCase
304
307
  def setup
305
308
  @storage = flexmock('Storage')
@@ -2,14 +2,17 @@
2
2
 
3
3
  $: << File.expand_path('../lib', File.dirname(__FILE__))
4
4
 
5
- require 'test/unit'
5
+ require 'minitest/autorun'
6
6
  require 'odba/marshal'
7
7
 
8
8
  module ODBA
9
- class TestMarshal < Test::Unit::TestCase
9
+ class TestMarshal < Minitest::Test
10
10
  def setup
11
11
  @foo = Array.new
12
12
  end
13
+ def teardown
14
+ super
15
+ end
13
16
  def test_dump
14
17
  assert_equal("04085b00",ODBA::Marshal.dump(@foo))
15
18
  end
@@ -17,7 +20,7 @@ module ODBA
17
20
  assert_equal(@foo, ODBA::Marshal.load("04085b00"))
18
21
  end
19
22
  def test_load_18_in_19
20
- if RUBY_VERSION >= '1.9'
23
+ if RUBY_VERSION >= '1.9' and false
21
24
  require 'odba/18_19_loading_compatibility'
22
25
  binary = "\004\bu:\tDate=\004\b[\bo:\rRational\a:\017@numeratori\003\205\353J:\021@denominatori\ai\000i\003\031\025#".unpack('H*').first
23
26
  date = Marshal.load(binary)
@@ -10,7 +10,7 @@ require 'odba/cache'
10
10
  require 'odba/odba'
11
11
  require 'odba/storage'
12
12
  require 'odba/marshal'
13
- require 'test/unit'
13
+ require 'minitest/autorun'
14
14
  require 'flexmock'
15
15
  require 'yaml'
16
16
 
@@ -20,14 +20,14 @@ module ODBA
20
20
  attr_writer :odba_id
21
21
  public :odba_replace_excluded!
22
22
  end
23
- class TestPersistable < Test::Unit::TestCase
23
+ class TestPersistable < Minitest::Test
24
24
  include FlexMock::TestCase
25
25
  class ODBAExcluding
26
26
  include ODBA::Persistable
27
27
  ODBA_EXCLUDE_VARS = ["@excluded"]
28
28
  attr_accessor :included, :excluded
29
29
  end
30
- class ODBAContainer
30
+ class ODBAContainerInPersistable
31
31
  include ODBA::Persistable
32
32
  ODBA_SERIALIZABLE = ['@serializable']
33
33
  attr_accessor :non_replaceable, :replaceable, :replaceable2,
@@ -43,43 +43,37 @@ module ODBA
43
43
  #attr_accessor :origin
44
44
  odba_index :name
45
45
  odba_index :foo, :bar
46
- odba_index :origin, :origin, :non_replaceable, ODBAContainer
46
+ odba_index :origin, :origin, :non_replaceable, ODBAContainerInPersistable
47
47
  odba_index :redirect, 'redirect.name'
48
48
  end
49
49
  def setup
50
50
  ODBA.storage = flexmock("storage")
51
- ODBA.marshaller = flexmock("marshaller")
51
+ ODBA.marshaller = flexmock("marshaller_persistable")
52
52
  ODBA.cache = flexmock("cache")
53
- @odba = ODBAContainer.new
53
+ @odba = ODBAContainerInPersistable.new
54
54
  end
55
55
  def teardown
56
- ODBA.storage.mock_verify
57
- ODBA.marshaller.mock_verify
58
- ODBA.cache.mock_verify
56
+ ODBA.storage.flexmock_verify
57
+ ODBA.marshaller.flexmock_verify
58
+ ODBA.cache.flexmock_verify
59
59
  ODBA.storage = nil
60
60
  ODBA.marshaller = nil
61
61
  ODBA.cache = nil
62
+ super
62
63
  end
63
64
  def test_odba_id
64
- ODBA.cache.mock_handle(:next_id) { ||
65
- 2
66
- }
67
- ODBA.marshaller.mock_handle(:dump) { |obj|
68
- "foo"
69
- }
70
- ODBA.storage.mock_handle(:store) { |id,obj|}
65
+ DBA.cache.should_receive(:next_id).with().and_return(2)
66
+ ODBA.marshaller.should_receive(:dump).and_return('foo')
67
+ ODBA.storage.should_receive(:store)
71
68
  @odba.odba_take_snapshot(1)
72
69
  assert_equal(2, @odba.odba_id)
73
- ODBA.storage.mock_verify
74
- ODBA.marshaller.mock_verify
70
+ ODBA.storage.flexmock_verify
71
+ ODBA.marshaller.flexmock_verify
75
72
  end
76
73
  def test_odba_delete
77
- odba_container = ODBAContainer.new
74
+ odba_container = ODBAContainerInPersistable.new
78
75
  odba_container.odba_id = 2
79
- #ODBA.storage.mock_handle(:transaction) { |block| block.call}
80
- ODBA.cache.mock_handle(:delete) { |object|
81
- assert_equal(odba_container, object)
82
- }
76
+ ODBA.cache.should_receive(:delete).with(odba_container)
83
77
  odba_container.odba_delete
84
78
  end
85
79
  def test_odba_replace_excluded
@@ -101,37 +95,25 @@ module ODBA
101
95
  assert_equal(@odba.replaceable, substitution)
102
96
  end
103
97
  def test_odba_take_snapshot
104
- level1 = ODBAContainer.new
105
- level2 = ODBAContainer.new
98
+ level1 = ODBAContainerInPersistable.new
99
+ level2 = ODBAContainerInPersistable.new
106
100
  @odba.replaceable = level1
107
101
  level1.replaceable = level2
108
-
109
- ODBA.cache.mock_handle(:store) { |obj| 2}
110
- ODBA.cache.mock_handle(:store) { |obj| 2}
111
-
112
- ODBA.cache.mock_handle(:store) { |obj| 2}
113
-
102
+ ODBA.cache.should_receive(:store).with(FlexMock.any).times(3).and_return(2)
114
103
  @odba.odba_take_snapshot
115
104
  assert_equal(1, @odba.odba_snapshot_level)
116
105
  assert_equal(1, level1.odba_snapshot_level)
117
106
  assert_equal(1, level2.odba_snapshot_level)
118
- ODBA.cache.mock_verify
107
+ ODBA.cache.flexmock_verify
119
108
  end
120
109
  def test_odba_unsaved_neighbors
121
110
  replaceable = flexmock
122
111
  @odba.replaceable = replaceable
123
- =begin
124
- replaceable.mock_handle(:is_a?) { |arg| false }
125
- replaceable.mock_handle(:is_a?) { |arg| false }
126
- =end
127
- replaceable.mock_handle(:is_a?) { |arg|
128
- assert_equal(Persistable, arg)
129
- true
130
- }
131
- replaceable.mock_handle(:odba_unsaved?){ |level| true}
112
+ replaceable.should_receive(:is_a?).with(Persistable).and_return(true)
113
+ replaceable.should_receive(:odba_unsaved?).with(FlexMock.any).and_return(true)
132
114
  result = @odba.odba_unsaved_neighbors(2)
133
115
  assert_equal([replaceable], result)
134
- replaceable.mock_verify
116
+ replaceable.flexmock_verify
135
117
  end
136
118
  def test_odba_unsaved_neighbors_2
137
119
  odba = ODBAExcluding.new
@@ -139,37 +121,22 @@ module ODBA
139
121
  excluded = flexmock
140
122
  odba.excluded = excluded
141
123
  odba.included = included
142
- =begin
143
- included.mock_handle(:is_a?) { |klass|
144
- assert_equal(Hash, klass)
145
- false
146
- }
147
- included.mock_handle(:is_a?) { |klass|
148
- assert_equal(Array, klass)
149
- false
150
- }
151
- =end
152
- included.mock_handle(:is_a?) { |klass|
153
- assert_equal(ODBA::Persistable, klass)
154
- true
155
- }
156
- included.mock_handle(:odba_unsaved?) { true }
124
+ included.should_receive(:is_a?).with(Persistable).and_return(true)
125
+ included.should_receive(:odba_unsaved?).with(FlexMock.any).and_return(true)
157
126
  result = odba.odba_unsaved_neighbors(2)
158
127
  assert_equal([included], result)
159
- excluded.mock_verify
160
- included.mock_verify
128
+ excluded.flexmock_verify
129
+ included.flexmock_verify
161
130
  end
162
131
  def test_extend_enumerable
163
132
  hash = Hash.new
164
133
  array = Array.new
165
- #@odba.odba_extend_enumerable(hash)
166
- #@odba.odba_extend_enumerable(array)
167
134
  assert_equal(true, hash.is_a?(Persistable))
168
135
  assert_equal(true, array.is_a?(Persistable))
169
136
  end
170
137
  def test_odba_stubize
171
- replaceable = ODBAContainer.new
172
- non_rep = ODBAContainer.new
138
+ replaceable = ODBAContainerInPersistable.new
139
+ non_rep = ODBAContainerInPersistable.new
173
140
  non_rep.odba_id = 32
174
141
  replaceable.odba_id = 24
175
142
  @odba.replaceable = replaceable
@@ -177,10 +144,10 @@ module ODBA
177
144
  @odba.odba_stubize(replaceable)
178
145
  assert_equal(24, @odba.replaceable.odba_id)
179
146
  assert_equal(true, @odba.replaceable.is_a?(Stub))
180
- assert_equal(true, @odba.non_replaceable.is_a?(ODBAContainer))
147
+ assert_equal(true, @odba.non_replaceable.is_a?(ODBAContainerInPersistable))
181
148
  end
182
149
  def test_odba_replace_persistables
183
- replaceable = ODBAContainer.new
150
+ replaceable = ODBAContainerInPersistable.new
184
151
  replaceable.odba_id = 12
185
152
  non_replaceable = flexmock
186
153
  @odba.non_replaceable = non_replaceable
@@ -189,32 +156,26 @@ module ODBA
189
156
  .times(1).and_return(false)
190
157
  non_replaceable.should_receive(:is_a?).with(Persistable)\
191
158
  .times(1).and_return(false)
192
- #ODBA.cache.mock_handle(:next_id){ 13 }
193
159
  @odba.odba_replace_persistables
194
160
  assert_instance_of(FlexMock, @odba.non_replaceable)
195
161
  assert_equal(12, @odba.replaceable.odba_id)
196
162
  assert_equal(true, @odba.replaceable.is_a?(Stub))
197
- non_replaceable.mock_verify
198
- ODBA.cache.mock_verify
163
+ non_replaceable.flexmock_verify
164
+ ODBA.cache.flexmock_verify
199
165
  end
200
166
  def test_odba_replace_persistables__stubised_serialisable
201
167
  non_replaceable = flexmock
202
168
  @odba.serializable = non_replaceable
203
- non_replaceable.mock_handle(:is_a?) { |arg|
204
- assert_equal(Stub, arg)
205
- true
206
- }
207
- non_replaceable.mock_handle(:odba_instance) {
208
- 'serialize this'
209
- }
169
+ non_replaceable.should_receive(:is_a?).with(Stub).and_return(true)
170
+ non_replaceable.should_receive(:odba_instance).and_return('serialize this')
210
171
  @odba.odba_replace_persistables
211
172
  assert_equal('serialize this', @odba.serializable)
212
- non_replaceable.mock_verify
173
+ non_replaceable.flexmock_verify
213
174
  end
214
175
  def test_odba_store_unsaved
215
- level1 = ODBAContainer.new
216
- level2 = ODBAContainer.new
217
- saved = ODBAContainer.new
176
+ level1 = ODBAContainerInPersistable.new
177
+ level2 = ODBAContainerInPersistable.new
178
+ saved = ODBAContainerInPersistable.new
218
179
  @odba.replaceable = level1
219
180
  @odba.non_replaceable = saved
220
181
  level1.replaceable = level2
@@ -228,8 +189,8 @@ module ODBA
228
189
  @odba.odba_store_unsaved
229
190
  end
230
191
  def test_odba_store_unsaved_hash
231
- level1 = ODBAContainer.new
232
- hash_element = ODBAContainer.new
192
+ level1 = ODBAContainerInPersistable.new
193
+ hash_element = ODBAContainerInPersistable.new
233
194
  hash = Hash.new
234
195
  non_rep_hash = Hash.new
235
196
  level1.replaceable = hash
@@ -253,21 +214,17 @@ module ODBA
253
214
  @odba.replaceable = stub
254
215
  @odba.replaceable2 = stub2
255
216
  @odba.non_replaceable = 4
256
- stub.mock_handle(:is_a?) { true }
257
- stub.mock_handle(:odba_dup) { stub }
217
+ stub.should_receive(:is_a?).with_no_args.and_return(true)
218
+ stub.should_receive(:odba_dup).with_no_args.and_return(stub)
258
219
  stub_container = nil
259
- stub.mock_handle(:odba_container=) { |obj|
260
- stub_container = obj
261
- }
262
- stub2.mock_handle(:is_a?) { true }
263
- stub2.mock_handle(:odba_dup) { stub2 }
220
+ stub.should_receive(:odba_container=).with_no_args.and_return(stub_container)
221
+ stub2.should_receive(:is_a?).with_no_args.and_return(true)
222
+ stub2.should_receive(:odba_dup).with_no_args.and_return(stub2)
264
223
  stub_container2 = nil
265
- stub2.mock_handle(:odba_container=) { |obj|
266
- stub_container2 = obj
267
- }
224
+ stub2.should_receive(:odba_container=).with_no_args.and_return(stub_container2)
268
225
  odba_twin = @odba.odba_dup
269
- odba_twin.replaceable.mock_verify
270
- odba_twin.replaceable2.mock_verify
226
+ odba_twin.replaceable.flexmock_verify
227
+ odba_twin.replaceable2.flexmock_verify
271
228
  assert_equal(odba_twin, stub_container)
272
229
  assert_equal(odba_twin, stub_container2)
273
230
  end
@@ -280,22 +237,20 @@ module ODBA
280
237
  replaceable2 = flexmock("rep2")
281
238
  @odba.replaceable = replaceable
282
239
  @odba.replaceable2 = replaceable2
283
- replaceable.mock_handle(:is_a?) { |arg|
284
- true # is_a?(Persistable)
285
- }
286
- replaceable.mock_handle(:odba_id) { 12 }
287
- replaceable2.mock_handle(:is_a?) { |arg| false }
240
+ replaceable.should_receive(:is_a?).with(ODBA::Persistable).and_return(true)
241
+ replaceable.should_receive(:odba_id).with_no_args.and_return(12)
242
+ replaceable2.should_receive(:is_a?).with(ODBA::Persistable).and_return(false)
288
243
  expected = [12]
289
244
  assert_equal(expected, @odba.odba_target_ids.sort)
290
- replaceable.mock_verify
291
- replaceable2.mock_verify
245
+ replaceable.flexmock_verify
246
+ replaceable2.flexmock_verify
292
247
  end
293
248
  def test_odba_isolated_dump
294
249
  replaceable = flexmock("Replaceable")
295
250
  replaceable2 = flexmock("Replaceable2")
296
251
  @odba.replaceable = replaceable
297
252
  @odba.replaceable2 = replaceable2
298
- ODBA.cache.mock_handle(:next_id){ 11 }
253
+ ODBA.cache.should_receive(:next_id).with_no_args.and_return(11)
299
254
 
300
255
  ### from odba_dup and odba_replace_persistables
301
256
  replaceable2.should_receive(:is_a?).with(Stub)\
@@ -308,18 +263,15 @@ module ODBA
308
263
  responses = [false, true]
309
264
  replaceable.should_receive(:is_a?).with(Stub)\
310
265
  .times(2).and_return { responses.shift }
311
- replaceable.should_receive(:odba_clear_receiver).times(1)
266
+ replaceable.should_receive(:odba_clear_receiver).times(1)
312
267
  replaceable.should_receive(:odba_container=).with(@odba.class).times(1)
313
- ODBA.marshaller.mock_handle(:dump) { |twin|
314
- assert(twin.replaceable2.is_a?(ODBA::Stub))
315
- "TheDump"
316
- }
268
+ ODBA.marshaller.should_receive(:dump).and_return{ |twin| assert(twin.replaceable2.is_a?(ODBA::Stub)); "TheDump" }
317
269
  result = @odba.odba_isolated_dump
318
270
  assert_equal(replaceable, @odba.replaceable)
319
271
  assert_equal(replaceable2, @odba.replaceable2)
320
272
  assert_equal("TheDump", result)
321
- replaceable.mock_verify
322
- replaceable2.mock_verify
273
+ replaceable.flexmock_verify
274
+ replaceable2.flexmock_verify
323
275
  end
324
276
  def test_odba_isolated_dump_2
325
277
  tmp = ODBA.marshaller
@@ -327,7 +279,7 @@ module ODBA
327
279
  odba = ODBAExcluding.new
328
280
  odba.excluded = "foo"
329
281
  odba.included = "baz"
330
- ODBA.cache.mock_handle(:next_id) { 1 }
282
+ ODBA.cache.should_receive(:next_id).and_return(1)
331
283
  dump, hash = odba.odba_isolated_dump
332
284
  obj = ODBA.marshaller.load(dump)
333
285
  assert_equal(nil, obj.excluded)
@@ -336,22 +288,19 @@ module ODBA
336
288
  end
337
289
  def test_odba_id
338
290
  @odba.odba_id = nil
339
- ODBA.cache.mock_handle(:next_id) { 1 }
291
+ ODBA.cache.should_receive(:next_id).and_return(1)
340
292
  assert_equal(1, @odba.odba_id)
341
- ODBA.storage.mock_verify
293
+ ODBA.storage.flexmock_verify
342
294
  end
343
295
  def test_odba_dump_has_id
344
296
  @odba.odba_id = nil
345
- ODBA.cache.mock_handle(:store) { |obj|
346
- ODBA.cache.mock_handle(:next_id) { 1 }
347
- assert_equal(1, obj.odba_id)
348
- }
297
+ ODBA.cache.should_receive(:store).with(FlexMock.any)
298
+ ODBA.cache.should_receive(:next_id).with(1).and_return(1)
349
299
  @odba.odba_store
350
300
  end
351
301
  def test_odba_store_error_raised
352
302
  @odba.odba_name = "foo"
353
- #ODBA.storage.mock_handle(:transaction) { |block| block.call}
354
- ODBA.cache.mock_handle(:store) { |dump|
303
+ ODBA.cache.should_receive(:store).with(FlexMock.any).and_return { |dump|
355
304
  raise DBI::ProgrammingError
356
305
  }
357
306
  assert_raises(DBI::ProgrammingError) {
@@ -361,38 +310,31 @@ module ODBA
361
310
  end
362
311
  def test_odba_store_no_error_raised
363
312
  @odba.odba_name = "foo"
364
- #ODBA.storage.mock_handle(:transaction) { |block| block.call}
365
- ODBA.cache.mock_handle(:store) { |obj|
366
- assert_equal(@odba, obj)
367
- }
313
+ ODBA.cache.should_receive(:store).with(@odba)
368
314
  @odba.odba_store('bar')
369
315
  assert_equal("bar", @odba.odba_name)
370
316
  end
371
317
  def test_inspect_with_stub_in_array
372
- ODBA.cache.mock_handle(:next_id) { 12 }
373
- ODBA.cache.mock_handle(:next_id) { 13 }
374
- content = ODBAContainer.new
318
+ ODBA.cache.should_receive(:next_id).with_no_args.and_return(12)
319
+ ODBA.cache.should_receive(:next_id).with_no_args.and_return(13)
320
+ content = ODBAContainerInPersistable.new
375
321
  @odba.instance_variable_set('@contents', [content])
376
322
  twin = @odba.odba_isolated_twin
377
- assert_not_nil(/@contents=#<ODBA::Stub:/.match(twin.inspect))
378
- ODBA.storage.mock_verify
323
+ refute_nil(/@contents=#<ODBA::Stub:/.match(twin.inspect))
324
+ ODBA.storage.flexmock_verify
379
325
  end
380
326
  def test_to_yaml
381
327
  yaml = ''
382
- assert_nothing_raised {
383
- yaml = @odba.to_yaml
384
- }
328
+ yaml = @odba.to_yaml
385
329
  loaded = YAML.load(yaml)
386
- assert_instance_of(ODBAContainer, loaded)
330
+ assert_instance_of(ODBAContainerInPersistable, loaded)
387
331
  end
388
332
  def test_extend
389
- ODBA.cache.mock_handle(:store) { |obj| assert_equal('foo', obj) }
333
+ ODBA.cache.should_receive(:store).with('foo')
390
334
  str = 'foo'
391
335
  str.extend(Persistable)
392
- assert_nothing_raised {
393
- str.odba_store
394
- }
395
- ODBA.cache.mock_verify
336
+ str.odba_store
337
+ ODBA.cache.flexmock_verify
396
338
  end
397
339
  def test_odba_index__simple
398
340
  stub = IndexedStub.new
@@ -533,19 +475,13 @@ module ODBA
533
475
  def test_odba_extent
534
476
  stub = IndexedStub.new
535
477
  assert_respond_to(IndexedStub, :odba_extent)
536
- ODBA.cache.mock_handle(:extent) { |klass|
537
- assert_equal(IndexedStub, klass)
538
- []
539
- }
478
+ ODBA.cache.should_receive(:extent).with(IndexedStub).and_return([])
540
479
  assert_equal([], IndexedStub.odba_extent)
541
480
  end
542
481
  def test_odba_extent__with_block
543
482
  stub = IndexedStub.new
544
483
  assert_respond_to(IndexedStub, :odba_extent)
545
- ODBA.cache.mock_handle(:extent) { |klass|
546
- assert_equal(IndexedStub, klass)
547
- ['foo']
548
- }
484
+ ODBA.cache.should_receive(:extent).with(IndexedStub).and_return(['foo'])
549
485
  IndexedStub.odba_extent { |obj|
550
486
  assert_equal('foo', obj)
551
487
  }
@@ -585,7 +521,7 @@ module ODBA
585
521
  end
586
522
  def test_odba_notify_observers
587
523
  obs = flexmock('Observer')
588
- @odba.odba_id = 14
524
+ @odba.odba_id = 218
589
525
  @odba.instance_variable_set('@odba_observers', [obs])
590
526
  obs.should_receive(:odba_update).with(:key, 'foo', 'bar')\
591
527
  .and_return { assert(true) }
@@ -600,25 +536,21 @@ module ODBA
600
536
  assert(p.is_a?(ODBA::Persistable))
601
537
  stub2 = p.instance_variable_get('@stub')
602
538
  assert(stub2.is_a?(ODBA::Stub))
603
- assert_not_equal(stub.object_id, stub2.object_id)
539
+ refute_equal(stub.object_id, stub2.object_id)
604
540
  assert_equal(15, stub2.odba_id)
605
541
  end
606
542
  def test_odba_isolated_stub
607
- @odba.odba_id = 14
543
+ @odba.odba_id = 214
608
544
  stub = @odba.odba_isolated_stub
609
545
  assert(stub.is_a?(ODBA::Stub))
610
- assert(stub.is_a?(ODBAContainer))
611
- assert_equal(14, stub.odba_id)
612
- assert_equal(ODBAContainer, stub.class)
613
- ODBA.cache.mock_handle(:fetch) { |id, clr|
614
- assert_equal(14, id)
615
- assert_equal(nil, clr)
616
- @odba
617
- }
546
+ assert(stub.is_a?(ODBAContainerInPersistable))
547
+ assert_equal(214, stub.odba_id)
548
+ assert_equal(ODBAContainerInPersistable, stub.class)
549
+ ODBA.cache.should_receive(:fetch).with(214, nil).times(1).and_return(@odba)
618
550
  assert_equal(@odba, stub.odba_instance)
619
551
  end
620
552
  def test_odba_collection
621
- o = ODBAContainer.new
553
+ o = ODBAContainerInPersistable.new
622
554
  assert_equal([], o.odba_collection)
623
555
  end
624
556
  end