public
Last active

  • Download Gist
object_space_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
require File.dirname(__FILE__) + '/../../spec_helper'
 
describe "ObjectSpace.each_object" do
it "calls the block once for each living, nonimmediate object in the Ruby process" do
class ObjectSpaceSpecEachObject; end
new_obj = ObjectSpaceSpecEachObject.new
 
count = ObjectSpace.each_object(ObjectSpaceSpecEachObject) {}
count.should == 1
# this is needed to prevent the new_obj from being GC'd too early
new_obj.should_not == nil
end
 
deviates_on(:ironruby) do
it "raises NotSupportedException for non-Class classes" do
lambda { ObjectSpace.each_object(String) {} }.should raise_error(RuntimeError)
end
end
 
it "works for Module" do
modules = []
ObjectSpace.each_object(Module) { |o| modules << o }
modules.size.should > 90
modules.each { |m| m.should be_kind_of(Module) }
end
 
it "works for Class" do
classes = []
ObjectSpace.each_object(Class) { |o| classes << o }
classes.size.should > 70
classes.each { |c| c.should be_kind_of(Class) }
end
 
it "works for singleton Class" do
moduleClass = class << Module; self; end
classClass = class << Class; self; end
ObjectSpace.each_object(moduleClass) {}.should >= 2
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.