spec/wref_spec.rb in wref-0.0.2 vs spec/wref_spec.rb in wref-0.0.3

- old
+ new

@@ -18,12 +18,44 @@ str = "Test" map = Wref_map.new map[5] = str + map[6] = "trala" + raise "Should have been valid but wasnt." if !map.valid?(5) str = nil - GC.start - raise "Should habe been garbage collected but wasnt." if !map.valid?(5) + + #Test each-method. + count = 0 + str_col = "" + map.each do |a_str| + count += 1 + str_col << a_str + end + + raise "Expected collection to be 'Testtrala' but it wasnt: #{str_col}" if str_col != "Testtrala" + raise "Expected count 2 but it wasnt: #{count}" if count != 2 + + #Make the engine work a little to force garbage collection. + 0.upto(10) do + str = "New str" + ref = Wref.new(str) + ref = nil + + str2 = "New string" + ref2 = Wref.new(str2) + ref2 = nil + GC.start + end + + #Test each-method. + count = 0 + map.each do |a_str| + count += 1 + end + + raise "Expected count 0 but it wasnt: #{count}" if count != 0 + raise "Should have been garbage collected but wasnt." if map.valid?(5) end end end \ No newline at end of file